/* ==================== 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"); }
/* ==================== NET_Init ==================== */ void NET_Init (int port) { WORD wVersionRequested; int r; wVersionRequested = MAKEWORD(1, 1); r = WSAStartup (MAKEWORD(1, 1), &winsockdata); if (r) Sys_Error ("Winsock initialization failed."); // // open the single socket to be used for all communications // net_socket = UDP_OpenSocket (port); // // init the message buffer // net_message.maxsize = sizeof(net_message_buffer); net_message.data = net_message_buffer; // // determine my name & address // NET_GetLocalAddress (); Con_Printf("UDP Initialized\n"); }
void NET_Init (int port) { #ifdef _WIN32 int r; WORD wVersionRequested; wVersionRequested = MAKEWORD (1, 1); r = WSAStartup (wVersionRequested, &winsockdata); if (r) Sys_Error ("Winsock initialization failed."); #endif /* _WIN32 */ net_socket = UDP_OpenSocket (port); // init the message buffer _net_message_message.maxsize = sizeof (net_message_buffer); _net_message_message.data = net_message_buffer; // determine my name & address NET_GetLocalAddress (); net_loopback_adr.ip[0] = 127; net_loopback_adr.ip[3] = 1; Sys_Printf ("UDP (IPv4) Initialized\n"); }
// // Open server TCP port. // NOTE: Zero port will actually close already opened port. // void NET_InitServer_TCP(unsigned short int port) { // close socket first. if (svs.sockettcp != INVALID_SOCKET) { Con_Printf("Server TCP port closed\n"); closesocket(svs.sockettcp); svs.sockettcp = INVALID_SOCKET; net_local_sv_tcpipadr.type = NA_INVALID; } if (port) { svs.sockettcp = TCP_OpenListenSocket (port); if (svs.sockettcp != INVALID_SOCKET) { // get local address. NET_GetLocalAddress (svs.sockettcp, &net_local_sv_tcpipadr); Con_Printf("Opening server TCP port %u\n", (unsigned int)port); } else { Con_Printf("Failed to open server TCP port %u\n", (unsigned int)port); } } }
void NET_InitClient(void) { int port = PORT_CLIENT; int p; p = COM_CheckParm ("-clientport"); if (p && p < COM_Argc()) { port = atoi(COM_Argv(p+1)); } if (cls.socketip == INVALID_SOCKET) cls.socketip = UDP_OpenSocket (port); if (cls.socketip == INVALID_SOCKET) cls.socketip = UDP_OpenSocket (PORT_ANY); // any dynamic port if (cls.socketip == INVALID_SOCKET) Sys_Error ("Couldn't allocate client socket"); // init the message buffer SZ_Init (&net_message, net_message_buffer, sizeof(net_message_buffer)); // determine my name & address NET_GetLocalAddress (cls.socketip, &net_local_cl_ipadr); Com_Printf_State (PRINT_OK, "Client port Initialized\n"); }
/* ==================== 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"); } }
/* <d4991> ../engine/net_ws.c:2182 */ void NET_Config(qboolean multiplayer) { int i; static qboolean old_config; static qboolean bFirst = TRUE; if (old_config == multiplayer) { return; } old_config = multiplayer; if (multiplayer) { if (!noip) NET_OpenIP(); #ifdef _WIN32 if (!noipx) NET_OpenIPX(); #endif //_WIN32 if (bFirst) { bFirst = FALSE; NET_GetLocalAddress(); } } else { NET_ThreadLock(); for (i = 0; i < 3; i++) { if (ip_sockets[i]) { #ifdef _WIN32 CRehldsPlatformHolder::get()->closesocket(ip_sockets[i]); #else SOCKET_CLOSE(ip_sockets[i]); #endif //_WIN32 ip_sockets[i] = 0; } #ifdef _WIN32 if (ipx_sockets[i]) { CRehldsPlatformHolder::get()->closesocket(ipx_sockets[i]); ipx_sockets[i] = 0; } #endif //_WIN32 } NET_ThreadUnlock(); } net_configured = multiplayer ? 1 : 0; }
// // BindToLocalPort // void BindToLocalPort (SOCKET s, u_short wanted) { int v; struct sockaddr_in address; memset (&address, 0, sizeof(address)); address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; u_short next = wanted; // denis - try several ports do { address.sin_port = htons(next++); v = bind (s, (sockaddr *)&address, sizeof(address)); if(next > wanted + 16) { I_FatalError ("BindToPort: error"); return; } }while (v == SOCKET_ERROR); char tmp[32] = ""; sprintf(tmp, "%d", next - 1); port.ForceSet(tmp); #ifdef ODA_HAVE_MINIUPNP std::string ip = NET_GetLocalAddress(); if (!ip.empty()) { sv_upnp_internalip.Set(ip.c_str()); Printf(PRINT_HIGH, "UPnP: Internal IP address is: %s\n", ip.c_str()); upnp_add_redir(ip.c_str(), next - 1); } else { Printf(PRINT_HIGH, "UPnP: Could not get first internal IP address, " "UPnP will not function\n"); is_upnp_ok = false; } #endif Printf(PRINT_HIGH, "Bound to local port %d\n", next - 1); }
/* ==================== NET_Init ==================== */ void NET_Init (int port) { // // open the single socket to be used for all communications // net_socket = UDP_OpenSocket (port); // // init the message buffer // net_message.maxsize = sizeof(net_message_buffer); net_message.data = net_message_buffer; // // determine my name & address // NET_GetLocalAddress (); Con_Printf("UDP Initialized\n"); }
void NET_InitServer (void) { int port = PORT_SERVER; int p; p = COM_CheckParm ("-port"); if (p && p < COM_Argc()) { port = atoi(COM_Argv(p+1)); } if (svs.socketip == INVALID_SOCKET) { svs.socketip = UDP_OpenSocket (port); } if (svs.socketip != INVALID_SOCKET) { NET_GetLocalAddress (svs.socketip, &net_local_sv_ipadr); Cvar_SetROM (&sv_local_addr, NET_AdrToString (net_local_sv_ipadr)); } else { // FIXME: is it right??? Cvar_SetROM (&sv_local_addr, ""); } if (svs.socketip == INVALID_SOCKET) { #ifdef SERVERONLY Sys_Error #else Con_Printf #endif ("WARNING: Couldn't allocate server socket\n"); } #ifndef SERVERONLY // init the message buffer SZ_Init (&net_message, net_message_buffer, sizeof(net_message_buffer)); #endif }
/* ==================== NET_Init ==================== */ void NET_Init (int port) { // // open the single socket to be used for all communications // net_socket = UDP_OpenSocket (port); // // init the message buffer // net_message.maxsize = sizeof(net_message_buffer); net_message.data = net_message_buffer; // // determine my name & address // NET_GetLocalAddress (); #if !defined (__APPLE__) && !defined (MACOSX) Con_Printf("UDP Initialized\n"); #endif /* !__APPLE__ &&Ê!MACOSX */ }
/* ==================== 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 ) ); }