Scroll to navigation

connect(2) System Calls Manual connect(2)

JMÉNO

connect - inicializuj spojení soketu

KNIHOVNA

Standardní knihovna C (libc, -lc)

POUŽITÍ

#include <sys/socket.h>
int connect(int sockfd, const struct sockaddr *addr,
            socklen_t addrlen);

POPIS

Systémové volání connect() připojí soket specifikovaný v sockfd k adrese specifikované v addr. Parametr addrlen udává velikost addr. Formát adresy v addr je dán adresovým prostorem deskriptoru v sockfd. Viz socket(2) pro více detailů.

Parametr sockfd je soket. Je-li jeho typ SOCK_DGRAM, pak je addr jediným místem, odkud a kam budou přijímány, resp. posílány datagramy. Je-li typ soketu SOCK_STREAM, nebo SOCK_SEQPACKET potom se toto volání pokusí navázat spojení se soketem, který je specifikován v addr, což je adresa v jmenném prostoru soketu. Každý jmenný prostor interpretuje adresu v addr.

Some protocol sockets (e.g., UNIX domain stream sockets) may successfully connect() only once.

Some protocol sockets (e.g., datagram sockets in the UNIX and Internet domains) may use connect() multiple times to change their association.

Some protocol sockets (e.g., TCP sockets as well as datagram sockets in the UNIX and Internet domains) may dissolve the association by connecting to an address with the sa_family member of sockaddr set to AF_UNSPEC; thereafter, the socket can be connected to another address. (AF_UNSPEC is supported since Linux 2.2.)

NÁVRATOVÉ HODNOTY

If the connection or binding succeeds, zero is returned. On error, -1 is returned, and errno is set to indicate the error.

CHYBOVÉ STAVY

Tento seznam je pouze všeobecný. Mohou existovat další specifické chyby pro použitý jmenný prostor.

Pro sokety UNIXové domény, které jsou identifikovány jménem: je odmítnuto zapisování do souboru specifikovaného soketem, nebo je odmítnuto právo vyhledávat v adresářích specifikovaných cestou. (Viz path_resolution(7).)
Uživatel se pokusil připojit k broadcastové adrese, aniž by měl povolen broadcastový příznak na soketu, nebo požadavek na spojení byl odmítnut kvůli lokálnímu pravidlu firewallu.
It can also be returned if an SELinux policy denied a connection (for example, if there is a policy saying that an HTTP proxy can only connect to ports associated with HTTP servers, and the proxy tries to connect to a different port).
Adresa je již používána.
(Internet domain sockets) The socket referred to by sockfd had not previously been bound to an address and, upon attempting to bind it to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. See the discussion of /proc/sys/net/ipv4/ip_local_port_range in ip(7).
Poskytnutá adresa nemá správně specifikovanou rodinu adres v poli sa_family.
For nonblocking UNIX domain sockets, the socket is nonblocking, and the connection cannot be completed immediately. For other socket families, there are insufficient entries in the routing cache.
Soket je neblokující a předchozí pokus o spojení ještě nebyl dokončen.
sockfd is not a valid open file descriptor.
A connect() on a stream socket found no one listening on the remote address.
Adresa soketu je mimo adresový prostor procesu.
The socket is nonblocking and the connection cannot be completed immediately. (UNIX domain sockets failed with EAGAIN instead.) It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure).
Systémové volání bylo přerušeno doručením signálu. Viz signal(7).
Soket je již spojen.
Síť není dosažitelná.
The file descriptor sockfd does not refer to a socket.
The socket type does not support the requested communications protocol. This error can occur, for example, on an attempt to connect a UNIX domain datagram socket to a stream socket.
Timeout při pokusu o navázání spojení. Server může být příliš zaneprázdněn a není schopen přijmou další spojení. Vězte, že pro IP sokety může být timeout velmi dlouhý, pokud jsou syncookies povoleny na straně serveru.

STANDARDY

POSIX.1-2008.

HISTORIE

POSIX.1-2001, SVr4, 4.4BSD, (connect() se poprvé objevila ve 4.2BSD).

POZNÁMKY

If connect() fails, consider the state of the socket as unspecified. Portable applications should close the socket and create a new one for reconnecting.

PŘÍKLADY

Příklad použití connect() je v getaddrinfo(3).

DALŠÍ INFORMACE

accept(2), bind(2), getsockname(2), listen(2), socket(2), path_resolution(7), selinux(8)

PŘEKLAD

Překlad této příručky do španělštiny vytvořili Pavel Heimlich <tropikhajma@gmail.com>

Tento překlad je bezplatná dokumentace; Přečtěte si GNU General Public License Version 3 nebo novější ohledně podmínek autorských práv. Neexistuje ŽÁDNÁ ODPOVĚDNOST.

Pokud narazíte na nějaké chyby v překladu této příručky, pošlete e-mail na adresu translation-team-cs@lists.sourceforge.net.

30. března 2023 Linux man-pages 6.05.01