Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Dec 2003 22:13:36 +0200
From:      Alin-Adrian Anton <aanton@reversedhell.net>
To:        Andy Hilker <ah@cryptobank.de>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: porting linux SOCK_RAW to freebsd
Message-ID:  <3FD77E70.7060500@reversedhell.net>
In-Reply-To: <20031210123251.GA12847@goodhope.crypta.net>
References:  <20031210123251.GA12847@goodhope.crypta.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FD77E70.7060500>