Allow write access to bpf in pcap_open()

看板DFBSD_submit作者時間21年前 (2004/10/18 04:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
Hello. libpcap as shipped in DragonFly 1.1-current opens the descriptor with O_RDONLY. This is not consistent with most other operating systems. Linux doesn't use bpf but it's possible to inject packets through the descriptor. Same thing on Solaris. NetBSD and OpenBSD made local changes to pcap_open() a long time ago to allow this. It would be nice if the same change was introduced in DragonFly as well. It would unbreak things like ucarp. Trivial patch follows. --- contrib/libpcap-0.8.3/pcap-bpf.c.orig 2004-10-17 21:40:36.000000000 +0200 +++ contrib/libpcap-0.8.3/pcap-bpf.c 2004-10-17 21:42:51.000000000 +0200 @@ -467,7 +467,9 @@ */ do { (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++); - fd = open(device, O_RDONLY); + fd = open(device, O_RDWR); + if (fd < 0 && errno == EACCES) + fd = open(device, O_RDONLY); } while (fd < 0 && errno == EBUSY); /*
文章代碼(AID): #11Siz_00 (DFBSD_submit)
文章代碼(AID): #11Siz_00 (DFBSD_submit)