Initiates a connection on a socket.
Format
#include <socket.h>
int connect (int s, struct sockaddr *name, int
namelen);
Routine Variants
This socket routine has a variant named __bsd44_connect. Enabled by
defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible
semantics. See Section A.7 for
more information.
Arguments
- s
- A socket descriptor that has been created with socket.
- name
- The address of a structure that specifies the name of the
remote socket in the format specific to the address family (AF_
INET).
- namelen
- The size, in bytes, of the structure pointed to by
name.
Description
If s is a socket descriptor of type SOCK_DGRAM, then
this call permanently specifies the peer to which data is to be
sent. If it is of type SOCK_STREAM, then this call attempts to make
a connection to another socket.
Each communications space interprets the name parameter in
its own way. This argument specifies the socket to which the socket
specified in s is to be connected.
See also accept, select, socket, getsockname, and shutdown in this
appendix.
Return Values
0 | Indicates success. |
-1 | Indicates an error; errno is set to one
of the following:
- EBADF - The socket descriptor is invalid.
- ENOTSOCK - The socket descriptor references a file, not a
socket.
- EADDRNOTAVAIL - specified address is not available from
the local machine.
- EAFNOSUPPORT - Address in the specified address family
cannot be used with this socket.
- EISCONN - The socket is already connected.
- ETIMEOUT - 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.
- EADDRINUSE - The specified Internet address and ports are
already in use.
- EFAULT - The name parameter is not a valid part
of the user address space.
- EWOULDBLOCK - The socket is nonblocking and the connection
cannot be completed immediately. It is possible to select the
socket while it is connecting by selecting it for writing.
|
Previous Page | Next Page | Table of Contents | Index