raw sockets - C `sendto` versus `write` -
correct me if i'm wrong, understanding of sending raw packet inevitably defined buffering array of bytes in array, , writing socket. however, example code i've seen far tend towards sendto, send used, , i've never seen code other own use write. missing something? apparent preoccupation complicating code this?
why use send , sendto when write seems me obvious choice when dealing raw sockets?
sendto typically used unconnected udp sockets or raw sockets. takes parameter specifying destination address/port of packet. send , write don't have parameter, there's no way tell data go.
send used tcp sockets , connected udp sockets. since connection has been established, destination not need specified, , in fact function doesn't have parameter one.
while write function can used in places send can used, lacks flags parameter can enable behaviors on tcp sockets. doesn't return same set of error codes send, if things go wrong might not meaningful error code. in theory use write on raw socket if ip_hdrincl socket option set, again it's not preferable since doesn't support same error codes send.
Comments
Post a Comment