From owner-freebsd-hackers Sat May 9 03:38:35 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id DAA26985 for freebsd-hackers-outgoing; Sat, 9 May 1998 03:38:35 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ifi.uio.no (0@ifi.uio.no [129.240.64.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id DAA26978 for ; Sat, 9 May 1998 03:38:27 -0700 (PDT) (envelope-from dag-erli@ifi.uio.no) Received: from skejdbrimir.ifi.uio.no (skejdbrimir.ifi.uio.no [129.240.65.2]) by ifi.uio.no (8.8.8/8.8.7/ifi0.2) with SMTP id MAA04985; Sat, 9 May 1998 12:37:39 +0200 (MET DST) Received: from localhost (dag-erli@localhost) by skejdbrimir.ifi.uio.no ; Sat, 9 May 1998 10:37:37 GMT Mime-Version: 1.0 To: Terry Lambert Cc: fygrave@freenet.bishkek.su (CyberPsychotic), brian@deity.loa.com, freebsd-hackers@FreeBSD.ORG Subject: Re: bpf References: <199805091001.DAA27195@usr06.primenet.com> Organization: Gutteklubben Terrasse / KRST / PUMS / YASMW X-url: http://www.stud.ifi.uio.no/~dag-erli/ X-Stop-Spam: http://www.cauce.org From: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) Date: 09 May 1998 12:37:30 +0200 In-Reply-To: Terry Lambert's message of "Sat, 9 May 1998 10:01:00 +0000 (GMT)" Message-ID: Lines: 46 X-Mailer: Gnus v5.5/Emacs 19.34 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Terry Lambert 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