SDLNet_UDP_Bind
Name
SDLNet_UDP_Bind -- Bind an address to a channel on a socket.
Synopsis
int SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address);
sock The UDPsocket on which to assign the address.
channel The channel to assign address to. This should be less than SDLNET_MAX_UDPCHANNELS. If -1 is used, then the first unbound channel will be used, this should only be used for incomming packet filtering, as it will find the first channel with less than SDLNET_MAX_UDPADDRESSES assigned to it and use that one.
address The resolved IPaddress to assign to the socket's channel. The host and port are both used. It is not helpful to bind 0.0.0.0 to a channel.
Description
Bind an address to a channel on a socket.
Incoming packets are only allowed from bound addresses for the socket channel.
All outgoing packets on that channel, regardless of the packets internal address, will attempt to send once on each bound address on that channel.
You may assign up to SDLNET_MAX_UDPADDRESSES to each channel.
Return Value
Returns: The channel number that was bound. -1 is returned on errors, such as no free channels, or this channel has SDLNET_MAX_UDPADDRESSES already assigned to it, or you have used a channel higher or equal to SDLNET_MAX_UDPCHANNELS, or lower than -1.
Example
// Bind address to the first free channel
//UDPsocket udpsock;
//IPaddress *address;
int channel;
channel=SDLNet_UDP_Bind(udpsock, -1, address);
if(channel==-1) {
printf("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
// do something because we failed to bind
}
See Also
SDLNet_UDP_Unbind, SDLNet_UDP_GetPeerAddress, SDLNet_UDP_Open, IPaddress, UDPsocket
