HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
c
connect(2) connect(2)
NAME
connect - initiate a connection on a socket
SYNOPSIS
#include <sys/socket.h>
AF_CCITT only
#include <x25/x25addrstr.h>
AF_INET and AF_VME_LINK only
#include <netinet/in.h>
AF_UNIX only
#include <sys/un.h>
int connect(int s, const void *addr, int addrlen);
_XOPEN_SOURCE_EXTENDED only (UNIX 98)
int connect(int s, const struct sockaddr *addr, socklen_t addrlen);
Obsolescent _XOPEN_SOURCE_EXTENDED only (UNIX 95)
int connect(int s, const struct sockaddr *addr, size_t addrlen);
DESCRIPTION
The connect() function initiates a connection on a socket.
s is a socket descriptor.
addr is a pointer to a socket address structure containing the address of a remote socket to which a connec-
tion is to be established.
addrlen is the size of this address structure. Since the size of the socket address structure varies among
socket address families, the correct socket address structure should be used with each address family (for
example, struct sockaddr_in
for AF_INET and AF_VME_LINK and struct sockaddr_un for
AF_UNIX). Typically, the
sizeof() function is used to pass this value (for example,
sizeof(struct sockaddr_in)
).
If the socket is of type
SOCK_DGRAM, connect() specifies the peer address to which messages are to be
sent, and the call returns immediately. Furthermore, this socket can only receive messages sent from this
address.
If the socket is of type SOCK_STREAM , connect() attempts to contact the remote host to make a con-
nection between the remote socket (peer) and the local socket specified by s. The call normally blocks until
the connection completes. If nonblocking mode has been enabled with the
O_NONBLOCK or O_NDELAY
fcntl()
flags or the FIOSNBIO ioctl() request and the connection cannot be completed immedi-
ately, connect() returns an error as described below. In these cases, select() can be used on this
socket to determine when the connection has completed by selecting it for writing.
The connect() system call may complete if remote program has a pending listen() even though
remote program had not yet issued an accept() system call.
O_NONBLOCK and O_NDELAY are defined in <sys/fcntl.h>
and explained in fcntl(2), fcntl(5), and
socket(7).
FIOSNBIO is defined in <sys/ioctl.h>
and explained in ioctl(2), ioctl(5), and socket(7).
If s is a
SOCK_STREAM socket that is bound to the same local address as another SOCK_STREAM
socket,
connect() returns [EADDRINUSE] if addr is the same as the peer address of that other socket. This
situation can only happen if the SO_REUSEADDR option has been set on s, which is an AF_INET socket
(see getsockopt(2)).
If the AF_INET socket does not already have a local address bound to it (see bind(2)), connect() also
binds the socket to a local address chosen by the system.
An AF_VME_LINK socket always binds the socket to a local address chosen by the system.
Generally, stream sockets may successfully connect only once; datagram sockets may use connect()
multiple times to change the peer address. For datagram sockets, a side effect of attempting to connect to
some invalid address (see ERRORS below) is that the peer address is no longer maintained by the system.
An example of an invalidaddress for a datagram socket is addrlen set to 0 and addr set to any value.
Section 2−−38 − 1 − HP-UX Release 11i: December 2000
___
___