Source string Read only

_
(itstool) path: imageobject/imagedata This is a reference to an external file such as an image or video. When the file changes, the md5 hash will change to let you know you need to update your localized copy. The msgstr is not used at all. Set it to whatever you like once you have updated your copy of the file.
47/470
Context English State
<imageobject> <imagedata fileref="sockets/sain"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>sockaddr_in</phrase> </textobject>
The three important fields are <varname>sin_family</varname>, which is byte 1 of the structure, <varname>sin_port</varname>, a 16-bit value found in bytes 2 and 3, and <varname>sin_addr</varname>, a 32-bit integer representation of the <acronym>IP</acronym> address, stored in bytes 4-7.
Now, let us try to fill it out. Let us assume we are trying to write a client for the <emphasis>daytime</emphasis> protocol, which simply states that its server will write a text string representing the current date and time to port 13. We want to use <acronym>TCP/IP</acronym>, so we need to specify <constant>AF_INET</constant> in the address family field. <constant>AF_INET</constant> is defined as <constant>2</constant>. Let us use the <acronym>IP</acronym> address of <systemitem class="ipaddress">192.43.244.18</systemitem>, which is the time server of US federal government (<systemitem class="fqdomainname">time.nist.gov</systemitem>).
_ external ref='sockets/sainfill' md5='__failed__'
0 1 2 3
+--------+--------+-----------------+
0 | 0 | 2 | 13 |
+-----------------+-----------------+
4 | 192.43.244.18 |
+-----------------------------------+
8 | 0 |
+-----------------------------------+
12 | 0 |
+-----------------------------------+
<imageobject> <imagedata fileref="sockets/sainfill"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>Specific example of sockaddr_in</phrase> </textobject>
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">192.43.244.18</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.
Why?
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.

Loading…

No matching activity found.

Browse all component changes

Things to check

Multiple failing checks

The translations in several languages have failing checks

Reset

Glossary

English English
No related strings found in the glossary.

Source information

Context
_
Source string comment
(itstool) path: imageobject/imagedata This is a reference to an external file such as an image or video. When the file changes, the md5 hash will change to let you know you need to update your localized copy. The msgstr is not used at all. Set it to whatever you like once you have updated your copy of the file.
Flags
read-only
Source string location
book.translate.xml:5519 book.translate.xml:5639
String age
a year ago
Source string age
a year ago
Translation file
books/developers-handbook.pot, string 914