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 20:32:15 +0200
On Sat, Apr 08, 2000 at 10:51:11AM -0700, Ben Greear wrote:
> 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?

No. They work like pids. 

> > > 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?

[relooking at your original message]

First you pass the wrong address to PF_PACKET sendto() -- it gets a 
sockaddr_ll, not a old style spkt address.
It is not clear from your snippet where fromlen comes from, but it is
probably not correctly initialized (it should be sizeof(struct sockaddr_ll)
Also sendto really gets a ``to'' not a ``from'', maybe you should fix
the confusing naming.


-Andi