Translation

(itstool) path: sect4/programlisting
/*
* 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 */
292/2900
Context English Portuguese (Brazil) State
<function>socket</function> <function> soquete </function>
The one function used by both, clients and servers, is <citerefentry><refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum></citerefentry>. It is declared this way: A única função usada por ambos, clientes e servidores, é <citerefentry><refentrytitle> soquete </refentrytitle><manvolnum> 2 </manvolnum></citerefentry> . É declarado desta maneira:
int socket(int domain, int type, int protocol);
int socket(int domain, int type, int protocol);
The return value is of the same type as that of <function>open</function>, an integer. FreeBSD allocates its value from the same pool as that of file handles. That is what allows sockets to be treated the same way as files. O valor de retorno é do mesmo tipo que o de <function> aberto </function> , um inteiro. O FreeBSD aloca seu valor do mesmo conjunto de identificadores de arquivos. Isso é o que permite que os sockets sejam tratados da mesma maneira que os arquivos.
The <varname>domain</varname> argument tells the system what <emphasis>protocol family</emphasis> you want it to use. Many of them exist, some are vendor specific, others are very common. They are declared in <filename>sys/socket.h</filename>. O <varname> domínio </varname> argumento diz ao sistema que <emphasis> família de protocolo </emphasis> você quer que ele use. Muitos deles existem, alguns são específicos do fornecedor, outros são muito comuns. Eles são declarados em <filename> sys / socket.h </filename>
Use <constant>PF_INET</constant> for <acronym>UDP</acronym>, <acronym>TCP</acronym> and other Internet protocols (<acronym>IP</acronym>v4). Usar <constant> PF_INET </constant> para <acronym>UDP</acronym> , <acronym>TCP</acronym> e outros protocolos da Internet ( <acronym>IP</acronym> v4).
Five values are defined for the <varname>type</varname> argument, again, in <filename>sys/socket.h</filename>. All of them start with <quote><constant>SOCK_</constant></quote>. The most common one is <constant>SOCK_STREAM</constant>, which tells the system you are asking for a <emphasis>reliable stream delivery service</emphasis> (which is <acronym>TCP</acronym> when used with <constant>PF_INET</constant>). Cinco valores são definidos para o <varname> tipo </varname> argumento, novamente, em <filename> sys / socket.h </filename> . Todos eles começam com <quote><constant> MEIA_ </constant></quote> . O mais comum é <constant> SOCK_STREAM </constant> , que informa ao sistema que você está pedindo uma <emphasis> serviço de entrega de fluxo confiável </emphasis> (que é <acronym>TCP</acronym> quando usado com <constant> PF_INET </constant> )
If you asked for <constant>SOCK_DGRAM</constant>, you would be requesting a <emphasis>connectionless datagram delivery service</emphasis> (in our case, <acronym>UDP</acronym>). Se você pediu <constant> SOCK_DGRAM </constant> , você estaria solicitando um <emphasis> serviço de entrega de datagramas sem conexão </emphasis> (no nosso caso, <acronym>UDP</acronym> ).
If you wanted to be in charge of the low-level protocols (such as <acronym>IP</acronym>), or even network interfaces (e.g., the Ethernet), you would need to specify <constant>SOCK_RAW</constant>. Se você quisesse estar no comando dos protocolos de baixo nível (como <acronym>IP</acronym> ), ou mesmo das interfaces de rede (por exemplo, a Ethernet), você precisaria especificar <constant> SOCK_RAW </constant>
Finally, the <varname>protocol</varname> argument depends on the previous two arguments, and is not always meaningful. In that case, use <constant>0</constant> for its value. Finalmente, o <varname> protocolo </varname> argumento depende dos dois argumentos anteriores e nem sempre é significativo. Nesse caso, use <constant> 0 </constant> por seu valor
The Unconnected Socket O Soquete Desconectado
Nowhere, in the <function>socket</function> function have we specified to what other system we should be connected. Our newly created socket remains <emphasis>unconnected</emphasis>. Em nenhum lugar, no <function> soquete </function> função especificamos para qual outro sistema devemos estar conectados. Nossa soquete recém-criada permanece <emphasis> desconectado </emphasis>
This is on purpose: To use a telephone analogy, we have just attached a modem to the phone line. We have neither told the modem to make a call, nor to answer if the phone rings. Isso é feito de propósito: para usar uma analogia de telefone, acabamos de conectar um modem à linha telefônica. Não dissemos ao modem para fazer uma ligação nem para responder se o telefone tocar.
<varname>sockaddr</varname> <varname> sockaddr </varname>
Various functions of the sockets family expect the address of (or pointer to, to use C terminology) a small area of the memory. The various C declarations in the <filename>sys/socket.h</filename> refer to it as <varname>struct sockaddr</varname>. This structure is declared in the same file: Várias funções da família de soquetes esperam o endereço de (ou ponteiro para, usar a terminologia C) uma pequena área da memória. As várias declarações C no <filename> sys / socket.h </filename> referir-se a ele como <varname> struct sockaddr </varname> . Esta estrutura é declarada no mesmo arquivo:
/*
* 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 */

/*
* 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. Por favor, note o <emphasis> imprecisão </emphasis> com o qual o <varname> sa_data </varname> campo é declarado, assim como uma matriz de <constant> 14 </constant> bytes, com o comentário sugerindo que pode haver mais de <constant> 14 </constant> deles.
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. Essa imprecisão é bastante deliberada. Sockets é uma interface muito poderosa. Embora a maioria das pessoas pense nisso como nada mais do que a interface da Internet - e a maioria dos aplicativos provavelmente a usa para isso hoje em dia - os soquetes podem ser usados ​​para praticamente <emphasis> qualquer </emphasis> tipo de comunicação entre processos, da qual a Internet (ou, mais precisamente, <acronym>IP</acronym> ) é apenas uma.
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>: O <filename> sys / socket.h </filename> refere-se aos vários tipos de protocolos que os sockets tratarão como <emphasis> endereço famílias </emphasis> e os relaciona logo antes da definição de <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

/*
* 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>. O usado para <acronym>IP</acronym> é <symbol> AF_INET </symbol> . É um símbolo para a constante <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. É o <emphasis> família de endereço </emphasis> listado no <varname> sa_family </varname> Campo de <varname> sockaddr </varname> que decide exatamente como os bytes vagamente nomeados <varname> sa_data </varname> será usado.
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: Especificamente, sempre que o <emphasis> família de endereço </emphasis> é <symbol> AF_INET </symbol> , podemos usar <varname> struct sockaddr_in </varname> encontrado em <filename> netinet / in.h </filename> onde quer que <varname> sockaddr </varname> é esperado:
/*
* 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];
};

/*
* 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: Podemos visualizar sua organização desta maneira:
_ external ref='sockets/sain' md5='__failed__' external ref='sockets/sain' md5='__failed__'
0 1 2 3
+--------+--------+-----------------+
0 | 0 | Family | Port |
+--------+--------+-----------------+
4 | IP Address |
+-----------------------------------+
8 | 0 |
+-----------------------------------+
12 | 0 |
+-----------------------------------+
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> <imageobject><imagedata fileref="sockets/sain"/></imageobject><textobject> &lt;_: literallayout-1 /&gt; </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. Os três campos importantes são <varname> sin_family </varname> , que é o byte 1 da estrutura, <varname> sin_port </varname> , um valor de 16 bits encontrado nos bytes 2 e 3 e <varname> sin_addr </varname> , uma representação inteira de 32 bits do endereço <acronym>IP</acronym> , armazenada nos 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>). Agora, vamos tentar preenchê-lo. Vamos supor que estamos tentando escrever um cliente para o <emphasis> dia </emphasis> protocolo, que simplesmente afirma que seu servidor irá escrever uma seqüência de texto que representa a data e hora atuais para a porta 13. Queremos usar <acronym>TCP / IP</acronym> , por isso precisamos especificar <constant> AF_INET </constant> no campo da família de endereços. <constant> AF_INET </constant> é definido como <constant> 2 </constant> . Vamos usar o endereço <acronym>IP</acronym> de <systemitem class="ipaddress"> 192.43.244.18 </systemitem> , que é o servidor de horário do governo federal dos EUA ( <systemitem class="fqdomainname"> time.nist.gov </systemitem> )
_ external ref='sockets/sainfill' md5='__failed__' external ref='sockets/sainfill' md5='__failed__'

Loading…

New source string a year ago
Browse all component changes

Things to check

Mismatching line breaks

Number of new lines in translation does not match source

Reset

Trailing newline

Source and translation do not both end with a newline

Reset

Starting newline

Source and translation do not both start with a newline

Reset

Glossary

English Portuguese (Brazil)
No related strings found in the glossary.

Source information

Source string comment
(itstool) path: sect4/programlisting
Flags
no-wrap
Source string location
book.translate.xml:5307
String age
a year ago
Source string age
a year ago
Translation file
books/pt_BR/developers-handbook.po, string 887