shithub: opus-tools

Download patch

ref: 7c700fc06fa9d83cba28aed77a94f7ef2ac28d35
parent: 6d045e72eab738789dc6fd1db628553b24842908
author: Mark Harris <mark.hsj@gmail.com>
date: Sun Apr 29 18:38:05 EDT 2018

opusrtp: Fix error if pcap is unavailable

--- a/src/opusrtp.c
+++ b/src/opusrtp.c
@@ -1060,11 +1060,9 @@
 {
   int option, i;
   const char *dest = "127.0.0.1";
-#ifdef HAVE_PCAP
   const char *input_pcap = NULL;
   const char *output_file = NULL;
   int pcap_mode = 0;
-#endif
   int port = 1234;
   int payload_type = -1;
   int samplerate = 48000;
@@ -1090,12 +1088,7 @@
     switch (option) {
       case 0:
         if (!strcmp(long_options[i].name, "sniff")) {
-#ifdef HAVE_PCAP
           pcap_mode = 1;
-#else
-          fprintf(stderr, "pcap support disabled, sorry.\n");
-          return 1;
-#endif
         } else {
           fprintf(stderr, "Unknown option - try %s --help.\n", argv[0]);
           return -1;
@@ -1115,16 +1108,11 @@
             dest = optarg;
         break;
       case 'e':
-#ifdef HAVE_PCAP
         if (optarg) {
             input_pcap = optarg;
             pcap_mode = 1;
         }
         break;
-#else
-        fprintf(stderr, "pcap support disabled, sorry.\n");
-        return 1;
-#endif
       case 'p':
         if (optarg)
             port = atoi(optarg);
@@ -1153,13 +1141,11 @@
 
   if (optind < argc) {
     /* files to transmit were specified */
-#ifdef HAVE_PCAP
     if (pcap_mode) {
       fprintf(stderr, "Ogg Opus input files cannot be used with %s.\n",
         input_pcap ? "--extract" : "--sniff");
       return 1;
     }
-#endif
     if (payload_type < 0) payload_type = 120;
     for (i = optind; i < argc; i++) {
       rtp_send_file(argv[i], dest, port, payload_type);
@@ -1167,11 +1153,18 @@
     return 0;
   }
 
-#ifdef HAVE_PCAP
   if (pcap_mode) {
+#ifdef HAVE_PCAP
     return sniff(input_pcap, output_file, payload_type, samplerate, channels);
-  }
+#else
+    (void)input_pcap;
+    (void)output_file;
+    (void)samplerate;
+    (void)channels;
+    fprintf(stderr, "Sorry, pcap support is disabled.\n");
+    return 1;
 #endif
+  }
 
   usage(argv[0]);
   return 1;