From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 10 04:32:55 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3A96016A4CE for ; Wed, 10 Dec 2003 04:32:55 -0800 (PST) Received: from mail.crypta.net (cryptobank.biz [217.160.183.210]) by mx1.FreeBSD.org (Postfix) with ESMTP id B738B43D28 for ; Wed, 10 Dec 2003 04:32:53 -0800 (PST) (envelope-from ah@cryptobank.de) Received: by mail.crypta.net (Postfix, from userid 1001) id CC44C78E4C; Wed, 10 Dec 2003 13:32:51 +0100 (CET) Date: Wed, 10 Dec 2003 13:32:51 +0100 From: Andy Hilker To: freebsd-hackers@FreeBSD.ORG Message-ID: <20031210123251.GA12847@goodhope.crypta.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-PGP-Key: http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0xEC6E1071 X-PGP-Fingerprint: 9B2E 5892 AD93 D5C5 FB8E 3912 35D6 951B EC6E 1071 Organization: cryptobank - Andy Hilker Subject: porting linux SOCK_RAW to freebsd X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Dec 2003 12:32:55 -0000 Hi, i try porting a little utility from linux to freebsd. Maybe someone could give me a hint, what i am doing wrong. -- snip -- /* Note: not portable */ // if ((s = socket(AF_INET, SOCK_PACKET, SOCK_PACKET)) < 0) { // ??? ported if ((s = socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) < 0) { if (errno == EPERM) fprintf(stderr, "programm must run as root\n"); else perror("programm: socket"); if (! debug) return 2; } /* Fill in the source address, if possible. The code to retrieve the local station address is Linux specific. */ /* Note: not portable */ /* if (! opt_no_src_addr){ struct ifreq if_hwaddr; unsigned char *hwaddr = ifr_addr.sa_data; strcpy(if_hwaddr.ifr_name, ifname); if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) { fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname, strerror(errno)); return 1; } memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6); if (verbose) { printf("The hardware address (SIOCGIFHWADDR) of %s is type %d " "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", ifname, if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); } } */ // ??? ported, xx:xx:xx:xx:xx:xx = MAC Adress of sender memcpy(outpack+6, "xx:xx:xx:xx:xx:xx", 6); /* Note: not portable */ /* whereto.sa_family = 0; strcpy(whereto.sa_data, ifname); if ((i = sendto(s, outpack, pktsize, 0, &whereto, sizeof(whereto))) < 0) perror("sendto"); else if (debug) printf("sendto returned %d.\n", i); */ // ??? ported, fxp0 = sending interface whereto.sa_family = 0; strcpy(whereto.sa_data, "fxp0"); if ((i = sendto(s, outpack, pktsize, 0, &whereto, sizeof(whereto))) < 0) perror("sendto"); else if (debug) printf("sendto returned %d.\n", i); -- snip -- bye, Andy