Source string Read only

(itstool) path: sect4/mediaobject
Context English State
By the way the <varname>sin_addr</varname> field is declared as being of the <varname>struct in_addr</varname> type, which is defined in <filename>netinet/in.h</filename>:
* Internet address (a structure for historical reasons)
struct in_addr {
in_addr_t s_addr;
In addition, <varname>in_addr_t</varname> is a 32-bit integer.
The <systemitem class="ipaddress"></systemitem> is just a convenient notation of expressing a 32-bit integer by listing all of its 8-bit bytes, starting with the <emphasis>most significant</emphasis> one.
So far, we have viewed <varname>sockaddr</varname> as an abstraction. Our computer does not store <varname>short</varname> integers as a single 16-bit entity, but as a sequence of 2 bytes. Similarly, it stores 32-bit integers as a sequence of 4 bytes.
Suppose we coded something like this:
sa.sin_family = AF_INET;
sa.sin_port = 13;
sa.sin_addr.s_addr = (((((192 &lt;&lt; 8) | 43) &lt;&lt; 8) | 244) &lt;&lt; 8) | 18;
What would the result look like?
Well, that depends, of course. On a <trademark class="registered">Pentium</trademark>, or other x86, based computer, it would look like this:
_ external ref='sockets/sainlsb' md5='__failed__'
0 1 2 3
0 | 0 | 2 | 13 | 0 |
4 | 18 | 244 | 43 | 192 |
8 | 0 |
12 | 0 |
<imageobject> <imagedata fileref="sockets/sainlsb"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>sockaddr_in on an Intel system</phrase> </textobject>
On a different system, it might look like this:
_ external ref='sockets/sainmsb' md5='__failed__'
0 1 2 3
0 | 0 | 2 | 0 | 13 |
4 | 192 | 43 | 244 | 18 |
8 | 0 |
12 | 0 |
<imageobject> <imagedata fileref="sockets/sainmsb"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>sockaddr_in on an MSB system</phrase> </textobject>
And on a PDP it might look different yet. But the above two are the most common ways in use today.
Ordinarily, wanting to write portable code, programmers pretend that these differences do not exist. And they get away with it (except when they code in assembly language). Alas, you cannot get away with it that easily when coding for sockets.
Because when communicating with another computer, you usually do not know whether it stores data <emphasis>most significant byte</emphasis> (<acronym>MSB</acronym>) or <emphasis>least significant byte</emphasis> (<acronym>LSB</acronym>) first.
You might be wondering, <emphasis><quote>So, will sockets not handle it for me?</quote></emphasis>
It will not.
While that answer may surprise you at first, remember that the general sockets interface only understands the <varname>sa_len</varname> and <varname>sa_family</varname> fields of the <varname>sockaddr</varname> structure. You do not have to worry about the byte order there (of course, on FreeBSD <varname>sa_family</varname> is only 1 byte anyway, but many other <trademark class="registered">UNIX</trademark> systems do not have <varname>sa_len</varname> and use 2 bytes for <varname>sa_family</varname>, and expect the data in whatever order is native to the computer).
But the rest of the data is just <varname>sa_data[14]</varname> as far as sockets goes. Depending on the <emphasis>address family</emphasis>, sockets just forwards that data to its destination.
Indeed, when we enter a port number, it is because we want the other computer to know what service we are asking for. And, when we are the server, we read the port number so we know what service the other computer is expecting from us. Either way, sockets only has to forward the port number as data. It does not interpret it in any way.
Similarly, we enter the <acronym>IP</acronym> address to tell everyone on the way where to send our data to. Sockets, again, only forwards it as data.
That is why, we (the <emphasis>programmers</emphasis>, not the <emphasis>sockets</emphasis>) have to distinguish between the byte order used by our computer and a conventional byte order to send the data in to the other computer.
We will call the byte order our computer uses the <emphasis>host byte order</emphasis>, or just the <emphasis>host order</emphasis>.
There is a convention of sending the multi-byte data over <acronym>IP</acronym> <emphasis><acronym>MSB</acronym> first</emphasis>. This, we will refer to as the <emphasis>network byte order</emphasis>, or simply the <emphasis>network order</emphasis>.
Now, if we compiled the above code for an Intel based computer, our <emphasis>host byte order</emphasis> would produce:
<imageobject> <imagedata fileref="sockets/sainlsb"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>Host byte order on an Intel system</phrase> </textobject>


No matching activity found.

Browse all component changes

Things to check

Multiple failing checks

The translations in several languages have failing checks



English English
No related strings found in the glossary.

Source information

Source string comment
(itstool) path: sect4/mediaobject
Source string location
String age
a year ago
Source string age
a year ago
Translation file
books/developers-handbook.pot, string 930