Sendto In Raw Socket

91 views Asked by At

the sendto function we have to pass destination struct sockaddr or sockaddr_in But what's the purpose?

isn't it, if we use raw Socket, we create our own header, which means we will specify the address directly in the header not in the sockaddr_in struct?

Does that mean we use sendto on raw socket is to determine which interface to use?

1

There are 1 answers

0
Steffen Ullrich On

A raw IP socket contains only network layer information as target, i.e. IP address. To deliver the packet in the local network one also needs to have information for the lower layers, i.e. which network interface to use for sending, which MAC address to have as target at the link layer etc. The target IP address given in sendto is used to determine these information.