📄 connect.2
字号:
.\" SCCSID: @(#)connect.2 4.1 12/9/88.TH connect 2.SH Nameconnect \- initiate a connection on a socket.SH Syntax.nf.ft B#include <sys/types.h>#include <sys/socket.h>.PP.ft Bconnect(s, name, namelen)int s;struct sockaddr *name;int namelen;.fi.SH Description.NXR "connect system call".NXA "connect system call" "shutdown system call".NXR "socket" "initiating a connection"The.PN connect call initiates a connection on a socket.The parameter.I sis a socket.If the socket is of type SOCK_DGRAM,this call permanently specifies the peer to whichdatagrams are sent.If it is of type SOCK_STREAM,this call attempts to make a connection toanother 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 nameparameter in its own way.The size of the structure .I sockaddr is.I namelen..SH Return ValuesIf the connection or binding succeeds, then 0 is returned.Otherwise, a \-1 is returned, and a more specific errorcode is stored in \fIerrno\fP..SH DiagnosticsThe call fails under the following conditions:.TP 15[EBADF]The.I sis not a valid descriptor..TP 15[ENOTSOCK]The.I sis a descriptor for a file, not a socket..TP 15[EADDRNOTAVAIL]The specified address is not available on this machine..TP 15[EAFNOSUPPORT]Addresses in the specified address family cannot be used with this socket..TP 15[EINPROGRESS]The connection is requested on a socket with FNDELAY set(using.MS fcntl 2 )..TP 15[EISCONN]The socket is already connected..TP 15[ETIMEDOUT]Connection establishment timed out without establishing a connection..TP 15[ECONNREFUSED]The attempt to connect was forcefully rejected..TP 15[ENETUNREACH]The network is not reachable from this host..TP 15[EADDRINUSE]The address is already in use..TP 15[EFAULT]The \fIname\fP parameter specifies an area outsidethe process address space..br.ne 3.TP 15[EWOULDBLOCK]The socket is nonblocking, and theconnection cannotbe completed immediately.You can select the socket for writing by using the.PN selectsystem callwhile it is connecting..PPThe following errors are specific to connecting names in theULTRIX domain:.TP 15[ENOTDIR]A component of the path prefix is not a directory..TP 15[ENAMETOOLONG]A component of a pathname exceeded 255 characters, or anentire path name exceeded 1023 characters..TP 15[ENOENT]The named socket does not exist..TP 15[EACCES]Search permission is denied for a component of the pathprefix..TP 15[ELOOP]Too many symbolic links were encountered in translatingthe pathname..SH See Alsoaccept(2), fcntl(2), getsockname(2), select(2), shutdown(2), socket(2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -