The translation is temporarily closed for contributions due to maintenance, please come back later.

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.
Context English State
/*
* daytime.c
*
* Programmed by G. Adam Stanislav
* 19 June 2001
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int main(int argc, char *argv[]) {
register int s;
register int bytes;
struct sockaddr_in sa;
struct hostent *he;
char buf[BUFSIZ+1];
char *host;

if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
return 1;
}

bzero(&sa, sizeof sa);

sa.sin_family = AF_INET;
sa.sin_port = htons(13);

host = (argc > 1) ? (char *)argv[1] : "time.nist.gov";

if ((he = gethostbyname(host)) == NULL) {
herror(host);
return 2;
}

bcopy(he->h_addr_list[0],&sa.sin_addr, he->h_length);

if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) {
perror("connect");
return 3;
}

while ((bytes = read(s, buf, BUFSIZ)) > 0)
write(1, buf, bytes);

close(s);
return 0;
}
We now can type a domain name (or an <acronym>IP</acronym> address, it works both ways) on the command line, and the program will try to connect to its <emphasis>daytime</emphasis> server. Otherwise, it will still default to <systemitem class="fqdomainname">time.nist.gov</systemitem>. However, even in this case we will use <function>gethostbyname</function> rather than hard coding <systemitem class="ipaddress">192.43.244.18</systemitem>. That way, even if its <acronym>IP</acronym> address changes in the future, we will still find it.
Since it takes virtually no time to get the time from your local server, you could run <application>daytime</application> twice in a row: First to get the time from <systemitem class="fqdomainname">time.nist.gov</systemitem>, the second time from your own system. You can then compare the results and see how exact your system clock is:
<prompt>%</prompt> <userinput>daytime ; daytime localhost</userinput>


52080 01-06-20 04:02:33 50 0 0 390.2 UTC(NIST) *
2001-06-20T04:02:35Z
<prompt>%</prompt>
As you can see, my system was two seconds ahead of the <acronym>NIST</acronym> time.
<function>getservbyname</function>
Sometimes you may not be sure what port a certain service uses. The <citerefentry><refentrytitle>getservbyname</refentrytitle><manvolnum>3</manvolnum></citerefentry> function, also declared in <filename>netdb.h</filename> comes in very handy in those cases:
struct servent * getservbyname(const char *name, const char *proto);
The <varname>servent</varname> structure contains the <varname>s_port</varname>, which contains the proper port, already in <emphasis>network byte order</emphasis>.
Had we not known the correct port for the <emphasis>daytime</emphasis> service, we could have found it this way:
struct servent *se;
...
if ((se = getservbyname("daytime", "tcp")) == NULL {
fprintf(stderr, "Cannot determine which port to use.\n");
return 7;
}
sa.sin_port = se-&gt;s_port;
You usually do know the port. But if you are developing a new protocol, you may be testing it on an unofficial port. Some day, you will register the protocol and its port (if nowhere else, at least in your <filename>/etc/services</filename>, which is where <function>getservbyname</function> looks). Instead of returning an error in the above code, you just use the temporary port number. Once you have listed the protocol in <filename>/etc/services</filename>, your software will find its port without you having to rewrite the code.
Concurrent Servers
Unlike a sequential server, a <emphasis>concurrent server</emphasis> has to be able to serve more than one client at a time. For example, a <emphasis>chat server</emphasis> may be serving a specific client for hours—it cannot wait till it stops serving a client before it serves the next one.
This requires a significant change in our flowchart:
_ external ref='sockets/serv2' md5='__failed__'
+-----------------+
| Create Socket |
+-----------------+
|
+-----------------+
| Bind Port | Daemon Process
+-----------------+
| +--------+
+-------------+--&gt;| Init |
| | +--------+
+-----------------+ | |
| Exit | | +--------+
+-----------------+ | | Listen |
| +--------+
| |
| +--------+
| | Accept |
| +--------+
| | +------------------+
| +------&gt;| Close Top Socket |
| | +------------------+
| +--------+ |
| | Close | +------------------+
| +--------+ | Serve |
| | +------------------+
|&lt;--------+ |
+------------------+
| Close Acc Socket |
+--------+ +------------------+
| Signal | |
+--------+ +------------------+
| Exit |
+------------------+
<imageobject> <imagedata fileref="sockets/serv2"/> </imageobject> <textobject> <_:literallayout-1/> </textobject> <textobject> <phrase>Concurrent Server</phrase> </textobject>
We moved the <emphasis>serve</emphasis> from the <emphasis>daemon process</emphasis> to its own <emphasis>server process</emphasis>. However, because each child process inherits all open files (and a socket is treated just like a file), the new process inherits not only the <emphasis><quote>accepted handle,</quote></emphasis> i.e., the socket returned by the <function>accept</function> call, but also the <emphasis>top socket</emphasis>, i.e., the one opened by the top process right at the beginning.
However, the <emphasis>server process</emphasis> does not need this socket and should <function>close</function> it immediately. Similarly, the <emphasis>daemon process</emphasis> no longer needs the <emphasis>accepted socket</emphasis>, and not only should, but <emphasis>must</emphasis> <function>close</function> it—otherwise, it will run out of available <emphasis>file descriptors</emphasis> sooner or later.
After the <emphasis>server process</emphasis> is done serving, it should close the <emphasis>accepted socket</emphasis>. Instead of returning to <function>accept</function>, it now exits.
Under <trademark class="registered">UNIX</trademark>, a process does not really <emphasis>exit</emphasis>. Instead, it <emphasis>returns</emphasis> to its parent. Typically, a parent process <function>wait</function>s for its child process, and obtains a return value. However, our <emphasis>daemon process</emphasis> cannot simply stop and wait. That would defeat the whole purpose of creating additional processes. But if it never does <function>wait</function>, its children will become <emphasis>zombies</emphasis>—no longer functional but still roaming around.
For that reason, the <emphasis>daemon process</emphasis> needs to set <emphasis>signal handlers</emphasis> in its <emphasis>initialize daemon</emphasis> phase. At least a <symbol>SIGCHLD</symbol> signal has to be processed, so the daemon can remove the zombie return values from the system and release the system resources they are taking up.
That is why our flowchart now contains a <emphasis>process signals</emphasis> box, which is not connected to any other box. By the way, many servers also process <symbol>SIGHUP</symbol>, and typically interpret as the signal from the superuser that they should reread their configuration files. This allows us to change settings without having to kill and restart these servers.
IPv6 Internals
IPv6/IPsec Implementation
<personname> <firstname>Yoshinobu</firstname> <surname>Inoue</surname> </personname> <contrib>Contributed by </contrib>
This section should explain IPv6 and IPsec related implementation internals. These functionalities are derived from <link xlink:href="http://www.kame.net/">KAME project</link>
IPv6
Conformance
The IPv6 related functions conforms, or tries to conform to the latest set of IPv6 specifications. For future reference we list some of the relevant documents below (<emphasis>NOTE</emphasis>: this is not a complete list - this is too hard to maintain...).

Loading…

No matching activity found.

Browse all component changes

Things to check

Multiple failing checks

Following checks are failing:
Unchanged translation: Portuguese (Brazil), Persian

Reset

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