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.
48/480
Context English State
/*
* Structure used by kernel to store most
* addresses.
*/
struct sockaddr {
unsigned char sa_len; /* total length */
sa_family_t sa_family; /* address family */
char sa_data[14]; /* actually longer; address value */
};
#define SOCK_MAXADDRLEN 255 /* longest possible addresses */
Please note the <emphasis>vagueness</emphasis> with which the <varname>sa_data</varname> field is declared, just as an array of <constant>14</constant> bytes, with the comment hinting there can be more than <constant>14</constant> of them.
This vagueness is quite deliberate. Sockets is a very powerful interface. While most people perhaps think of it as nothing more than the Internet interface—and most applications probably use it for that nowadays—sockets can be used for just about <emphasis>any</emphasis> kind of interprocess communications, of which the Internet (or, more precisely, <acronym>IP</acronym>) is only one.
The <filename>sys/socket.h</filename> refers to the various types of protocols sockets will handle as <emphasis>address families</emphasis>, and lists them right before the definition of <varname>sockaddr</varname>:
/*
* Address families.
*/
#define AF_UNSPEC 0 /* unspecified */
#define AF_LOCAL 1 /* local to host (pipes, portals) */
#define AF_UNIX AF_LOCAL /* backward compatibility */
#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
#define AF_IMPLINK 3 /* arpanet imp addresses */
#define AF_PUP 4 /* pup protocols: e.g. BSP */
#define AF_CHAOS 5 /* mit CHAOS protocols */
#define AF_NS 6 /* XEROX NS protocols */
#define AF_ISO 7 /* ISO protocols */
#define AF_OSI AF_ISO
#define AF_ECMA 8 /* European computer manufacturers */
#define AF_DATAKIT 9 /* datakit protocols */
#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
#define AF_SNA 11 /* IBM SNA */
#define AF_DECnet 12 /* DECnet */
#define AF_DLI 13 /* DEC Direct data link interface */
#define AF_LAT 14 /* LAT */
#define AF_HYLINK 15 /* NSC Hyperchannel */
#define AF_APPLETALK 16 /* Apple Talk */
#define AF_ROUTE 17 /* Internal Routing Protocol */
#define AF_LINK 18 /* Link layer interface */
#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
#define AF_COIP 20 /* connection-oriented IP, aka ST II */
#define AF_CNT 21 /* Computer Network Technology */
#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
#define AF_IPX 23 /* Novell Internet Protocol */
#define AF_SIP 24 /* Simple Internet Protocol */
#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
#define AF_ISDN 26 /* Integrated Services Digital Network*/
#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
#define pseudo_AF_KEY 27 /* Internal key-management function */
#define AF_INET6 28 /* IPv6 */
#define AF_NATM 29 /* native ATM access */
#define AF_ATM 30 /* ATM */
#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
* in interface output routine
*/
#define AF_NETGRAPH 32 /* Netgraph sockets */
#define AF_SLOW 33 /* 802.3ad slow protocol */
#define AF_SCLUSTER 34 /* Sitara cluster protocol */
#define AF_ARP 35
#define AF_BLUETOOTH 36 /* Bluetooth sockets */
#define AF_MAX 37
The one used for <acronym>IP</acronym> is <symbol>AF_INET</symbol>. It is a symbol for the constant <constant>2</constant>.
It is the <emphasis>address family</emphasis> listed in the <varname>sa_family</varname> field of <varname>sockaddr</varname> that decides how exactly the vaguely named bytes of <varname>sa_data</varname> will be used.
Specifically, whenever the <emphasis>address family</emphasis> is <symbol>AF_INET</symbol>, we can use <varname>struct sockaddr_in</varname> found in <filename>netinet/in.h</filename>, wherever <varname>sockaddr</varname> is expected:
/*
* Socket address, internet style.
*/
struct sockaddr_in {
uint8_t sin_len;
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
We can visualize its organization this way:
_ external ref='sockets/sain' md5='__failed__'
0 1 2 3
+--------+--------+-----------------+
0 | 0 | Family | Port |
+--------+--------+-----------------+
4 | IP Address |
+-----------------------------------+
8 | 0 |
+-----------------------------------+
12 | 0 |
+-----------------------------------+
<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:

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:5459
String age
a year ago
Source string age
a year ago
Translation file
books/developers-handbook.pot, string 902