Manual Page Result
0
Command: connect | Section: 2 | Source: Digital UNIX | File: connect.2.gz
connect(2) System Calls Manual connect(2)
NAME
connect - Connects two sockets
SYNOPSIS
#include <sys/socket.h>
int connect ( int socket, const struct sockaddr *address,
size_t address_len );
[Digital] The following definition of the connect() function does not
conform to current standards and is supported only for backward compat-
ibility (see standards(5)):
int connect ( int socket, struct sockaddr *address, int
address_len );
STANDARDS
Interfaces documented on this reference page conform to industry stan-
dards as follows:
connect(): XPG4-UNIX
Refer to the standards(5) reference page for more information about in-
dustry standards and associated tags.
PARAMETERS
Specifies the unique name of the socket. Points to a sockaddr struc-
ture, the format of which is determined by the domain and by the behav-
ior requested for the socket. The sockaddr structure is an overlay for
a sockaddr_in or sockaddr_un structure, depending on which of the sup-
ported address families is active.
[Digital] If the compile-time option _SOCKADDR_LEN is defined
before the sys/socket.h header file is included, the sockaddr
structure takes 4.4BSD behavior, with a field for specifying the
length of the socket address. Otherwise, the default 4.3BSD
sockaddr structure is used, with the length of the socket ad-
dress assumed to be 14 bytes or less.
If _SOCKADDR_LEN is defined, the 4.3BSD sockaddr structure is
defined with the name osockaddr. Specifies the length of the
sockaddr structure pointed to by the address parameter.
DESCRIPTION
The connect() function requests a connection between two sockets. The
kernel sets up the communications links between the sockets; both sock-
ets must use the same address format and protocol.
The connect() function performs a different action for each of the fol-
lowing types of initiating sockets: If the initiating socket is
SOCK_DGRAM, the connect() function establishes the peer address. The
peer address identifies the socket where all datagrams are sent on sub-
sequent send() functions. It also identifies the socket from where
datagrams can be received; datagrams from other peer addresses are not
delivered.
No connections are made by thisconnect function. If the initi-
ating socket is SOCK_STREAM, then the connect() function at-
tempts to make a connection to the socket specified by the ad-
dress parameter. Each communication space interprets the ad-
dress parameter differently.
RETURN VALUES
Upon successful completion, the connect() function returns a value of 0
(zero). Otherwise, a value of -1 is returned and errno is set to indi-
cate the error.
ERRORS
If the connect() function fails, errno may be set to one of the follow-
ing values: Search permission is denied for a component of the path
prefix; or write access to the named socket is denied. The specified
address is already in use. The specified address is not available from
the local machine. The addresses in the specified address family can-
not be used with this socket. A connection request is already in
progress for the specified socket. The socket parameter is not valid.
The attempt to connect was rejected. The address parameter is not in a
readable part of the user address space. O_NONBLOCK is set for the
file descriptor for the socket and the connection cannot be immediately
established; the connection will be established asynchronously. The
connect() function was interrupted by a signal while waiting for the
connection to be established. The connection establishment may con-
tinue asynchronously. An I/O error occurred while reading from or
writing to the file system. The socket is already connected. Too many
symbolic links were encountered in translating the pathname in address.
A component of the pathname exceeded NAME_MAX characters, or an entire
pathname exceeded PATH_MAX characters. No route to the network or host
is present. A component of the pathname does not name an existing file
or the pathname is an empty string. A component of the path prefix of
the pathname in address is not a directory. The socket parameter
refers to a file, not a socket. The specified address has a different
type than the socket bound to the specified peer address. The estab-
lishment of a connection timed out before a connection was made. The
socket is marked nonblocking, so the connection cannot be immediately
completed. The application program can select the socket for writing
during the connection process.
RELATED INFORMATION
Functions: accept(2), bind(2), socket(2), getsockname(2), select(2),
send(2)
Standards: standards(5) delim off
connect(2)