From owner-freebsd-questions Tue Jun 20 06:18:13 1995 Return-Path: questions-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id GAA19404 for questions-outgoing; Tue, 20 Jun 1995 06:18:13 -0700 Received: from inet-gw-2.pa.dec.com (inet-gw-2.pa.dec.com [16.1.0.23]) by freefall.cdrom.com (8.6.10/8.6.6) with SMTP id GAA19398 for ; Tue, 20 Jun 1995 06:18:10 -0700 Received: from osabs0.osa.dec.com by inet-gw-2.pa.dec.com (5.65/24Feb95) id AA10616; Tue, 20 Jun 95 06:14:08 -0700 Received: by osabs0.osa.dec.com (5.57/ULTRIX-fma-041391); id AA23068; Tue, 20 Jun 95 22:14:09 +0900 Received: by osou15.osa.dec.com; (5.65/1.1.8.2/05Oct94-1005AM) id AA25735; Tue, 20 Jun 1995 22:13:34 +0900 Date: Tue, 20 Jun 1995 22:13:34 +0900 From: Inoguchi Message-Id: <9506201313.AA25735@osou15.osa.dec.com> Apparently-To: questions@FreeBSD.org Sender: questions-owner@FreeBSD.org Precedence: bulk I forgot to put with sample code. Thanks / Kinichiro Inoguchi ----------------------------------------------------------------------- Hello, I have a question about BSD packet filter. I'm using RELEASE 2.0.5, now. I want to read/write from/to bpf. I could read from bpf, but can't write ! I tested again and again, but can't put packet to Ethernet. write() system call didn't return error code until buffer was full. It seems that everything I wrote to bpf stayed in system buffer. Please tell me ! Kinichiro Inoguchi ------------------------------------------------------------------------ #include #include #include #include #include #include #include #include #define ETHERTYPE_DLI 0x6006 struct bpf_insn insns[] = { BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12), BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_DLI, 0, 1), BPF_STMT(BPF_RET+BPF_K, (u_int)-1), BPF_STMT(BPF_RET+BPF_K, 0), }; int main() { int ists; int fd; struct bpf_program bpfprog; unsigned short sval; struct ifreq ifReq; u_int flag; int bufsiz; char *buf; unsigned char sim_addr[6] = {0xaa, 0x00, 0x04, 0x00, 0x96, 0xff}; unsigned char osoi_addr[6] = {0x08, 0x00, 0x2b, 0x3c, 0xfd, 0x6d}; /* open device */ if((fd = open("/dev/bpf0", O_WRONLY)) < 0) { perror("open"); exit(0); } /* binding */ memset(&ifReq, 0, sizeof(struct ifreq)); strcpy(ifReq.ifr_name, "le0"); if(ioctl(fd, BIOCSETIF, &ifReq)) { perror("setif"); exit(0); } flag = 1; if(ioctl(fd, BIOCIMMEDIATE, &flag) < 0) { perror("immediate"); exit(0); } if(ioctl(fd, BIOCPROMISC) < 0) { perror("promisc"); exit(0); } /* filter settings */ bpfprog.bf_len = sizeof(insns) / sizeof(struct bpf_insn); bpfprog.bf_insns = insns; if(ioctl(fd, BIOCSETF, &bpfprog) < 0) { perror("SETF"); exit(0); } if(ioctl(fd, BIOCGBLEN, &bufsiz) < 0) { perror("gblen"); exit(0); } buf = (char *) malloc(bufsiz); memset(buf, 0, bufsiz); /* create packet to send */ memmove(&buf[0], sim_addr, 6); memmove(&buf[6], osoi_addr, 6); sval = htons(0x6006); memmove(&buf[12], &sval, 2); sval = 2; memmove(&buf[14], &sval, 2); /* send packet */ ists = write(fd, buf, 18); if(ists < 0) { perror("write"); } }