X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/89c4ed635a5aba9241e12e796c7e5025879d0e77..a3cc5c72831f0e0465ddce1886b29357f9257121:/ecnprobe/capture.c diff --git a/ecnprobe/capture.c b/ecnprobe/capture.c index 494fc21..32a8e0b 100644 --- a/ecnprobe/capture.c +++ b/ecnprobe/capture.c @@ -56,7 +56,7 @@ pcap_t *pc; /* pcap device */ int datalinkOffset; /* offset of ip packet from datalink packet */ -int captureDebug = 0; +int captureDebug = 1; unsigned int thisTimeZone; void CaptureInit(u_int32_t sourceIP, u_int16_t sourcePort, @@ -82,7 +82,17 @@ void CaptureInit(u_int32_t sourceIP, u_int16_t sourcePort, if (dev != NULL) { device = dev; } else { - device = pcap_lookupdev(errbuf); + pcap_if_t *devlist; + /* + * Find the list of interfaces, and pick + * the first interface. + */ + if (pcap_findalldevs(&devlist, errbuf) >= 0 && + devlist != NULL) { + device = strdup(devlist->name); + pcap_freealldevs(devlist); + } + if (device == NULL) { fprintf(stderr, "Can't find capture device: %s\n", errbuf); exit(-1); @@ -131,13 +141,13 @@ void CaptureInit(u_int32_t sourceIP, u_int16_t sourcePort, exit(-1); } - strncpy(source, InetAddress(sourceIP), sizeof(source) - 1); - strncpy(target, InetAddress(targetIP), sizeof(target) - 1); + strlcpy(source, InetAddress(sourceIP), sizeof(source)); + strlcpy(target, InetAddress(targetIP), sizeof(target)); /* Setup initial filter */ sprintf(filtercmds, - "host %s and host %s and port %d\n", - source, target, targetPort); + "(host %s && host %s && port %d) || icmp\n", + source, target, targetPort); if (captureDebug) { printf("datalinkOffset = %d\n", datalinkOffset);