When trying to use TCP/IP socket - "socket(AF_INET, SOCK_STREAM, 0)", tcp in this case, does the call to send and recv do a byte-order conversion automatically ?
CodePudding user response:
At the TCP level, byte ordering only applies to the IPs and ports in the TCP/IP headers, which are established when connect()
/accept()
are called. When working with instances of sockaddr_in...
structs, the user is responsible for handling byte conversions to/from network byte order as needed.
send()
/recv()
simply deal with a socket handle and a raw byte array, so there are no byte order issues when calling them. However, if the byte array has data that contains multi-byte integers in it, those have to be handled separately by the user as needed.