logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

connect.3p (8408B)


  1. '\" et
  2. .TH CONNECT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. connect
  12. \(em connect a socket
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/socket.h>
  17. .P
  18. int connect(int \fIsocket\fP, const struct sockaddr *\fIaddress\fP,
  19. socklen_t \fIaddress_len\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIconnect\fR()
  24. function shall attempt to make a connection on a connection-mode
  25. socket or to set or reset the peer address of a connectionless-mode
  26. socket. The function takes the following arguments:
  27. .IP "\fIsocket\fR" 12
  28. Specifies the file descriptor associated with the socket.
  29. .IP "\fIaddress\fR" 12
  30. Points to a
  31. .BR sockaddr
  32. structure containing the peer address. The length and format of the
  33. address depend on the address family of the socket.
  34. .IP "\fIaddress_len\fR" 12
  35. Specifies the length of the
  36. .BR sockaddr
  37. structure pointed to by the
  38. .IR address
  39. argument.
  40. .P
  41. If the socket has not already been bound to a local address,
  42. \fIconnect\fR()
  43. shall bind it to an address which, unless the socket's address family
  44. is AF_UNIX, is an unused local address.
  45. .P
  46. If the initiating socket is not connection-mode, then
  47. \fIconnect\fR()
  48. shall set the socket's peer address, and no connection is made. For
  49. SOCK_DGRAM sockets, the peer address identifies where all datagrams are
  50. sent on subsequent
  51. \fIsend\fR()
  52. functions, and limits the remote sender for subsequent
  53. \fIrecv\fR()
  54. functions. If the
  55. .IR sa_family
  56. member of
  57. .IR address
  58. is AF_UNSPEC, the socket's peer address shall be reset. Note that despite
  59. no connection being made, the term ``connected'' is used to describe a
  60. connectionless-mode socket for which a peer address has been set.
  61. .P
  62. If the initiating socket is connection-mode, then
  63. \fIconnect\fR()
  64. shall attempt to establish a connection to the address specified by the
  65. .IR address
  66. argument. If the connection cannot be established immediately and
  67. O_NONBLOCK is not set for the file descriptor for the socket,
  68. \fIconnect\fR()
  69. shall block for up to an unspecified timeout interval until the
  70. connection is established. If the timeout interval expires before the
  71. connection is established,
  72. \fIconnect\fR()
  73. shall fail and the connection attempt shall be aborted. If
  74. \fIconnect\fR()
  75. is interrupted by a signal that is caught while blocked waiting to
  76. establish a connection,
  77. \fIconnect\fR()
  78. shall fail and set
  79. .IR errno
  80. to
  81. .BR [EINTR] ,
  82. but the connection request shall not be aborted, and the connection
  83. shall be established asynchronously.
  84. .P
  85. If the connection cannot be established immediately and O_NONBLOCK is
  86. set for the file descriptor for the socket,
  87. \fIconnect\fR()
  88. shall fail and set
  89. .IR errno
  90. to
  91. .BR [EINPROGRESS] ,
  92. but the connection request shall not be aborted, and the connection
  93. shall be established asynchronously. Subsequent calls to
  94. \fIconnect\fR()
  95. for the same socket, before the connection is established, shall fail
  96. and set
  97. .IR errno
  98. to
  99. .BR [EALREADY] .
  100. .P
  101. When the connection has been established asynchronously,
  102. \fIpselect\fR(),
  103. \fIselect\fR(),
  104. and
  105. \fIpoll\fR()
  106. shall indicate that the file descriptor for the socket is ready for
  107. writing.
  108. .P
  109. The socket in use may require the process to have appropriate
  110. privileges to use the
  111. \fIconnect\fR()
  112. function.
  113. .SH "RETURN VALUE"
  114. Upon successful completion,
  115. \fIconnect\fR()
  116. shall return 0; otherwise, \-1 shall be returned and
  117. .IR errno
  118. set to indicate the error.
  119. .SH ERRORS
  120. The
  121. \fIconnect\fR()
  122. function shall fail if:
  123. .TP
  124. .BR EADDRNOTAVAIL
  125. .br
  126. The specified address is not available from the local machine.
  127. .TP
  128. .BR EAFNOSUPPORT
  129. .br
  130. The specified address is not a valid address for the address family of
  131. the specified socket.
  132. .TP
  133. .BR EALREADY
  134. A connection request is already in progress for the specified socket.
  135. .TP
  136. .BR EBADF
  137. The
  138. .IR socket
  139. argument is not a valid file descriptor.
  140. .TP
  141. .BR ECONNREFUSED
  142. .br
  143. The target address was not listening for connections or refused the
  144. connection request.
  145. .TP
  146. .BR EINPROGRESS
  147. O_NONBLOCK is set for the file descriptor for the socket and the
  148. connection cannot be immediately established; the connection shall be
  149. established asynchronously.
  150. .TP
  151. .BR EINTR
  152. The attempt to establish a connection was interrupted by delivery of a
  153. signal that was caught; the connection shall be established
  154. asynchronously.
  155. .TP
  156. .BR EISCONN
  157. The specified socket is connection-mode and is already connected.
  158. .TP
  159. .BR ENETUNREACH
  160. .br
  161. No route to the network is present.
  162. .TP
  163. .BR ENOTSOCK
  164. The
  165. .IR socket
  166. argument does not refer to a socket.
  167. .TP
  168. .BR EPROTOTYPE
  169. The specified address has a different type than the socket bound to the
  170. specified peer address.
  171. .TP
  172. .BR ETIMEDOUT
  173. The attempt to connect timed out before a connection was made.
  174. .P
  175. If the address family of the socket is AF_UNIX, then
  176. \fIconnect\fR()
  177. shall fail if:
  178. .TP
  179. .BR EIO
  180. An I/O error occurred while reading from or writing to the file system.
  181. .TP
  182. .BR ELOOP
  183. A loop exists in symbolic links encountered during resolution of the
  184. pathname in
  185. .IR address .
  186. .TP
  187. .BR ENAMETOOLONG
  188. .br
  189. The length of a component of a pathname is longer than
  190. {NAME_MAX}.
  191. .TP
  192. .BR ENOENT
  193. A component of the pathname does not name an existing file or the
  194. pathname is an empty string.
  195. .TP
  196. .BR ENOTDIR
  197. A component of the path prefix of the pathname in
  198. .IR address
  199. names an existing file that is neither a directory nor a symbolic link
  200. to a directory, or the pathname in
  201. .IR address
  202. contains at least one non-\c
  203. <slash>
  204. character and ends with one or more trailing
  205. <slash>
  206. characters and the last pathname component names an existing file that
  207. is neither a directory nor a symbolic link to a directory.
  208. .P
  209. The
  210. \fIconnect\fR()
  211. function may fail if:
  212. .TP
  213. .BR EACCES
  214. Search permission is denied for a component of the path prefix; or
  215. write access to the named socket is denied.
  216. .TP
  217. .BR EADDRINUSE
  218. Attempt to establish a connection that uses addresses that are already
  219. in use.
  220. .TP
  221. .BR ECONNRESET
  222. Remote host reset the connection request.
  223. .TP
  224. .BR EHOSTUNREACH
  225. .br
  226. The destination host cannot be reached (probably because the host is
  227. down or a remote router cannot reach it).
  228. .TP
  229. .BR EINVAL
  230. The
  231. .IR address_len
  232. argument is not a valid length for the address family; or invalid
  233. address family in the
  234. .BR sockaddr
  235. structure.
  236. .TP
  237. .BR ELOOP
  238. More than
  239. {SYMLOOP_MAX}
  240. symbolic links were encountered during resolution of the pathname in
  241. .IR address .
  242. .TP
  243. .BR ENAMETOOLONG
  244. .br
  245. The length of a pathname exceeds
  246. {PATH_MAX},
  247. or pathname resolution of a symbolic link produced an intermediate
  248. result with a length that exceeds
  249. {PATH_MAX}.
  250. .TP
  251. .BR ENETDOWN
  252. The local network interface used to reach the destination is down.
  253. .TP
  254. .BR ENOBUFS
  255. No buffer space is available.
  256. .TP
  257. .BR EOPNOTSUPP
  258. The socket is listening and cannot be connected.
  259. .LP
  260. .IR "The following sections are informative."
  261. .SH EXAMPLES
  262. None.
  263. .SH "APPLICATION USAGE"
  264. If
  265. \fIconnect\fR()
  266. fails, the state of the socket is unspecified. Conforming applications
  267. should close the file descriptor and create a new socket before
  268. attempting to reconnect.
  269. .SH "RATIONALE"
  270. None.
  271. .SH "FUTURE DIRECTIONS"
  272. None.
  273. .SH "SEE ALSO"
  274. .IR "\fIaccept\fR\^(\|)",
  275. .IR "\fIbind\fR\^(\|)",
  276. .IR "\fIclose\fR\^(\|)",
  277. .IR "\fIgetsockname\fR\^(\|)",
  278. .IR "\fIpoll\fR\^(\|)",
  279. .IR "\fIpselect\fR\^(\|)",
  280. .IR "\fIsend\fR\^(\|)",
  281. .IR "\fIshutdown\fR\^(\|)",
  282. .IR "\fIsocket\fR\^(\|)"
  283. .P
  284. The Base Definitions volume of POSIX.1\(hy2017,
  285. .IR "\fB<sys_socket.h>\fP"
  286. .\"
  287. .SH COPYRIGHT
  288. Portions of this text are reprinted and reproduced in electronic form
  289. from IEEE Std 1003.1-2017, Standard for Information Technology
  290. -- Portable Operating System Interface (POSIX), The Open Group Base
  291. Specifications Issue 7, 2018 Edition,
  292. Copyright (C) 2018 by the Institute of
  293. Electrical and Electronics Engineers, Inc and The Open Group.
  294. In the event of any discrepancy between this version and the original IEEE and
  295. The Open Group Standard, the original IEEE and The Open Group Standard
  296. is the referee document. The original Standard can be obtained online at
  297. http://www.opengroup.org/unix/online.html .
  298. .PP
  299. Any typographical or formatting errors that appear
  300. in this page are most likely
  301. to have been introduced during the conversion of the source files to
  302. man page format. To report such errors, see
  303. https://www.kernel.org/doc/man-pages/reporting_bugs.html .