user11126281
user11126281

Reputation:

Should I convert to network byte order (hton*) if all machines on the network use little-endian?

I am writing a client-server application that uses UDP to send datagrams between two Intel x64 computers. I control the hardware on both sides and have verified that they use identical little-endian architecture.

As I can confirm both machines are little-endian, are there any benefits given by using hton* functions to change the byte order before sending my data? Surely this creates a very slight performance decrease and gives no benefit?

Upvotes: 3

Views: 64

Answers (1)

dbush
dbush

Reputation: 223739

Your protocol could always be used in ways you don't expect. The program may get picked up by someone running on an ARM or Sun system, for example.

Since values sent over a network are generally expected to be in network byte order, it's best to convert your values before sending. Any effect on performance would be negligible and would be considered premature optimization.

Upvotes: 1

Related Questions