Пример #1
0
/* Bind the address 'address' to the requested channel on the UDP socket.
   If the channel is -1, then the first unbound channel that has not yet
   been bound to the maximum number of addresses will be bound with
   the given address as it's primary address.
   If the channel is already bound, this new address will be added to the
   list of valid source addresses for packets arriving on the channel.
   If the channel is not already bound, then the address becomes the primary
   address, to which all outbound packets on the channel are sent.
   This function returns the channel which was bound, or -1 on error.
*/
int SDLNet_UDP_Bind(UDPsocket sock, int channel, const IPaddress *address)
{
    struct UDP_channel *binding;

    if ( sock == NULL ) {
        SDLNet_SetError("Passed a NULL socket");
        return(-1);
    }

    if ( channel == -1 ) {
        for ( channel=0; channel < SDLNET_MAX_UDPCHANNELS; ++channel ) {
            binding = &sock->binding[channel];
            if ( binding->numbound < SDLNET_MAX_UDPADDRESSES ) {
                break;
            }
        }
    } else {
        if ( ! ValidChannel(channel) ) {
            return(-1);
        }
        binding = &sock->binding[channel];
    }
    if ( binding->numbound == SDLNET_MAX_UDPADDRESSES ) {
        SDLNet_SetError("No room for new addresses");
        return(-1);
    }
    binding->address[binding->numbound++] = *address;
    return(channel);
}
Пример #2
0
/* Get the primary IP address of the remote system associated with the
   socket and channel.
   If the channel is not bound, this function returns NULL.
 */
IPaddress *SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel)
{
    IPaddress *address;

    address = NULL;
    switch (channel) {
        case -1:
            /* Return the actual address of the socket */
            address = &sock->address;
            break;
        default:
            /* Return the address of the bound channel */
            if ( ValidChannel(channel) &&
                (sock->binding[channel].numbound > 0) ) {
                address = &sock->binding[channel].address[0];
            }
            break;
    }
    return(address);
}
Пример #3
0
/* Bind the address 'address' to the requested channel on the UDP socket.
   If the channel is -1, then the first unbound channel will be bound with
   the given address as it's primary address.
   If the channel is already bound, this new address will be added to the
   list of valid source addresses for packets arriving on the channel.
   If the channel is not already bound, then the address becomes the primary
   address, to which all outbound packets on the channel are sent.
   This function returns the channel which was bound, or -1 on error.
*/
int SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address)
{
	struct UDP_channel *binding;

	if ( channel == -1 ) {
		for ( channel=0; channel < SDLNET_MAX_UDPCHANNELS; ++channel ) {
			binding = &sock->binding[channel];
			if ( binding->numbound < SDLNET_MAX_UDPADDRESSES ) {
				break;
			}
		}
	} else {
		if ( ! ValidChannel(channel) ) {
			return(-1);
		}
		binding = &sock->binding[channel];
	}
	if ( binding->numbound == SDLNET_MAX_UDPADDRESSES ) {
		iprintf("SDL_NET: No room for new addresses");
		return(-1);
	}
	binding->address[binding->numbound++] = *address;
	return(channel);
}