unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (OSF1-V5.1-alpha)
Page:
Section:
Apropos / Subsearch:
optional field



connect(2)							   connect(2)



NAME
  connect - Connects two sockets

SYNOPSIS

  #include <&lt;sys/socket.h>&gt;

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

  [XNS4.0]  The	definition of the connect() function in	XNS4.0 uses a size_t
  data type instead of a socklen_t data	type as	specified in XNS5.0 (the pre-
  vious	definition).

  [Tru64 UNIX]	The following definition of the	connect() function  does not
  conform to current standards and is supported	only for backward compatibil-
  ity (see standards(5)):

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

STANDARDS

  Interfaces documented	on this	reference page conform to industry standards
  as follows:

  connect():  XNS5.0

  Refer	to the standards(5) reference page for more information	about indus-
  try standards	and associated tags.

PARAMETERS

  socket
      Specifies	a file descriptor for the socket.

  address
      Points to	a sockaddr structure, the format of which is determined	by
      the domain and by	the behavior requested for the socket.	The sockaddr
      structure	is an overlay for a sockaddr_in, sockaddr_un, sockaddr_in6,
      or sockaddr_storage structure, depending on which	of the supported
      address families is active.

      [Tru64 UNIX]   If	the compile-time option	_SOCKADDR_LEN is defined
      before the sys/socket.h header file is included, the sockaddr structure
      takes 4.4BSD behavior, with a field for specifying the length of the
      socket address.  Otherwise, the default 4.3BSD sockaddr structure	is
      used, with the length of the socket address assumed to be	14 bytes or
      less.

      If _SOCKADDR_LEN is defined, the 4.3BSD sockaddr structure is defined
      with the name osockaddr.

  address_len
      Specifies	the length of the sockaddr structure pointed to	by the
      address parameter.

DESCRIPTION

  The connect()	function requests a connection between two sockets.  The ker-
  nel sets up the communications links between the sockets; both sockets must
  use the same address format and protocol.

  The connect()	function performs a different action for each of the follow-
  ing types of initiating sockets:

    +  If the initiating socket	is SOCK_DGRAM, the connect() function estab-
       lishes the peer address.	 The peer address identifies the socket	where
       all datagrams are sent on subsequent send() functions. It also identi-
       fies the	socket from where datagrams can	be received; datagrams from
       other peer addresses are	not delivered.	If address is a	null address
       for the protocol, the socket's peer address is reset.

       No connections are made by this connect function.

    +  If the initiating socket	is SOCK_STREAM,	the connect() function
       attempts	to make	a connection to	the socket specified by	the address
       parameter.  Each	communication space interprets the address parameter
       differently.

  If the function fails	for a connection mode socket, applications should use
  the close() function to deallocate the socket	and descriptor.	 If attempt-
  ing to reinitiate the	connection, applications should	create a new socket.

  If the connection cannot be established immediately, one of the following
  occurs:

    +  If the socket file descriptor is	marked non-blocking, the connect()
       function	fails and sets errno to	[EINPROGRESS]. However,	the connec-
       tion request is not aborted; the	connection will	be established asyn-
       chronously.  If you make	a call to connect() for	the same socket
       before the connection is	established, the function fails	and sets
       errno to	[EALREADY].

    +  If the socket file descriptor is	marked blocking, the connect() func-
       tion blocks for an unspecified amount of	time until the connection is
       established.  If	the timeout interval expires before the	connection is
       established, the	function fails and aborts the connection attempt.
       While blocked, if connect() is interrupted by a signal, it fails	and
       sets errno to [EINTR].  However,	the connection request is not
       aborted;	the connection is established asynchronously.

RETURN VALUES

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

ERRORS

  If the connect() function fails, errno may be	set to one of the following
  values:

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

	    [XNS4.0]  This error applies to AF_UNIX sockets only.

  [EADDRINUSE]
	    The	specified address is already in	use.

  [EADDRNOTAVAIL]
	    The	specified address is not available from	the local machine.

  [EAFNOSUPPORT]
	    The	addresses in the specified address family cannot be used with
	    this socket.

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

  [EBADF]   The	socket parameter is not	valid.

  [ECONNREFUSED]
	    The	attempt	to connect was rejected.

  [ECONNRESET]
	    The	remote host reset the connection request.

  [EFAULT]  The	address	parameter is not in a readable part of the user
	    address space.

  [EHOSTUNREACH]
	    The	specified host is not reachable.

  [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	connect() function was interrupted by a	signal while waiting
	    for	the connection to be established.  The connection establish-
	    ment may continue asynchronously.

  [EINVAL]  The	value of the address_len parameter is invalid for the speci-
	    fied address family; or the	sa_family field	in the socket address
	    structure is invalid for the protocol.

  [EIO]	    For	an AF_UNIX socket, an I/O error	occurred while reading from
	    or writing to the file system.

  [EISCONN] The	socket is already connected.

  [ELOOP]   For	an AF_UNIX socket, too many symbolic links were	encountered
	    in translating the pathname	in address.

  [ENAMETOOLONG]
	    A component	of the pathname	exceeded NAME_MAX characters, or an
	    entire pathname exceeded PATH_MAX characters.

  [ENETDOWN]
	    The	local network connection is not	operational.

  [ENETUNREACH]
	    No route to	the network or host is present.

  [ENOBUFS] Insufficient resources are available in the	system to complete
	    the	call.

  [ENOENT]  For	an AF_UNIX socket, a component of the pathname does not	name
	    an existing	file or	the pathname is	an empty string.

  [ENOSR]   The	available STREAMS resources were insufficient for the opera-
	    tion to complete.

  [ENOTDIR] For	an AF_UNIX socket, a component of the path prefix of the
	    pathname in	address	is not a directory.

  [ENOTSOCK]
	    The	socket parameter refers	to a file, not a socket.

  [EOPNOTSUPP]
	    The	socket is listening and	cannot be connected.

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

  [ETIMEDOUT]
	    The	establishment of a connection timed out	before a connection
	    was	made.

  [EWOULDBLOCK]
	    [Tru64 UNIX]  The socket is	marked nonblocking, so the connection
	    cannot be immediately completed.  The application program can
	    select the socket for writing during the connection	process.

RELATED	INFORMATION

  Functions: accept(2),	bind(2), socket(2), getsockname(2), select(2),
  send(2).

  Standards: standards(5).