Network byte order 
Author Message
 Network byte order



Quote:
>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  
 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  
 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  
 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.

Use hton() and ntoh() instead of making any assumptions.



Sat, 17 Apr 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. char * in network byte order to unsigned long int

2. Network Byte Order

3. Network Byte Order

4. convert floating-point value to network byte-order

5. Network Byte Order Question

6. byte order and bit order

7. Writting low-order or high-order bytes

8. Socket Program(Host Order/Network Order)

9. byte order

10. Byte order and portability

11. Byte-Ordering

12. Strange byte order using fread() and fwrite()

 

 
Powered by phpBB® Forum Software