connect() system call
connect(2) connect(2)
NAME
connect - Connects two sockets
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
int connect (
int socket,
struct sockaddr *address,
int address_len );
PARAMETERS
socket
Specifies the unique name of the socket.
address
Points to a sockaddr structure, the format of which is determined by
the domain and by the behavior requested for the socket. The sockaddr
structure is an overlay for a sockaddr_in, sockaddr_un, or sockaddr_ns
structure, depending on which of the supported address families is
active. 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 address assumed to be 14 bytes or less.
If _SOCKADDR_LEN is defined, the 4.3BSD sockaddr structure is defined
with the name osockaddr.
address_len
Specifies the length of the sockaddr structure pointed to by the
address parameter.
DESCRIPTION
The connect() function requests a connection between two sockets. The ker-
nel sets up the communications links between the sockets; both sockets must
use the same address format and protocol.
The connect() function performs a different action for each of the follow-
ing types of initiating sockets:
+ If the initiating socket is SOCK_DGRAM, then the connect() function
establishes the peer address. The peer address identifies the socket
where all datagrams are sent on subsequent send() functions. No con-
nections are made by this connect function.
+ If the initiating socket is SOCK_STREAM, then the connect() function
attempts to make a connection to the socket specified by the address
parameter. Each communication space interprets the address 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 indicate
the error.
ERRORS
If the connect() function fails, errno may be set to one of the following
values:
[EBADF] The socket parameter is not valid.
[ENOTSOCK]
The socket parameter refers to a file, not a socket.
[EADDRNOTAVAIL]
The specified address is not available from the local machine.
[EAFNOSUPPORT]
The addresses in the specified address family cannot be used with
this socket.
[EISCONN] The socket is already connected.
[ETIMEDOUT]
The establishment of a connection timed out before a connection
was made.
[ECONNREFUSED]
The attempt to connect was rejected.
[ENETUNREACH]
No route to the network or host is present.
[EADDRINUSE]
The specified address is already in use.
[EFAULT] The address parameter is not in a readable part of the user
address space.
[EWOULDBLOCK]
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.
[EINTR] The connect() function was interrupted by a signal while waiting
for the connection to be established. The connection establish-
ment may continue asynchronously.
RELATED INFORMATION
Functions: accept(2), bind(2), socket(2), getsockname(2), select(2),
send(2) delim off