From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 10 12:13:08 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 3A75D16A4CE for ; Wed, 10 Dec 2003 12:13:08 -0800 (PST) Received: from mail.rdstm.ro (mail.rdstm.ro [193.231.233.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8A34843D1F for ; Wed, 10 Dec 2003 12:13:06 -0800 (PST) (envelope-from aanton@reversedhell.net) Received: from reversedhell.net (casa_auto [81.196.32.25]) by mail.rdstm.ro (8.12.10/8.12.1) with ESMTP id hBAKCxQI003192; Wed, 10 Dec 2003 22:13:00 +0200 Message-ID: <3FD77E70.7060500@reversedhell.net> Date: Wed, 10 Dec 2003 22:13:36 +0200 From: Alin-Adrian Anton User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.5) Gecko/20031027 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andy Hilker , freebsd-hackers@FreeBSD.ORG References: <20031210123251.GA12847@goodhope.crypta.net> In-Reply-To: <20031210123251.GA12847@goodhope.crypta.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: 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 20:13:08 -0000 Andy Hilker wrote: >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 > > > I wrote a paper on FreeBSD raw sockets a while ago. You can find it here: http://www.reversedhell.net/rawsockets/raw_tcp.tgz or here: http://packetstormsecurity.org/programming-tutorials/raw_tcp.tgz Cheers/bye, Alin.