From owner-freebsd-hackers Tue Jul 23 17:25:14 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id RAA26907 for hackers-outgoing; Tue, 23 Jul 1996 17:25:14 -0700 (PDT) Received: from mail0.iij.ad.jp (root@mail0.iij.ad.jp [192.244.176.61]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id RAA26901 for ; Tue, 23 Jul 1996 17:25:11 -0700 (PDT) Received: from uucp1.iij.ad.jp (uucp1.iij.ad.jp [192.244.176.73]) by mail0.iij.ad.jp (8.6.12+2.4W/3.3W9-MAIL) with ESMTP id JAA24172; Wed, 24 Jul 1996 09:24:26 +0900 Received: (from uucp@localhost) by uucp1.iij.ad.jp (8.6.12+2.4W/3.3W9-UUCP) with UUCP id JAA06060; Wed, 24 Jul 1996 09:24:26 +0900 Received: from xxx.fct.kgc.co.jp by yyy.kgc.co.jp (8.7.5/3.4W:95122611) id JAA11392; Wed, 24 Jul 1996 09:12:07 +0900 (JST) Received: from localhost by xxx.fct.kgc.co.jp (8.6.12/3.3W8:95062916) id JAA00403; Wed, 24 Jul 1996 09:12:07 +0900 Message-Id: <199607240012.JAA00403@xxx.fct.kgc.co.jp> To: "K.V.S. Sankaram" cc: hackers@FreeBSD.org Subject: Re: How to use BPF ? In-reply-to: "K.V.S. Sankaram"'s message of 23 Jul 1996 19:29:01 +0900 References: Date: Wed, 24 Jul 1996 09:12:06 +0900 From: Toshihiro Kanda Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk > 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)