Ethereal-dev: [ethereal-dev] Re: Question on sendto with PF_PACKET and SOCK_RAW.
Andi Kleen wrote:
>
> 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.
If I have to go back to using the SOCK_PACKET stuff I'll try to
debug this and let you know what I find...
>
> >
> > 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.
Out of curiosity, if I manage to remove interface 4 at run-time,
and have bound to index 5 earlier, will I now be bound to the
wrong interface?
> > 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
Same (wrong) result, unfortunately. The bind system call did not return
< 0, but could I have screwed it up enough that the sendto cannot work?
I've tracked the file descriptor through the code, and it's the same one
I bound earlier...
I'll swap my ethernet interfaces to see if putting it on eth0 instead of
eth8 will make any difference...
Thanks,
Ben
--
Ben Greear (greearb@xxxxxxxxxxxxxxx) http://www.candelatech.com
Author of ScryMUD: scry.wanfear.com 4444 (Released under GPL)
http://scry.wanfear.com http://scry.wanfear.com/~greear