vindyz
vindyz

Reputation: 1101

What happens if ntohl() is called with an integer that is already in host byte order?

If I use ntohl() on an integer which is already in host byte order will that cause any problems?

If not, how does the ntohl() function know its argument is already in host byte order?

Upvotes: 1

Views: 1585

Answers (3)

Zan Lynx
Zan Lynx

Reputation: 54325

You are asking "If I call ntohl() on an integer twice, will it cause a problem?"

The answer is "Yes."

This should be obvious if you think about the name of the function. It is named "Network to Host Long". After calling this function the integer is now in host byte order not in network byte order.

Upvotes: 0

Michael F
Michael F

Reputation: 40830

It doesn't know. It assumes it's given an integer in network byte order and converts it to host, if necessary - that is all.

Upvotes: 1

cnicutar
cnicutar

Reputation: 182619

Your question doesn't make any sense. For ntohl nothing is high-order or low-order.

  • If the endianness of the system is the same as network order, it will do nothing
  • Otherwise it will swap stuff around

Upvotes: 3

Related Questions