Sockets Programming Interfaces
3-16
EADDRINUSE
The specified address is already in use.
EISCONN
The socket is already connected.
ETIMEDOUT
Connection establishment timed out without es-
tablishing a connection.
ECONNREFUSED
The attempt to connect was forcefully rejected.
ENETUNREACH
The network isn’t reachable from this host
Description
The connect() function establishes a logical (and potentially physical) connec-
tion from the socket specified by s to the foreign name (address) specified by
pName.
If sock is of type SOCK_DGRAM, this call specifies the peer address with
which the socket is to be associated; this address is that to which datagrams
are to be sent, and the only address from which datagrams are to be received.
If the socket is of type SOCK_STREAM, the function attempts to make a con-
nection to another socket.
The argument s is a socket that has been created with the socket() function.
The argument pName is a structure of type sockaddr that contains the desired
foreign address. The len parameter contains the size of pName which is si-
zeof( struct sockaddr ).
Stream sockets may connect only once; while datagram sockets may re-con-
nect multiple times to change their association. The connection may be dis-
solved by attempting to connect to an illegal address (say NULL IP and Port).
Datagram sockets that require multiple connections may consider using the
recvfrom() and sendto() functions instead of connect().
It is possible to select (fdSelect()) a socket for the purposes of doing a connect
by selecting it for writing.
Get Name (address) of Connected Peer
getpeername
Syntax
int getpeername( int s, PSA pName, int *plen );
Parameter(s)
s
Socket
pName
Name (address) of connected peer
plen
Pointer to size of pName
Return Value
If it succeeds, the function returns 0. Otherwise, a value of –1 is returned and
the function fdError() can be called to determine the error:
EBADF
The file descriptor (socket) is invalid.
ENOTSOCK
The file descriptor does not reference a socket.