Date: Thu, 27 May 1999 13:05:17 +0000 (GMT) From: "@cm3_1aM3r" <bugtraq@edoropolis.org> To: freebsd-hackers@FreeBSD.ORG Subject: arp & bpf..? Message-ID: <Pine.BSF.4.05.9905271256060.3693-100000@francine.edoropolis.org>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/time.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> #include <net/route.h> #include <net/bpf.h> #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9905271256060.3693-100000>