TCPIP_UDP_Bind Function

C

bool TCPIP_UDP_Bind(UDP_SOCKET hUDP, IP_ADDRESS_TYPE addType, UDP_PORT localPort, IP_MULTI_ADDRESS* localAddress); 

Returns

  • true - Indicates success

  • false - Indicates failure

Description

Sockets don't need specific binding, it is done automatically by the stack However, specific binding can be requested using this function. Works for both client and server sockets. For a server socket it will restrict accepting connections of a specific type on a specific interface only. For a client socket it will force a specific address type and a local port and interface.

Remarks

If address type IP_ADDRESS_TYPE_ANY is used, the localAddress parameter won't be used and the socket won't change the local address. However, for the call to succeed, socket must have been created with IP_ADDRESS_TYPE_ANY type and must not be currently bound to a IP_ADDRESS_TYPE_IPV4/IP_ADDRESS_TYPE_IPV6 type. If address type IP_ADDRESS_TYPE_IPV4/IP_ADDRESS_TYPE_IPV6 is used, then the socket type will be changed accordingly, and the localAddress will be used, if provided. The socket will be bound to this type of address. For the call to succeed the socket must currently have the type IP_ADDRESS_TYPE_ANY or to match the addType parameter. If localAddress is the valid address of a network interface, and addType != IP_ADDRESS_TYPE_ANY, then the call will enforce UDP_OPTION_STRICT_NET on the socket. If localPort is 0, the stack will assign a unique local port (if the socket doesn't already have a unique local port) In order to change dynamically the type of address, the socket must have been created with a IP_ADDRESS_TYPE_ANY type and not currently bound to a different address type. TCPIP_UDP_Disconnect could be issued to remove a previous IP type binding.

Preconditions

UDP socket should have been opened with TCPIP_UDP_ServerOpen()/TCPIP_UDP_ClientOpen()(). hUDP - valid socket

Parameters

ParametersDescription
hUDPThe socket to bind.
addTypeThe type of address being used. Valid values are IP_ADDRESS_TYPE_ANY/IP_ADDRESS_TYPE_IPV4/IP_ADDRESS_TYPE_IPV6 .
localPortThe local port to bind to.
localAddressLocal address to use.