0

I wanted to use ntohs initially, but the following section in the Remarks forced me to ask here for help:

If the netshort parameter is already in host byte order, then this function will reverse it. It is up to the application to determine if the byte order must be reversed.

I could try something like this:

short int i= 0x1;
char *c= (char*)&i;

if(c[0] == 1)  // little endian, use ntohs

but I was wondering if there is Winsock API function that does the same?

AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84

1 Answers1

2

Although I did not test it, the WSANtohs function does not include a remark to have the application check if the byte order must be reversed. It does say that it checks the network byte order:

The socket passed in the s parameter is used to determine the network byte order required based on the Winsock catalog protocol entry associated with the socket.

Ton Plooij
  • 2,583
  • 12
  • 15