DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

connect(SSC)


connect -- initiate a connection on a socket

Syntax

cc ... -lsocket

#include <sys/types.h>
#include <sys/socket.h>

int connect (s, name, namelen) int s; const struct sockaddr *name; int namelen;

Description

connect( ) initiates a connection on a socket. The s parameter is a socket. If it is of type SOCK_DGRAM, then this call permanently specifies the peer to which datagrams are to be sent; if it is of type SOCK_STREAM, then this call attempts to make a connection to another socket. The other socket is specified by name; namelen is the length of name, which is an address in the address family of the socket. Each address family interprets the name parameter in its own way.

Return values

A return value of zero indicates that the call succeeded. A return value of -1 indicates that an error occurred, and in this case an error code is stored in the global variable errno.

Diagnostics

The call fails if:

[EBADF]
The s argument is not a valid descriptor.

[ENOTSOCK]
The s argument is a descriptor for a file, not a socket.

[EADDRNOTAVAIL]
The specified address is not available on this machine.

[EAFNOSUPPORT]
Addresses in the specified address family cannot be used with this socket.

[EISCONN]
The socket is already connected.

[ETIMEDOUT]
Connection establishment timed out without establishing a connection.

[ECONNREFUSED]
The attempt to connect was forcefully rejected.

[ENETUNREACH]
The network is not reachable from this host.

[EHOSTUNREACH]
The destination host is not reachable from this host.

[EADDRINUSE]
The address is already in use.

[EFAULT]
The name parameter specifies an area outside the process address space.

See also

Intro(ADMP), Intro(SSC), accept(SSC), getsockname(SSC), socket(SSC)
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003