<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>connect</TITLE
|
>connect</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="bind"
|
TITLE="bind"
|
HREF="net-common-tcpip-manpages-bind.html"><LINK
|
HREF="net-common-tcpip-manpages-bind.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="getpeername"
|
TITLE="getpeername"
|
HREF="net-common-tcpip-manpages-getpeername.html"></HEAD
|
HREF="net-common-tcpip-manpages-getpeername.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-bind.html"
|
HREF="net-common-tcpip-manpages-bind.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 38. TCP/IP Library Reference</TD
|
>Chapter 38. TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-getpeername.html"
|
HREF="net-common-tcpip-manpages-getpeername.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="NET-COMMON-TCPIP-MANPAGES-CONNECT">connect</H1
|
NAME="NET-COMMON-TCPIP-MANPAGES-CONNECT">connect</H1
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>CONNECT(2) System Calls Manual CONNECT(2)
|
>CONNECT(2) System Calls Manual CONNECT(2)
|
|
|
NAME
|
NAME
|
connect - initiate a connection on a socket
|
connect - initiate a connection on a socket
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/socket.h>
|
#include <sys/socket.h>
|
|
|
int
|
int
|
connect(int s, const struct sockaddr *name, socklen_t namelen);
|
connect(int s, const struct sockaddr *name, socklen_t namelen);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
The parameter s is a socket. If it is of type SOCK_DGRAM, this call
|
The parameter s is a socket. If it is of type SOCK_DGRAM, this call
|
specifies the peer with which the socket is to be associated; this
|
specifies the peer with which the socket is to be associated; this
|
address is that to which datagrams are to be sent, and the only address
|
address is that to which datagrams are to be sent, and the only address
|
from which datagrams are to be received. If the socket is of type
|
from which datagrams are to be received. If the socket is of type
|
SOCK_STREAM, this call attempts to make a connection to another socket.
|
SOCK_STREAM, this call attempts to make a connection to another socket.
|
The other socket is specified by name, which is an address in the commu-
|
The other socket is specified by name, which is an address in the commu-
|
nications space of the socket. Each communications space interprets the
|
nications space of the socket. Each communications space interprets the
|
name parameter in its own way. Generally, stream sockets may success-
|
name parameter in its own way. Generally, stream sockets may success-
|
fully connect() only once; datagram sockets may use connect() multiple
|
fully connect() only once; datagram sockets may use connect() multiple
|
times to change their association. Datagram sockets may dissolve the
|
times to change their association. Datagram sockets may dissolve the
|
association by connecting to an invalid address, such as a null address.
|
association by connecting to an invalid address, such as a null address.
|
|
|
RETURN VALUES
|
RETURN VALUES
|
If the connection or binding succeeds, 0 is returned. Otherwise a -1 is
|
If the connection or binding succeeds, 0 is returned. Otherwise a -1 is
|
returned, and a more specific error code is stored in errno.
|
returned, and a more specific error code is stored in errno.
|
|
|
ERRORS
|
ERRORS
|
The connect() call fails if:
|
The connect() call fails if:
|
|
|
[EBADF] S is not a valid descriptor.
|
[EBADF] S is not a valid descriptor.
|
|
|
[ENOTSOCK] S is a descriptor for a file, not a socket.
|
[ENOTSOCK] S is a descriptor for a file, not a socket.
|
|
|
[EADDRNOTAVAIL] The specified address is not available on this
|
[EADDRNOTAVAIL] The specified address is not available on this
|
machine.
|
machine.
|
|
|
[EAFNOSUPPORT] Addresses in the specified address family cannot be
|
[EAFNOSUPPORT] Addresses in the specified address family cannot be
|
used with this socket.
|
used with this socket.
|
|
|
[EISCONN] The socket is already connected.
|
[EISCONN] The socket is already connected.
|
|
|
[ETIMEDOUT] Connection establishment timed out without establish-
|
[ETIMEDOUT] Connection establishment timed out without establish-
|
ing a connection.
|
ing a connection.
|
|
|
[EINVAL] A TCP connection with a local broadcast, the all-ones
|
[EINVAL] A TCP connection with a local broadcast, the all-ones
|
or a multicast address as the peer was attempted.
|
or a multicast address as the peer was attempted.
|
|
|
[ECONNREFUSED] The attempt to connect was forcefully rejected.
|
[ECONNREFUSED] The attempt to connect was forcefully rejected.
|
|
|
[EINTR] A connect was interrupted before it succeeded by the
|
[EINTR] A connect was interrupted before it succeeded by the
|
delivery of a signal.
|
delivery of a signal.
|
|
|
[ENETUNREACH] The network isn't reachable from this host.
|
[ENETUNREACH] The network isn't reachable from this host.
|
|
|
[EADDRINUSE] The address is already in use.
|
[EADDRINUSE] The address is already in use.
|
|
|
[EFAULT] The name parameter specifies an area outside the pro-
|
[EFAULT] The name parameter specifies an area outside the pro-
|
cess address space.
|
cess address space.
|
|
|
[EINPROGRESS] The socket is non-blocking and the connection cannot
|
[EINPROGRESS] The socket is non-blocking and the connection cannot
|
be completed immediately. It is possible to select(2)
|
be completed immediately. It is possible to select(2)
|
or poll(2) for completion by selecting the socket for
|
or poll(2) for completion by selecting the socket for
|
writing, and also use getsockopt(2) with SO_ERROR to
|
writing, and also use getsockopt(2) with SO_ERROR to
|
check for error conditions.
|
check for error conditions.
|
|
|
[EALREADY] The socket is non-blocking and a previous connection
|
[EALREADY] The socket is non-blocking and a previous connection
|
attempt has not yet been completed.
|
attempt has not yet been completed.
|
|
|
The following errors are specific to connecting names in the UNIX domain.
|
The following errors are specific to connecting names in the UNIX domain.
|
These errors may not apply in future versions of the UNIX IPC domain.
|
These errors may not apply in future versions of the UNIX IPC domain.
|
|
|
[ENOTDIR] A component of the path prefix is not a directory.
|
[ENOTDIR] A component of the path prefix is not a directory.
|
|
|
[ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} charac-
|
[ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} charac-
|
ters, or an entire path name exceeded {PATH_MAX} char-
|
ters, or an entire path name exceeded {PATH_MAX} char-
|
acters.
|
acters.
|
|
|
[ENOENT] The named socket does not exist.
|
[ENOENT] The named socket does not exist.
|
|
|
[EACCES] Search permission is denied for a component of the
|
[EACCES] Search permission is denied for a component of the
|
path prefix.
|
path prefix.
|
|
|
[EACCES] Write access to the named socket is denied.
|
[EACCES] Write access to the named socket is denied.
|
|
|
[ELOOP] Too many symbolic links were encountered in translat-
|
[ELOOP] Too many symbolic links were encountered in translat-
|
ing the pathname.
|
ing the pathname.
|
|
|
SEE ALSO
|
SEE ALSO
|
accept(2), getsockname(2), getsockopt(2), poll(2), select(2), socket(2)
|
accept(2), getsockname(2), getsockopt(2), poll(2), select(2), socket(2)
|
|
|
HISTORY
|
HISTORY
|
The connect() function call appeared in 4.2BSD.
|
The connect() function call appeared in 4.2BSD.
|
|
|
BSD February 15, 1999 BSD
|
BSD February 15, 1999 BSD
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-bind.html"
|
HREF="net-common-tcpip-manpages-bind.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-getpeername.html"
|
HREF="net-common-tcpip-manpages-getpeername.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>bind</TD
|
>bind</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>getpeername</TD
|
>getpeername</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|