Beispiel #1
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP( void )
{
    cvar_t	*ip;
    int		port;
    int		i;

    ip = Cvar_Get( "net_ip", "localhost", CVAR_LATCH );
    port = Cvar_Get( "net_port", va( "%i", PORT_SERVER ), CVAR_LATCH )->integer;

    // automatically scan for a valid port, so multiple
    // dedicated servers can be started without requiring
    // a different net_port for each one
    for( i = 0 ; i < 10 ; i++ ) {
        ip_socket = NET_IPSocket( ip->string, port + i );
        if ( ip_socket ) {
            Cvar_SetValue( "net_port", port + i );
            if ( net_socksEnabled->integer ) {
                NET_OpenSocks( port + i );
            }
#ifdef _XBOX
            NET_GetLocalAddress( false );
#else
            NET_GetLocalAddress();
#endif
            return;
        }
    }
    Com_Printf( "WARNING: Couldn't allocate IP port\n");
}
Beispiel #2
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP( void ) {
	int		i;
	int		err;
	int		port;
	int		port6;

	port = net_port->integer;
	port6 = net_port6->integer;

	NET_GetLocalAddress();

	// automatically scan for a valid port, so multiple
	// dedicated servers can be started without requiring
	// a different net_port for each one

	if(net_enabled->integer & NET_ENABLEV6)
	{
		for( i = 0 ; i < 10 ; i++ )
		{
			ip6_socket = NET_IP6Socket(net_ip6->string, port6 + i, &boundto, &err);
			if (ip6_socket != INVALID_SOCKET)
			{
				Cvar_SetValue( "net_port6", port6 + i );
				break;
			}
			else
			{
				if(err == EAFNOSUPPORT)
					break;
			}
		}
		if(ip6_socket == INVALID_SOCKET)
			Com_Printf( "WARNING: Couldn't bind to a v6 ip address.\n");
	}

	if(net_enabled->integer & NET_ENABLEV4)
	{
		for( i = 0 ; i < 10 ; i++ ) {
			ip_socket = NET_IPSocket( net_ip->string, port + i, &err );
			if (ip_socket != INVALID_SOCKET) {
				Cvar_SetValue( "net_port", port + i );

				if (net_socksEnabled->integer)
					NET_OpenSocks( port + i );

				break;
			}
			else
			{
				if(err == EAFNOSUPPORT)
					break;
			}
		}
		
		if(ip_socket == INVALID_SOCKET)
			Com_Printf( "WARNING: Couldn't bind to a v4 ip address.\n");
	}
}
Beispiel #3
0
/*
==================
InitForPort
==================
*/
bool idPort::InitForPort( int portNumber ) {
	int len = sizeof( struct sockaddr_in );

	netSocket = NET_IPSocket( net_ip.GetString(), portNumber, &bound_to );
	if ( netSocket <= 0 ) {
		netSocket = 0;
		memset( &bound_to, 0, sizeof( bound_to ) );
		return false;
	}

#if 0
	if ( net_socksEnabled.GetBool() ) {
		NET_OpenSocks( portNumber );
	}
#endif

	udpPorts[ bound_to.port ] = new idUDPLag;

	return true;
}
Beispiel #4
0
/*
====================
NET_OpenIP
====================
*/
static void NET_OpenIP( void )
{
	int i;
	int err;
	int port = PORT_ANY;
	int port6 = PORT_ANY;

	struct sockaddr_in boundto4;

	if ( serverMode )
	{
		port = NET_EnsureValidPortNo( net_port->integer );
		port6 = NET_EnsureValidPortNo( net_port6->integer );
	}

	NET_GetLocalAddress();

	// automatically scan for a valid port, so multiple
	// dedicated servers can be started without requiring
	// a different net_port for each one

	if ( net_enabled->integer & NET_ENABLEV6 )
	{
		for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i++ )
		{
			ip6_socket = NET_IP6Socket( net_ip6->string, port6, &boundto, &err );

			if ( ip6_socket != INVALID_SOCKET )
			{
				port6 = ntohs( boundto.sin6_port );
				break;
			}
			else if ( err == EAFNOSUPPORT )
			{
				port6 = PORT_ANY;
				break;
			}

			port6 = ( port6 == PORT_ANY ) ? port6 : NET_EnsureValidPortNo( port6 + 1 );
		}

		if ( ip6_socket == INVALID_SOCKET || err == EAFNOSUPPORT )
		{
			Com_Printf( "WARNING: Couldn't bind to an IPv6 address.\n" );
			port6 = PORT_ANY;
		}
	}

	if ( net_enabled->integer & NET_ENABLEV4 )
	{
		for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i++ )
		{
			ip_socket = NET_IPSocket( net_ip->string, port, &boundto4, &err );

			if ( ip_socket != INVALID_SOCKET )
			{
				port = ntohs( boundto4.sin_port );
				break;
			}
			else if ( err == EAFNOSUPPORT )
			{
				port = PORT_ANY;
				break;
			}

			port = ( port == PORT_ANY ) ? port : NET_EnsureValidPortNo( port + 1 );
		}

		if ( ip_socket == INVALID_SOCKET )
		{
			Com_Printf( "WARNING: Couldn't bind to an IPv4 address.\n" );
			port = PORT_ANY;
		}
	}

	if ( port != PORT_ANY && net_socksEnabled->integer )
	{
		NET_OpenSocks( port );
	}

	Cvar_Set( "net_currentPort", va( "%i", port ) );
	Cvar_Set( "net_currentPort6", va( "%i", port6 ) );
}