network byte order

J

Jesse Engle

i'm learning how to do some basic low-level network programming. the site
i'm reading talks about "network byte order" and "host byte order". the
thing is, it doesn't give an explanation as to what they are.

i understand most of what the main socket functions do, but i don't
understand what's up with this network byte order stuff.

could someone explain?
 
C

ChrisD

| i'm learning how to do some basic low-level network programming. the site
| i'm reading talks about "network byte order" and "host byte order". the
| thing is, it doesn't give an explanation as to what they are.| i understand most of what the main socket functions do, but i don't
| understand what's up with this network byte order stuff.| could someone explain?

Hi Jesse

It is the order of the bytes used when the cpu interprets a chunk of
bytes as e.g. an int. Search google for "endian", the first hit gives

http://www.cs.umass.edu/~verts/cs32/endian.html

which describes it better than me.
 
D

Dan Pop

In said:
i'm learning how to do some basic low-level network programming. the site
i'm reading talks about "network byte order" and "host byte order". the
thing is, it doesn't give an explanation as to what they are.

i understand most of what the main socket functions do, but i don't
understand what's up with this network byte order stuff.

could someone explain?

If you're not familiar with the concept of byte order, look it up.

The network byte order is big endian. The host byte order, is whatever
the host actually running your program makes it to be (usually either
little endian or big endian). So, whenever you need to supply
some data in network byte order, be sure to use the conversion
functions/macros described in your network programming tutorial.
Ditto for the case when you get data in the network byte order,
but want to use it on your local host.

Having the network impose a certain byte order makes data exchanges
between hosts using different byte orders possible. Be *very* careful
with the networking API functions, because, if you supply the data in the
wrong byte order, the bug(s) won't be easy to find. Especially if your
host uses the same byte order as the network and the conversion functions
are no-ops.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top