views:

774

answers:

1

How do I send data on a SOCK_PACKET socket without specifying which host it's bound for? I've constructed the IP header to show where it should go, but write() won't work.

+1  A: 

Don't. use write(), use sendto().

If you use PF_PACKET,SOCK_DGRAM, then it builds the link-layer headers for you, which is normally what you want. You still need to build whatever higher protocol you are using on top though.

You specify a sockaddr_ll in the destination parameter. You can specify a link-layer unicast address, multicast address or broadcast address.

MarkR
Does it matter what host I specify with sendto() if the IP header contains the destination
computergeek6
Yes absolutely; if you're sending an IP packet, you still need to send it to the appropriate link-layer address if you're using PF_PACKET, SOCK_DGRA. If you want to send raw IP packets, I recommend that you use PF_INET, SOCK_RAW instead.
MarkR
If I use PF_INET, SOCK_RAW, would I have to bind the socket?
computergeek6