Date: 09 May 1998 12:37:30 +0200 From: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) To: Terry Lambert <tlambert@primenet.com> Cc: fygrave@freenet.bishkek.su (CyberPsychotic), brian@deity.loa.com, freebsd-hackers@FreeBSD.ORG Subject: Re: bpf Message-ID: <xzpwwbv20id.fsf@skejdbrimir.ifi.uio.no> In-Reply-To: Terry Lambert's message of "Sat, 9 May 1998 10:01:00 %2B0000 (GMT)" References: <199805091001.DAA27195@usr06.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert <tlambert@primenet.com> writes: > > could you please give the sample of BIOCSETIF ioctl call? I think i should > > ivolve some particular structure or something here, but i checked manual > > and didn't find any reference > Meanwhile, look at the CAP code. 8-|. Hmmm... OK, basically you want to do something like this to capture packets: char bpf_dev[IFNAMSIZ], *buf; struct ifreq ifr; int n = 0, fd, len; /* Find an available BPF device */ do { sprintf(bpf_dev, "/dev/bpf%d", n++); fd = open(bpf_dev, O_RDONLY); } while (errno == EBUSY); if (fd < 0) /* it didn't work! */; /* Get buffer length */ if (ioctl(fd, BIOCGBLEN, &len) < 0) /* ouch */; if (!(buf = malloc(len))) /* ouch! */; /* Set interface to ep0 */ bzero(&ifr, sizeof(struct ifreq)); strcpy(ifr.ifr_name, "ep0"); if (ioctl(fd, BIOCSETIF, &ifr) < 0) /* ouch! */; /* Set immediate mode */ n = 1; if (ioctl(fd, BIOCIMMEDIATE, &n) < 0) /* ouch! */; /* Read packets */ while (1) { read(fd, buf, len); /* do something nifty with them */ } -- Noone else has a .sig like this one. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpwwbv20id.fsf>