Date: Wed, 24 Jul 1996 09:12:06 +0900 From: Toshihiro Kanda <candy@fct.kgc.co.jp> To: "K.V.S. Sankaram" <kasturi@teil.soft.net> Cc: hackers@FreeBSD.org Subject: Re: How to use BPF ? Message-ID: <199607240012.JAA00403@xxx.fct.kgc.co.jp> In-Reply-To: "K.V.S. Sankaram"'s message of 23 Jul 1996 19:29:01 %2B0900 References: <Pine.SGI.3.93.960723142034.11451D-100000@teil.soft.net>
next in thread | previous in thread | raw e-mail | index | archive | help
> I am facing problems in sending packets through BPF. Can anybody give me > > some idea (or steps) as to how to configure BPF and send packets through it ? static struct bpf_program prog; First, initialize prog. Then, char *name = "ed0"; fd = open("/dev/bpf0", O_RDWR); if (fd >= 0) { struct bpf_version ver; if (ioctl(fd, BIOCVERSION, &ver) == 0) { if (BPF_MAJOR_VERSION == ver.bv_major && BPF_MINOR_VERSION <= ver.bv_minor) { unsigned int blen = BPF_BUFFER_SIZE; if (ioctl(fd, BIOCSBLEN, &blen) == 0) { struct ifreq ifr; strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, &ifr) == 0) { unsigned int im = 1; if (ioctl(fd, BIOCIMMEDIATE, &im) == 0) { if (ioctl(fd, BIOCSETF, prog) == 0) { err = fd; } } } } } } if (err < 0) close(fd); } : : : write(fd, data, length); Note: data[12] and data[13] (ether type) must be host byte order (NOT network byte order). I believe this is a bug, though FreeBSD core team don't think so. candy@fct.kgc.co.jp (Toshihiro Kanda)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607240012.JAA00403>