Microsoft Windows CE 3.0  

bind

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This function associates a local address with a socket.

int
bind(
SOCKET
s
,
const
struct
sockaddr
*
addr
,
int
namelen
);

Parameters

s
[in] Descriptor that identifies an unbound socket.
addr
[in] Address to assign to the socket from the SOCKADDRstructure.
namelen
[in] Length of the name.

Return Values

Zero indicates that no error occurred. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

For Infrared Sockets (IrSock), this function has the following additional requirements and behaviors:

  • The Af_irda.h must be explicitly included.
  • The sockaddr_irdastructure is used in the addrparameter.
  • The WSAENETDOWN error value is not supported.
  • There is no wildcard address equivalent to INADDR_ANY.
  • IrSocketsclients must notcall bind.
  • If the service name is of the form "LSAP-SEL XXX" where XXXis a decimal integer in the range 1-127, the address indicates a specific LSAP-SEL. LSAP-SEL XXXservice names will cause no IAS calls. The socket will be bound directly to the specified LSAP-SEL, bypassing IAS. Windows CE reserves LSAP-SEL0 for IAS and LSAP-SEL3 for internal use.

    The bindfunction is used on an unconnected socket before subsequent calls to the connector listenfunctions. It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. When a socket is created with a call to the socketfunction, it exists in a name space (address family), but it has no name assigned to it. Use the bindfunction to establish the local association of the socket by assigning a local name to an unnamed socket.

    A name consists of three parts when using the Internet address family: the address family, a host address, and a port number that identifies the application.

    If an application does not care what local address is assigned, specify the manifest constant value ADDR_ANY for the sa_datamember of the nameparameter. This allows the underlying service provider to use any appropriate network address, potentially simplifying application programming in the presence of multihomed hosts (that is, hosts that have more than one network interface and address).

    For TCP/IP, if the port is specified as zero, the service provider assigns a unique port to the application with a value between 1024 and 5000. The application can use getsocknameafter calling bindto learn the address and the port that has been assigned to it. If the Internet address is equal to INADDR_ANY, getsocknamemay notnecessarily supply the address until the socket is connected, since several addresses can be valid if the host is multihomed. Binding to a specific port number other than port 0 is discouraged for client applications, since there is a danger of conflicting with another socket already using that port number.

    Requirements

    Runs on Versions Defined in Include Link to
    Windows CE OS 1.0 and later Winsock.h    
    Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

    See Also

    connect, listen, getsockname, setsockopt, socket, SOCKADDR, SOCKADDR_IN, SOCKADDR_IRDA