shithub: opus-tools

Download patch

ref: c83c06b4cebbeff4ff3debf08e5d3c340942f9c5
parent: 79b256df5c397a83037909a9a62a0ebc008d66a4
author: Ralph Giles <giles@mozilla.com>
date: Mon Aug 27 12:40:23 EDT 2012

ifdef-protect the pcap code.

We don't want to break the build when libpcap isn't available,
and eventually we want this tool to send/receive rtp streams
as well as sniff them, so move the pcap-related code to a
separate function, which we only call if it's available.

This means that by default the programme does nothing.

--- a/src/opusrtp.c
+++ b/src/opusrtp.c
@@ -328,6 +328,7 @@
   return 0;
 }
 
+#ifdef HAVE_PCAP
 /* pcap 'got_packet' callback */
 void write_packet(u_char *args, const struct pcap_pkthdr *header,
                   const u_char *data)
@@ -424,19 +425,22 @@
   }
 }
 
-int main(int argc, char *argv[])
+/* use libpcap to capture packets and write them to a file */
+int sniff(char *device)
 {
   state *params;
   pcap_t *pcap;
-  char *dev = "lo";
-  int port = 55555;
   char errbuf[PCAP_ERRBUF_SIZE];
   ogg_packet *op;
 
+  if (!device) {
+    device = "lo";
+  }
+
   /* set up */
-  pcap = pcap_open_live(dev, 9600, 0, 1000, errbuf);
+  pcap = pcap_open_live(device, 9600, 0, 1000, errbuf);
   if (pcap == NULL) {
-    fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
+    fprintf(stderr, "Couldn't open device %s: %s\n", device, errbuf);
     return(2);
   }
   params = malloc(sizeof(state));
@@ -469,7 +473,6 @@
   op_free(op);
   ogg_flush(params);
 
-
   /* start capture loop */
   fprintf(stderr, "Capturing packets\n");
   pcap_loop(pcap, 300, write_packet, (u_char *)params);
@@ -482,6 +485,16 @@
   ogg_stream_destroy(params->stream);
   free(params);
   pcap_close(pcap);
+
+  return 0;
+}
+#endif /* HAVE_PCAP */
+
+int main(int argc, char *argv[])
+{
+#ifdef HAVE_PCAP
+  sniff("lo");
+#endif
 
   return 0;
 }