Ethereal-dev: [ethereal-dev] Re: Question on sendto with PF_PACKET and SOCK_RAW.

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Andi Kleen" <ak@xxxxxxx>
Date: Sat, 8 Apr 2000 12:20:45 +0200
On Sat, Apr 08, 2000 at 12:38:13AM -0700, Ben Greear wrote:
> I can't seem to find any documentation anywhere on this....
> 
> I want to use the new PF_PACKET and SOCK_RAW options to create
> a socket that I can send raw ethernet frames on.  SOCK_PACKET
> was working ok for me, but it's deprecated, evidently, and
> it wasn't working on eth8, so I figured it was time to upgrade...

Although it is deprecated that would be a bug.

> 
> Also, using SIOCGIFINDEX, looking for eth1, gives me '3', when the
> only interfaces shown by ifconfig -a are eth0, eth1, and lo (in that order).
> Is that correct?

Yes, interface indexes count all interfaces. See netdevice(7) for details.
They have nothing to do with the name.

> sendto gives this error every time: sendto:  Invalid argument
> To send I use this:
> int foo::sendPktTo(int dev_socket, const char* dev, const char* msg,
>                    int msg_len) {
>    int r = 0;
> 
>    struct sockaddr from;
>    memset(&from, 0, sizeof(from));
>    from.sa_family = AF_INET;

SOCK_PACKET obviously does not like AF_INET addresses and tells you that.
Try it with AF_PACKET


>    strcpy(from.sa_data, dev);
>       
>    r = sendto(dev_socket, msg, msg_len, 0, &from, fromlen);
>    if (r < 0) {
>       VLOG << "ERROR: foo::sendto:  " << strerror(errno) << endl;
>    }


-Andi