|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 );
Zero indicates that no error occurred. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.
For Infrared Sockets (IrSock), this function has the following additional requirements and behaviors:
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.
|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.