C `sendto` vs` write`

Correct me if I'm wrong, but my understanding of sending a raw packet is inevitably defined as buffering an array of bytes in the array and writing it to the socket. However, most of the code examples I've seen so far tend to sendtobe rarely used send, and I have never seen code other than my own use write. Am I missing something? What complicates such code with this apparent concern?

Why use sendand sendtowhen writeit seems to me the obvious choice when working with raw sockets?

+4
source share
1 answer

sendtocommonly used with unbound UDP sockets or with raw sockets. It takes a parameter that defines the address / port of the packet receiver. sendand writedo not have this parameter, so there is no way to tell the data where to go.

sendused with TCP sockets and connected UDP sockets. Since the connection is established, the destination does not need to be specified, and in fact this function does not have a parameter for one.

write , send , flags, TCP. , send, , - , . write , IP_HDRINCL, , , send.

+5

Source: https://habr.com/ru/post/1627869/


All Articles