xref: /titanic_44/usr/src/man/man3xnet/connect.3xnet (revision 56b2bdd1f04d465cfe4a95b88ae5cba5884154e4)
te
Copyright 1994, The X/Open Company Ltd. All Rights Reserved Portions Copyright 1989 AT&T Portions Copyright (c) 1998, Sun Microsystems, Inc. All Rights Reserved
Sun Microsystems, Inc. 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.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
CONNECT 3XNET "Jun 10, 2002"
NAME
connect - connect a socket
SYNOPSIS

cc [ flag ... ] file ... -lxnet [ library ... ]
#include <sys/socket.h>

int connect(int socket, const struct sockaddr *address,
 socklen_t address_len);
DESCRIPTION

The connect() function requests a connection to be made on a socket. The function takes the following arguments: socket

Specifies the file descriptor associated with the socket.

address

Points to a sockaddr structure containing the peer address. The length and format of the address depend on the address family of the socket.

address_len

Specifies the length of the sockaddr structure pointed to by the address argument.

If the socket has not already been bound to a local address, connect() will bind it to an address which, unless the socket's address family is AF_UNIX, is an unused local address.

If the initiating socket is not connection-mode, then connect() sets the socket's peer address, but no connection is made. For SOCK_DGRAM sockets, the peer address identifies where all datagrams are sent on subsequent send(3XNET) calls, and limits the remote sender for subsequent recv(3XNET) calls. If address is a null address for the protocol, the socket's peer address will be reset.

If the initiating socket is connection-mode, then connect() attempts to establish a connection to the address specified by the address argument.

If the connection cannot be established immediately and O_NONBLOCK is not set for the file descriptor for the socket, connect() will block for up to an unspecified timeout interval until the connection is established. If the timeout interval expires before the connection is established, connect() will fail and the connection attempt will be aborted. If connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() will fail and set errno to EINTR, but the connection request will not be aborted, and the connection will be established asynchronously.

If the connection cannot be established immediately and O_NONBLOCK is set for the file descriptor for the socket, connect() will fail and set errno to EINPROGRESS, but the connection request will not be aborted, and the connection will be established asynchronously. Subsequent calls to connect() for the same socket, before the connection is established, will fail and set errno to EALREADY.

When the connection has been established asynchronously, select(3C) and poll(2) will indicate that the file descriptor for the socket is ready for writing.

The socket in use may require the process to have appropriate privileges to use the connect() function.

USAGE

If connect() fails, the state of the socket is unspecified. Portable applications should close the file descriptor and create a new socket before attempting to reconnect.

RETURN VALUES

Upon successful completion, connect() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.

ERRORS

The connect() function will fail if: EADDRNOTAVAIL

The specified address is not available from the local machine.

EAFNOSUPPORT

The specified address is not a valid address for the address family of the specified socket.

EALREADY

A connection request is already in progress for the specified socket.

EBADF

The socket argument is not a valid file descriptor.

ECONNREFUSED

The target address was not listening for connections or refused the connection request.

EFAULT

The address parameter can not be accessed.

EINPROGRESS

O_NONBLOCK is set for the file descriptor for the socket and the connection cannot be immediately established; the connection will be established asynchronously.

EINTR

The attempt to establish a connection was interrupted by delivery of a signal that was caught; the connection will be established asynchronously.

EISCONN

The specified socket is connection-mode and is already connected.

ENETUNREACH

No route to the network is present.

ENOTSOCK

The socket argument does not refer to a socket.

EPROTOTYPE

The specified address has a different type than the socket bound to the specified peer address.

ETIMEDOUT

The attempt to connect timed out before a connection was made.

If the address family of the socket is AF_UNIX, then connect() will fail if: EIO

An I/O error occurred while reading from or writing to the file system.

ELOOP

Too many symbolic links were encountered in translating the pathname in address.

ENAMETOOLONG

A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters.

ENOENT

A component of the pathname does not name an existing file or the pathname is an empty string.

ENOTDIR

A component of the path prefix of the pathname in address is not a directory.

The connect() function may fail if: EACCES

Search permission is denied for a component of the path prefix; or write access to the named socket is denied.

EADDRINUSE

Attempt to establish a connection that uses addresses that are already in use.

ECONNRESET

Remote host reset the connection request.

EHOSTUNREACH

The destination host cannot be reached (probably because the host is down or a remote router cannot reach it).

EINVAL

The address_len argument is not a valid length for the address family; or invalid address family in sockaddr structure.

ENAMETOOLONG

Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX.

ENETDOWN

The local interface used to reach the destination is down.

ENOBUFS

No buffer space is available.

ENOSR

There were insufficient STREAMS resources available to complete the operation.

EOPNOTSUPP

The socket is listening and can not be connected.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Standard
MT-Level MT-Safe
SEE ALSO

close(2), poll(2), accept(3XNET), bind(3XNET), getsockname(3XNET), select(3C), send(3XNET), shutdown(3XNET), socket(3XNET), attributes(5), standards(5)