[dns-operations] [PATCH] dnscap on OS X

Mark Santcroos mark at NLnetLabs.nl
Fri May 18 10:56:33 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joao Damas wrote:
> Mark, have a look at
> http://osdir.com/ml/network.tcpdump.devel/2006-06/msg00056.html

The ioctl(2) does the job, but then you loose buffering capabilities.

I don't have emperical evidence to proof, but under high network load
that will become a problem probably. (I think my solution works in that
case)

Anyway, at this moment I don't have strong preference for either
solution, I just wanted the thing to compile in the first place :-)

Patch attached for the ioctl solution.

Mark

- --
Mark Santcroos
NLnet Labs
http://www.nlnetlabs.nl/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGTYZgvgq6Qtvn644RAlseAJ49XSqY6CwmdXLg1AgMaVO5CrptxACgmDo8
PXZXNEFUb0K2/ofdI9R2dP4=
=rICy
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: dnscap.c
===================================================================
RCS file: /proj/cvsroot/dnscap/dnscap.c,v
retrieving revision 1.12
diff -d -u -r1.12 dnscap.c
--- dnscap.c	16 May 2007 23:10:18 -0000	1.12
+++ dnscap.c	18 May 2007 10:55:34 -0000
@@ -32,6 +32,13 @@
 #include <sys/select.h>
 #include <sys/socket.h>
 
+#ifdef __APPLE__
+#include <sys/ioctl.h>
+#include <net/ethernet.h>
+#include <net/bpf.h>
+#include <arpa/nameser_compat.h>
+#endif
+
 #ifdef __linux__
 # define __FAVOR_BSD
 # define __USE_GNU
@@ -743,6 +750,9 @@
 	     mypcap = ISC_LIST_NEXT(mypcap, link))
 	{
 		struct bpf_program bpfp;
+#ifdef __APPLE__
+		unsigned int ioarg = 1;
+#endif
 
 		errbuf[0] = '\0';
 		if (pcap_offline == NULL)
@@ -764,6 +774,9 @@
 		else if (linktype != mypcap->dlt)
 			linktype = DLT_LOOP;
 		mypcap->fdes = pcap_get_selectable_fd(mypcap->pcap);
+#ifdef __APPLE__
+		ioctl(mypcap->fdes, BIOCIMMEDIATE, &ioarg);
+#endif
 		if (pcap_offline == NULL)
 			if (pcap_setnonblock(mypcap->pcap, TRUE, errbuf) < 0) {
 				fprintf(stderr, "%s: pcap_setnonblock: %s\n",
@@ -792,7 +805,7 @@
 	int n;
 
 	do {
-		readfds = mypcap_fdset;
+		FD_COPY(&mypcap_fdset, &readfds);
 		n = select(pcap_maxfd+1, &readfds, NULL, NULL, NULL);
 	} while (n < 0 && errno == EINTR && !main_exit);
 	if (n < 0) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dnscap_osx_ioctl.diff.sig
Type: application/octet-stream
Size: 65 bytes
Desc: not available
URL: <https://lists.dns-oarc.net/pipermail/dns-operations/attachments/20070518/daba5c86/attachment.obj>


More information about the dns-operations mailing list