Network byte order

>I am currently porting some code from a UNIX platform to Windows95. I >came across a function called htonl().

Note that this isn't a standard C library function but your post does touch on some good programming principles.

Quote:

> This function apparently changes >a 32-bit number from host byte order to network byte order. I'm not >actually looking for code for such a function (the function already >exists within my compiler's libraries), but I was interested in finding >out what "network byte order" is exactly.

The point of functions such as this is to hide such details, you simply don't need to know. You should always call the function to convert between host and network byte order even if you 'know' that they are the same. This is what programming portably is all about, do it and your code will run on any system whatever the host or network byte orders.

Quote:

> I believe that the function >must switch the 32-bit number to either big-endian or little-endian, but >I'm unsure which.

TCP/IP network byte order is big-endian. But try to forget that when it comes to writing code. It might be useful to know for debugging.

-- -----------------------------------------

-----------------------------------------

Fri, 16 Apr 1999 03:00:00 GMT

Kevin M Sext#2 / 5

Network byte order

I am currently porting some code from a UNIX platform to Windows95. I came across a function called htonl(). This function apparently changes a 32-bit number from host byte order to network byte order. I'm not actually looking for code for such a function (the function already exists within my compiler's libraries), but I was interested in finding out what "network byte order" is exactly. I believe that the function must switch the 32-bit number to either big-endian or little-endian, but I'm unsure which. Thanks in advance for any help you can provide. If you could, please email any replies to me.

Kevin

Fri, 16 Apr 1999 03:00:00 GMT

Roos van Raadshooven L.#3 / 5

Network byte order

Quote:

>I am currently porting some code from a UNIX platform to Windows95. I >came across a function called htonl(). This function apparently changes >a 32-bit number from host byte order to network byte order. I'm not >actually looking for code for such a function (the function already >exists within my compiler's libraries), but I was interested in finding >out what "network byte order" is exactly. I believe that the function >must switch the 32-bit number to either big-endian or little-endian, but >I'm unsure which. Thanks in advance for any help you can provide. If >you could, please email any replies to me. >Kevin

Network byte order is big endian. PC byteorder is little endian.

Leon. -- Windows No Thanks!

Fri, 16 Apr 1999 03:00:00 GMT

Dann Corbi#4 / 5

Network byte order

[snip]

Quote:

> Network byte order is big endian. PC byteorder is little endian.

<Non-ANSI C schpiel follows:>

What about a Mac? The Motorola 68000 series CPU is opposite byte order from the Intel 80x86 series (if I remember correctly). AMIGA? ACORN? Transputer? It's best not to make any assumptions.