Files
seta75D ff309bfe1c Init
2021-10-11 18:37:13 -03:00

207 lines
4.3 KiB
Groff

.\" @(#)connect.2 1.1 94/10/31 SMI; from UCB 4.3
.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.TH CONNECT 2 "21 January 1990"
.SH NAME
connect \- initiate a connection on a socket
.SH SYNOPSIS
.nf
.ft B
#include <sys/types.h>
#include <sys/socket.h>
.ft
.if
.LP
.nf
.ft B
int connect(s, name, namelen)
int s;
struct sockaddr *name;
int namelen;
.ft
.fi
.IX connect() "" \fLconnect()\fP
.IX "socket operations" connect() "" \fLconnect()\fP
.IX "interprocess communication" connect() "" \fLconnect()\fP
.IX initiate "connection on socket \(em \fLconnect()\fR"
.SH DESCRIPTION
.LP
The parameter
.I s
is a socket.
If it is of type
.SM
.BR SOCK_DGRAM \*S,
then this call specifies the peer 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 it is of type
.SM
.BR SOCK_STREAM \*S,
then this call attempts to make a connection to
another socket.
The other socket is specified by
.I name
which is an address in the communications space of the socket.
Each communications space interprets the
.I name
parameter in its own way.
Generally, stream sockets may successfully
.B connect(\|)
only once; datagram sockets may use
.B connect(\|)
multiple times to change their association.
Datagram sockets may dissolve the association
by connecting to an invalid address, such as a null address.
.SH RETURN VALUES
.LP
.B connect(\|)
returns:
.TP
0
on success.
.TP
\-1
on failure and sets
.B errno
to indicate the error.
.SH ERRORS
.LP
The call fails if:
.TP 20
.SM EADDRINUSE
The address is already in use.
.TP
.SM EADDRNOTAVAIL
The specified address is not available on the remote machine.
.TP
.SM EAFNOSUPPORT
Addresses in the specified address family cannot be used with this socket.
.TP
.SM EALREADY
The socket is non-blocking
and a previous connection attempt
has not yet been completed.
.TP
.SM EBADF
.I s
is not a valid descriptor.
.TP
.SM ECONNREFUSED
The attempt to connect was forcefully rejected.
The calling program should
.BR close (2V)
the socket descriptor, and issue another
.BR socket (2)
call to obtain a new descriptor before attempting another
.BR connect (2)
call.
.TP
.SM EFAULT
The
.I name
parameter specifies an area outside
the process address space.
.TP
.SM EINPROGRESS
The socket is non-blocking and the connection cannot
be completed immediately. It is possible to
.BR select (2)
for completion by selecting the socket for writing.
.TP
.SM EINTR
The connection attempt was interrupted before
any data arrived by the delivery of a signal.
.TP
.SM EINVAL
.I namelen
is not the size of a valid address for the specified address family.
.TP
.SM EISCONN
The socket is already connected.
.TP
.SM ENETUNREACH
The network is not reachable from this host.
.TP
.SM ENOTSOCK
.I s
is a descriptor for a file, not a socket.
.TP
.SM ETIMEDOUT
Connection establishment timed out without establishing a connection.
.LP
The following errors are specific to connecting names in the
.SM UNIX
domain. These errors may not apply in future versions of the
.SM UNIX IPC
domain.
.TP 20
.SM EACCES
Search permission is denied for a component of the path prefix of the
path name in
.IR name .
.TP
.SM ELOOP
Too many symbolic links were encountered in translating the path name in
.IR name .
.TP
.SM EIO
An I/O error occurred while reading from or writing to the file system.
.TP
.SM ENAMETOOLONG
The length of the path argument exceeds
.SM {PATH_MAX}\s0.
.IP
A pathname component is longer than
.SM {NAME_MAX}
(see
.BR sysconf (2V))
while
.SM {_POSIX_NO_TRUNC}
is in effect
(see
.BR pathconf (2V)).
.TP
.SM ENOENT
A component of the path prefix of the path name in
.I name
does not exist.
.IP
The socket referred to by the path name in
.I name
does not exist.
.TP
.SM ENOTDIR
A component of the path prefix of the path name in
.I name
is not a directory.
.TP
.SM ENOTSOCK
The file referred to by
.I name
is not a socket.
.TP
.SM EPROTOTYPE
The file referred to by
.I name
is a socket of a type other than the type of
.I s
(e.g.,
.I s
is a
.SB SOCK_DGRAM
socket, while
.I name
refers to a
.SB SOCK_STREAM
socket).
.SH SEE ALSO
.BR accept (2),
.BR close (2V),
.BR connect (2),
.BR getsockname (2),
.BR select (2),
.BR socket (2)