SDLNet_UDP_GetPeerAddress

Name

SDLNet_UDP_GetPeerAddress -- Get the primary address assigned to this channel.

Synopsis

IPaddress *SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel)

sock A valid UDPsocket that probably has an address assigned to the channel.

channel The channel to get the primary address from in the socket. This may also be -1 to get the port which this socket is bound to on the local computer.

Description

Get the primary address assigned to this channel. Only the first bound address is returned.

When channel is -1, get the port that this socket is bound to on the local computer, this only means something if you opened the socket with a specific port number.

Do not free the returned IPaddress pointer.

Return Value

Returns: a pointer to an IPaddress. NULL is returned for unbound channels and on any errors.

Example

// get the primary address bound to UDPsocket channel 0
//UDPsocket udpsock;
IPaddress *address;

address=SDLNet_UDP_GetPeerAddress(udpsock, 0);
if(!address) {
    printf("SDLNet_UDP_GetPeerAddress: %s\n", SDLNet_GetError());
    // do something because we failed to get the address
}
else {
    // perhaps print out address->host and address->port
}

See Also

SDLNet_UDP_Bind, SDLNet_UDP_Unbind, IPaddress, UDPsocket

SDLNet_UDP_GetPeerAddress (last edited 2008-04-17 08:18:46 by localhost)