From owner-freebsd-hackers Thu May 27 5: 1: 9 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from francine.edoropolis.org (catv6055.extern.kun.nl [131.174.116.55]) by hub.freebsd.org (Postfix) with ESMTP id 2A8E51555A for ; Thu, 27 May 1999 05:00:59 -0700 (PDT) (envelope-from bugtraq@edoropolis.org) Received: from francine.edoropolis.org (francine.edoropolis.org [131.174.116.55]) by francine.edoropolis.org (8.9.2/8.9.2); ESMTP id NAA03705 for ; Thu, 27 May 1999 13:05:17 GMT (Abuse complaints to: abuse@edoropolis.org; mail from bugtraq@edoropolis.org-s) Date: Thu, 27 May 1999 13:05:17 +0000 (GMT) From: "@cm3_1aM3r" To: freebsd-hackers@FreeBSD.ORG Subject: arp & bpf..? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, I've been experimenting around a bit with the bpf interface, but I seem to do something completely wrong. I tried to recreate an ARP request, but it doesn't seem to work. Can anyone find the problem in the source included..? I've tried just about any combination of host-to-network- and network-to-host byte order.. Thanks, -- Khamba Staring Ps: I'm not subscribed to this mailing list, so if you're replying, could you please be so kind to cc me..? --------- begin source ----------- #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ETHER_ARPPROTO 0x806 #define ETHERLEN 6 #define IPLEN 4 #define ARP_REQUEST 1 #define ARP_REPLY 2 struct dlinkproto { u_char dest[ETHERLEN]; /* u_char source[ETHERLEN]; source addy is already added in header */ u_short type; }; struct arpproto { u_short hardware; u_short protocol; u_char hlen; u_char plen; u_short opcode; u_char h_sender[ETHERLEN]; u_char p_sender[IPLEN]; u_char h_recv[ETHERLEN]; u_char p_recv[IPLEN]; }; int main(argc, argv) int argc; char *argv[]; { char bpf_dev[10], *packet; struct ifreq ifr; struct dlinkproto *dlink; struct arpproto *arp; int n = 0, fd, len; len = sizeof(struct dlinkproto) + sizeof(struct arpproto); if(!(packet = malloc(len + 50))) { perror("malloc"); exit(-1); } bzero(packet, sizeof(packet)); dlink = (struct dlinkproto *)packet; arp = (struct arpproto *)packet + sizeof(struct dlinkproto); fd = open("/dev/bpf3", O_RDWR); if(fd < 0) { perror("open"); exit(-1); } len = 0; if(ioctl(fd, BIOCGBLEN, &len) < 0) { perror("ioctl(BIOCGBLEN)"); exit(-1); } bzero(&ifr, sizeof(struct ifreq)); strcpy(ifr.ifr_name, "ed1"); if(ioctl(fd, BIOCSETIF, &ifr) < 0) { perror("ioctl(BIOCSETIF)"); exit(-1); } n = 1; if(ioctl(fd, BIOCIMMEDIATE, &n) < 0) { perror("ioctl(BIOCIMMEDIATE)"); exit(-1); } /* ** destination mac address. */ dlink->dest[0] = 0xf9; dlink->dest[1] = 0xf8; dlink->dest[2] = 0xf7; dlink->dest[3] = 0xf6; dlink->dest[4] = 0xf5; dlink->dest[5] = 0xf4; dlink->type = htons(ETHER_ARPPROTO); arp->hardware = 1; arp->protocol = htons(ETHER_ARPPROTO); arp->hlen = ETHERLEN; arp->plen = IPLEN; arp->opcode = ARP_REQUEST; arp->h_sender[0] = 0x2a; arp->h_sender[1] = 0x2b; arp->h_sender[2] = 0x2c; arp->h_sender[3] = 0x2d; arp->h_sender[4] = 0x2e; arp->h_sender[5] = 0x2f; write(fd, packet, sizeof(struct dlinkproto) + sizeof(arp)); close(fd); free(packet); return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message