Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../usr/man/man3c/./connect.3c
Real path: /usr/share/man/man3c/connect.3c
Zurück
'\" te .\" Copyright (c) 1994, 2013, The X/Open Company Ltd. All rights reserved. .\" Portions Copyright (c) 1989, AT&T. All rights reserved. .\" Portions Copyright (c) 1998, 2021, Oracle and/or its affiliates. .\" Oracle gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH connect 3C "2 Feb 2021" "Oracle Solaris 11.4" "Standard C Library Functions" .SH NAME connect \- connect a socket .SH SYNOPSIS .LP .nf #include <sys/socket.h> \fBint\fR \fBconnect\fR(\fBint\fR \fIsocket\fR, \fBconst struct sockaddr *\fR\fIaddress\fR, \fBsocklen_t\fR \fIaddress_len\fR); .fi .SH DESCRIPTION .sp .LP The \fBconnect()\fR function requests a connection to be made on a socket. The function takes the following arguments: .sp .ne 2 .mk .na \fB\fIsocket\fR\fR .ad .RS 15n .rt Specifies the file descriptor associated with the socket. .RE .sp .ne 2 .mk .na \fB\fIaddress\fR\fR .ad .RS 15n .rt Points to a \fBsockaddr\fR structure containing the peer address. The length and format of the address depend on the address family of the socket. .RE .sp .ne 2 .mk .na \fB\fIaddress_len\fR\fR .ad .RS 15n .rt Specifies the length of the \fBsockaddr\fR structure pointed to by the \fIaddress\fR argument. .RE .sp .LP The \fBconnect()\fR call will bind the socket to a local unused address if it is not already bound and if the socket type is not \fBAF_UNIX\fR. .sp .LP If the initiating socket is not connection-mode, then \fBconnect()\fR sets the socket's peer address, but no connection is made. For \fBSOCK_DGRAM\fR sockets, the peer address identifies where all datagrams are sent on subsequent \fBsend\fR(3C) calls, and limits the remote sender for subsequent \fBrecv\fR(3C) calls. If \fIaddress\fR is a null address for the protocol, the socket's peer address will be reset. .sp .LP If the initiating socket is connection-mode, then \fBconnect()\fR attempts to establish a connection to the address specified by the \fIaddress\fR argument. .sp .LP If the connection cannot be established immediately and \fBO_NONBLOCK\fR is not set for the file descriptor for the socket, \fBconnect()\fR will block for up to an unspecified timeout interval until the connection is established. If the timeout interval expires before the connection is established, \fBconnect()\fR will fail and the connection attempt will be aborted. If \fBconnect()\fR is interrupted by a signal that is caught while blocked waiting to establish a connection, \fBconnect()\fR will fail and set \fBerrno\fR to \fBEINTR\fR, but the connection request will not be aborted, and the connection will be established asynchronously. .sp .LP If the connection cannot be established immediately and \fBO_NONBLOCK\fR is set for the file descriptor for the socket, \fBconnect()\fR will fail and set \fBerrno\fR to \fBEINPROGRESS\fR, but the connection request will not be aborted, and the connection will be established asynchronously. Subsequent calls to \fBconnect()\fR for the same socket, before the connection is established, will fail and set \fBerrno\fR to \fBEALREADY\fR. .sp .LP When the connection has been established asynchronously, \fBselect\fR(3C) and \fBpoll\fR(2) will indicate that the file descriptor for the socket is ready for writing. .sp .LP The socket in use may require the process to have appropriate privileges to use the \fBconnect()\fR function. .SH USAGE .sp .LP If \fBconnect()\fR fails, the state of the socket is unspecified. Applications should close the file descriptor and create a new socket before attempting to reconnect. .SH RETURN VALUES .sp .LP Upon successful completion, \fBconnect()\fR returns 0. Otherwise, \(mi1 is returned and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBconnect()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEADDRNOTAVAIL\fR\fR .ad .RS 17n .rt The specified address is not available from the local machine. .RE .sp .ne 2 .mk .na \fB\fBEAFNOSUPPORT\fR\fR .ad .RS 17n .rt The specified address is not a valid address for the address family of the specified socket. .RE .sp .ne 2 .mk .na \fB\fBEALREADY\fR\fR .ad .RS 17n .rt A connection request is already in progress for the specified socket. .RE .sp .ne 2 .mk .na \fB\fBEBADF\fR\fR .ad .RS 17n .rt The \fIsocket\fR argument is not a valid file descriptor. .RE .sp .ne 2 .mk .na \fB\fBECONNREFUSED\fR\fR .ad .RS 17n .rt The target address was not listening for connections or refused the connection request. .RE .sp .ne 2 .mk .na \fB\fBEFAULT\fR\fR .ad .RS 17n .rt The address parameter can not be accessed. .RE .sp .ne 2 .mk .na \fB\fBEINPROGRESS\fR\fR .ad .RS 17n .rt \fBO_NONBLOCK\fR is set for the file descriptor for the socket and the connection cannot be immediately established; the connection will be established asynchronously. .RE .sp .ne 2 .mk .na \fB\fBEINTR\fR\fR .ad .RS 17n .rt The attempt to establish a connection was interrupted by delivery of a signal that was caught; the connection will be established asynchronously. .RE .sp .ne 2 .mk .na \fB\fBEISCONN\fR\fR .ad .RS 17n .rt The specified socket is connection-mode and is already connected. .RE .sp .ne 2 .mk .na \fB\fBENETUNREACH\fR\fR .ad .RS 17n .rt No route to the network is present. .RE .sp .ne 2 .mk .na \fB\fBENOTSOCK\fR\fR .ad .RS 17n .rt The \fIsocket\fR argument does not refer to a socket. .RE .sp .ne 2 .mk .na \fB\fBEPROTOTYPE\fR\fR .ad .RS 17n .rt The specified address has a different type than the socket bound to the specified peer address. .RE .sp .ne 2 .mk .na \fB\fBETIMEDOUT\fR\fR .ad .RS 17n .rt The attempt to connect timed out before a connection was made. .RE .sp .LP If the address family of the socket is \fBAF_UNIX\fR, then \fBconnect()\fR will fail if: .sp .ne 2 .mk .na \fB\fBEIO\fR\fR .ad .RS 16n .rt An I/O error occurred while reading from or writing to the file system. .RE .sp .ne 2 .mk .na \fB\fBELOOP\fR\fR .ad .RS 16n .rt Too many symbolic links were encountered in translating the pathname in \fIaddress\fR. .RE .sp .ne 2 .mk .na \fB\fBENAMETOOLONG\fR\fR .ad .RS 16n .rt A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire pathname exceeded \fIPATH_MAX\fR characters. .RE .sp .ne 2 .mk .na \fB\fBENOENT\fR\fR .ad .RS 16n .rt A component of the pathname does not name an existing file or the pathname is an empty string. .RE .sp .ne 2 .mk .na \fB\fBENOTDIR\fR\fR .ad .RS 16n .rt A component of the path prefix of the pathname in \fIaddress\fR is not a directory. .RE .sp .LP The \fBconnect()\fR function may fail if: .sp .ne 2 .mk .na \fB\fBEACCES\fR\fR .ad .RS 16n .rt Search permission is denied for a component of the path prefix; or write access to the named socket is denied. Permission checks may be skipped for \fBAF_UNIX\fR sockets if the code was built with \fB__USE_SUNOS_SOCKETS__\fR defined before including the \fB<sys/socket.h>\fR header, or if it was built on Oracle Solaris 11.3 or earlier without requesting POSIX or X/Open standards conformance. .RE .sp .ne 2 .mk .na \fB\fBEADDRINUSE\fR\fR .ad .RS 16n .rt Attempt to establish a connection that uses addresses that are already in use. .RE .sp .ne 2 .mk .na \fB\fBECONNRESET\fR\fR .ad .RS 16n .rt Remote host reset the connection request. .RE .sp .ne 2 .mk .na \fB\fBEHOSTUNREACH\fR\fR .ad .RS 16n .rt The destination host cannot be reached (probably because the host is down or a remote router cannot reach it). .RE .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 16n .rt The \fIaddress_len\fR argument is not a valid length for the address family; or invalid address family in \fBsockaddr\fR structure. .RE .sp .ne 2 .mk .na \fB\fBENAMETOOLONG\fR\fR .ad .RS 16n .rt Pathname resolution of a symbolic link produced an intermediate result whose length exceeds \fIPATH_MAX\fR. .RE .sp .ne 2 .mk .na \fB\fBENETDOWN\fR\fR .ad .RS 16n .rt The local interface used to reach the destination is down. .RE .sp .ne 2 .mk .na \fB\fBENOBUFS\fR\fR .ad .RS 16n .rt No buffer space is available. .RE .sp .ne 2 .mk .na \fB\fBENOSR\fR\fR .ad .RS 16n .rt There were insufficient STREAMS resources available to complete the operation. .RE .sp .ne 2 .mk .na \fB\fBEOPNOTSUPP\fR\fR .ad .RS 16n .rt The socket is listening and can not be connected. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level Async-Signal-Safe _ Standard See \fBstandards\fR(7). .TE .sp .SH SEE ALSO .sp .LP \fBclose\fR(2), \fBpoll\fR(2), \fBaccept\fR(3C), \fBbind\fR(3C), \fBgetsockname\fR(3C), \fBselect\fR(3C), \fBsend\fR(3C), \fBshutdown\fR(3C), \fBsocket\fR(3C), \fBsocket.h\fR(3HEAD), \fBattributes\fR(7), \fBstandards\fR(7) .SH HISTORY .sp .LP The \fBconnect()\fR function has been present since the initial release of Solaris.