Byte Order on workstations

Mark Warren mwarren at rws1.ma30.bull.com
Fri Jun 28 21:11:59 AEST 1991


wangjw at cs.purdue.EDU (Jingwen Wang) writes:


>  I am a little curious about the byte order differences on different
>workstations. 

>  When we communicate via sockets over the network, we don't need to care
>about the differences between network order and host order. This is true 
>if we are communicating among the workstations of the same byte order.

>  But If we communicate between workstations of different byte order, .e.g., 
>Dec station -- Sun, we must first transform data into network order before 
>sending them and change them back to host order after receiving them.

First, all messages on the network are in "network" byte order, as far as the
message headers are concerned.  Even on machines whose host order is the
same as the network byte order, the hton{l,s}() and friends are used, even if
they are noops for a given machine.  The important thing is that for ANY
machine, network packets always have their headers and trailers in network,
not host, order.

>  My question is that in a network environment, how is this problem solved?
>For example, when this mail reaches your machine, how does your machine 
>know that this mail is from a Sun instead of a Dec Station? How does your
>machine process the byte order?

In general, the problem for the DATA contained in a message is not solved.
Mail works pretty well because it is byte stream data, so byte order is
immaterial.  For binary data, the the byte order of a message may be wrong.
It is up to cooperating applications to perform any necessary byte swapping
and re-alignment to make binary data usable.  One way this is done is by
using XDR's in Sun RPC.  This is ENTIRELY up to the application programs.
The network won't do anything for you except preserve the network headers.
--

 == Mark Warren                      Bull HN Information Systems Inc. ==
 == (508) 294-3171 (FAX 294-3020)    300 Concord Road     MS836A      ==
 == M.Warren at bull.com                Billerica, MA 01821              ==



More information about the Comp.unix.internals mailing list