当前位置: 首页>>代码示例>>C++>>正文


C++ NET_ErrorString函数代码示例

本文整理汇总了C++中NET_ErrorString函数的典型用法代码示例。如果您正苦于以下问题:C++ NET_ErrorString函数的具体用法?C++ NET_ErrorString怎么用?C++ NET_ErrorString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NET_ErrorString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SV_SendClientsFragments

/*
* SV_SendClientsFragments
*/
bool SV_SendClientsFragments( void )
{
	client_t *client;
	int i;
	bool sent = false;

	// send a message to each connected client
	for( i = 0, client = svs.clients; i < sv_maxclients->integer; i++, client++ )
	{
		if( client->state == CS_FREE || client->state == CS_ZOMBIE )
			continue;
		if( client->edict && ( client->edict->r.svflags & SVF_FAKECLIENT ) )
			continue;
		if( !client->netchan.unsentFragments )
			continue;

		if( !Netchan_TransmitNextFragment( &client->netchan ) )
		{
			Com_Printf( "Error sending fragment to %s: %s\n", NET_AddressToString( &client->netchan.remoteAddress ),
				NET_ErrorString() );
			if( client->reliable )
				SV_DropClient( client, DROP_TYPE_GENERAL, "Error sending fragment: %s\n", NET_ErrorString() );
			continue;
		}

		sent = true;
	}

	return sent;
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:33,代码来源:sv_send.c

示例2: TV_Relay_SendClientMessages

/*
* TV_Relay_SendClientMessages
*/
void TV_Relay_SendClientMessages( relay_t *relay )
{
	int i;
	client_t *client;

	assert( relay );

	// send a message to each connected client
	for( i = 0, client = tvs.clients; i < tv_maxclients->integer; i++, client++ )
	{
		if( client->state != CS_SPAWNED )
			continue;
		if( client->relay != relay )
			continue;

		if( !TV_Relay_SendClientDatagram( relay, client ) )
		{
			Com_Printf( "%s" S_COLOR_WHITE ": Error sending message: %s\n", client->name, NET_ErrorString() );
			if( client->reliable )
			{
				TV_Downstream_DropClient( client, DROP_TYPE_GENERAL, "Error sending message: %s\n",
					NET_ErrorString() );
			}
		}
	}
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:29,代码来源:tv_relay_client.c

示例3: TV_Downstream_SendClientsFragments

/*
* TV_Downstream_SendClientsFragments
*/
qboolean TV_Downstream_SendClientsFragments( void )
{
	client_t *client;
	int i;
	qboolean remaining = qfalse;

	// send a message to each connected client
	for( i = 0, client = tvs.clients; i < tv_maxclients->integer; i++, client++ )
	{
		if( client->state == CS_FREE || client->state == CS_ZOMBIE )
			continue;

		if( !client->netchan.unsentFragments )
			continue;

		if( !Netchan_TransmitNextFragment( &client->netchan ) )
		{
			Com_Printf( "%s" S_COLOR_WHITE ": Error sending fragment: %s\n", client->name, NET_ErrorString() );
			if( client->reliable )
			{
				TV_Downstream_DropClient( client, DROP_TYPE_GENERAL, "Error sending fragment: %s\n",
					NET_ErrorString() );
			}
			continue;
		}

		if( client->netchan.unsentFragments )
			remaining = qtrue;
	}

	return remaining;
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:35,代码来源:tv_downstream.c

示例4: NET_IPSocket

/*
====================
NET_Socket
====================
*/
int NET_IPSocket (char *net_interface, int port)
{
	int newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (newsocket == -1)
	{
		Com_Printf ("UDP_OpenSocket: Couldn't make socket: %s\n", LOG_NET, NET_ErrorString());
		return 0;
	}

	if (newsocket >= FD_SETSIZE)
		Com_Error (ERR_FATAL, "NET_IPSocket: socket is higher than FD_SETSIZE");

	// make it non-blocking
	qboolean _true = true;
	if (ioctl (newsocket, FIONBIO, &_true) == -1)
	{
		Com_Printf ("UDP_OpenSocket: Couldn't make non-blocking: %s\n", LOG_NET, NET_ErrorString());
		return 0;
	}

	// make it broadcast capable
	int	i = 1;
	if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
	{
		Com_Printf ("UDP_OpenSocket: Couldn't set SO_BROADCAST: %s\n", LOG_NET, NET_ErrorString());
		return 0;
	}

	// r1: accept icmp unreachables for quick disconnects
	if (!net_no_recverr->intvalue)
	{
		if (setsockopt (newsocket, IPPROTO_IP, IP_RECVERR, (char *)&i, sizeof(i)) == -1)
		{
			Com_Printf ("UDP_OpenSocket: Couldn't set IP_RECVERR: %s\n", LOG_NET, NET_ErrorString());
		}
	}

	struct sockaddr_in address;
	if (!net_interface || !net_interface[0] || !Q_stricmp(net_interface, "localhost"))
		address.sin_addr.s_addr = INADDR_ANY;
	else
		NET_StringToSockaddr (net_interface, (struct sockaddr *)&address);

	if (port == PORT_ANY)
		address.sin_port = 0;
	else
		address.sin_port = htons((uint16)port);

	address.sin_family = AF_INET;

	if( bind (newsocket, (struct sockaddr *) &address, sizeof(address)) == -1)
	{
		close (newsocket);
		Com_Printf ("UDP_OpenSocket: Couldn't bind to UDP port %d: %s\n", LOG_NET, port, NET_ErrorString());
		return 0;
	}

	return newsocket;
}
开发者ID:turol,项目名称:webquake2,代码行数:64,代码来源:net_udp.c

示例5: NET_IPSocket

/*
====================
NET_IPSocket
====================
*/
int NET_IPSocket( char *net_interface, int port ) {
	SOCKET newsocket;
	struct sockaddr_in address;
//bani - was improper parameter
	unsigned long _true = qtrue;
	int i = 1;
	int err;

	if ( net_interface ) {
		Com_Printf( "Opening IP socket: %s:%i\n", net_interface, port );
	} else {
		Com_Printf( "Opening IP socket: localhost:%i\n", port );
	}

	if ( ( newsocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) == INVALID_SOCKET ) {
		err = WSAGetLastError();
		if ( err != WSAEAFNOSUPPORT ) {
			Com_Printf( "WARNING: UDP_OpenSocket: socket: %s\n", NET_ErrorString() );
		}
		return 0;
	}

	// make it non-blocking
	if ( ioctlsocket( newsocket, FIONBIO, &_true ) == SOCKET_ERROR ) {
		Com_Printf( "WARNING: UDP_OpenSocket: ioctl FIONBIO: %s\n", NET_ErrorString() );
		return 0;
	}

	// make it broadcast capable
	if ( setsockopt( newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof( i ) ) == SOCKET_ERROR ) {
		Com_Printf( "WARNING: UDP_OpenSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString() );
		return 0;
	}

	if ( !net_interface || !net_interface[0] || !Q_stricmp( net_interface, "localhost" ) ) {
		address.sin_addr.s_addr = INADDR_ANY;
	} else {
		Sys_StringToSockaddr( net_interface, (struct sockaddr *)&address );
	}

	if ( port == PORT_ANY ) {
		address.sin_port = 0;
	} else {
		address.sin_port = htons( (short)port );
	}

	address.sin_family = AF_INET;

	if ( bind( newsocket, (void *)&address, sizeof( address ) ) == SOCKET_ERROR ) {
		Com_Printf( "WARNING: UDP_OpenSocket: bind: %s\n", NET_ErrorString() );
		closesocket( newsocket );
		return 0;
	}

	//bani
	NET_GetInterfaces();

	return newsocket;
}
开发者ID:AdrienJaguenet,项目名称:Enemy-Territory,代码行数:64,代码来源:win_net.c

示例6: NET_UDPSocket

/*
 ==================
 NET_UDPSocket
 ==================
*/
static bool NET_UDPSocket (netSrc_t sock, const char *ip, int port){

	struct sockaddr_in	adr;
	ulong				value = 1;

	Com_DPrintf("NET_UDPSocket( %s, %i )\n", ip, port);

	// Open an UDP socket
	if ((net.sockets[sock] = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET){
		Com_DPrintf(S_COLOR_YELLOW "NET_OpenSocket: socket() = %s\n", NET_ErrorString());
		return false;
	}

	// Make it non-blocking
	if (ioctlsocket(net.sockets[sock], FIONBIO, &value) == SOCKET_ERROR){
		Com_DPrintf(S_COLOR_YELLOW "NET_OpenSocket: ioctlsocket() = %s\n", NET_ErrorString());

		closesocket(net.sockets[sock]);
		net.sockets[sock] = INVALID_SOCKET;

		return false;
	}

	// Make it broadcast capable
	if (setsockopt(net.sockets[sock], SOL_SOCKET, SO_BROADCAST, (const char *)&value, sizeof(value)) == SOCKET_ERROR){
		Com_DPrintf(S_COLOR_YELLOW "NET_OpenSocket: setsockopt() = %s\n", NET_ErrorString());

		closesocket(net.sockets[sock]);
		net.sockets[sock] = INVALID_SOCKET;

		return false;
	}

	// Bind it
	adr.sin_family = AF_INET;

	if (!Str_ICompare(ip, "localhost"))
		adr.sin_addr.s_addr = INADDR_ANY;
	else {
		if (!NET_StringToSockAdr(ip, (struct sockaddr *)&adr))
			adr.sin_addr.s_addr = INADDR_ANY;
	}

	if (port == 0)
		adr.sin_port = 0;
	else
		adr.sin_port = htons((ushort)port);

	if (bind(net.sockets[sock], (void *)&adr, sizeof(adr)) == SOCKET_ERROR){
		Com_DPrintf(S_COLOR_YELLOW "NET_OpenSocket: bind() = %s\n", NET_ErrorString());

		closesocket(net.sockets[sock]);
		net.sockets[sock] = INVALID_SOCKET;

		return false;
	}

	return true;
}
开发者ID:Mirrorman95,项目名称:quake-2-evolved,代码行数:64,代码来源:win_network.c

示例7: NET_IPXSocket

int
NET_IPXSocket(int port)
{
	int newsocket;
	struct sockaddr_ipx address;
	unsigned long t = 1;

	if ((newsocket = socket(PF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == -1)
	{
		int err;

		err = WSAGetLastError();

		if (err != WSAEAFNOSUPPORT)
		{
			Com_Printf("WARNING: IPX_Socket: socket: %s\n", NET_ErrorString());
		}

		return 0;
	}

	/* make it non-blocking */
	if (ioctlsocket(newsocket, FIONBIO, &t) == -1)
	{
		Com_Printf("WARNING: IPX_Socket: ioctl FIONBIO: %s\n", NET_ErrorString());
		return 0;
	}

	/* make it broadcast capable */
	if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&t,
				sizeof(t)) == -1)
	{
		Com_Printf("WARNING: IPX_Socket: setsockopt SO_BROADCAST: %s\n",
				NET_ErrorString());
		return 0;
	}

	address.sa_family = AF_IPX;
	memset(address.sa_netnum, 0, 4);
	memset(address.sa_nodenum, 0, 6);

	if (port == PORT_ANY)
	{
		address.sa_socket = 0;
	}
	else
	{
		address.sa_socket = htons((short)port);
	}

	if (bind(newsocket, (void *)&address, sizeof(address)) == -1)
	{
		Com_Printf("WARNING: IPX_Socket: bind: %s\n", NET_ErrorString());
		closesocket(newsocket);
		return 0;
	}

	return newsocket;
}
开发者ID:Pickle,项目名称:yquake2,代码行数:59,代码来源:network.c

示例8: NET_IPSocket

/*
====================
NET_IPSocket
====================
 */
int NET_IPSocket(char *net_interface, int port, int *err) {
    SOCKET newsocket;
    struct sockaddr_in address;
    u_long _true = 1;
    int i = 1;

    *err = 0;

    if (net_interface) {
        Com_Printf("Opening IP socket: %s:%i\n", net_interface, port);
    } else {
        Com_Printf("Opening IP socket: 0.0.0.0:%i\n", port);
    }

    if ((newsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
        *err = socketError;
        Com_Printf("WARNING: NET_IPSocket: socket: %s\n", NET_ErrorString());
        return newsocket;
    }
    // make it non-blocking
    if (ioctlsocket(newsocket, FIONBIO, &_true) == SOCKET_ERROR) {
        Com_Printf("WARNING: NET_IPSocket: ioctl FIONBIO: %s\n", NET_ErrorString());
        *err = socketError;
        closesocket(newsocket);
        return INVALID_SOCKET;
    }

    // make it broadcast capable
    if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *) & i, sizeof (i)) == SOCKET_ERROR) {
        Com_Printf("WARNING: NET_IPSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString());
    }

    if (!net_interface || !net_interface[0]) {
        address.sin_family = AF_INET;
        address.sin_addr.s_addr = INADDR_ANY;
    } else {
        if (!Sys_StringToSockaddr(net_interface, (struct sockaddr *) & address, sizeof (address), AF_INET)) {
            closesocket(newsocket);
            return INVALID_SOCKET;
        }
    }

    if (port == PORT_ANY) {
        address.sin_port = 0;
    } else {
        address.sin_port = htons((short) port);
    }

    if (bind(newsocket, (void *) & address, sizeof (address)) == SOCKET_ERROR) {
        Com_Printf("WARNING: NET_IPSocket: bind: %s\n", NET_ErrorString());
        *err = socketError;
        closesocket(newsocket);
        return INVALID_SOCKET;
    }

    return newsocket;
}
开发者ID:zturtleman,项目名称:q3rain,代码行数:62,代码来源:net_ip.c

示例9: NET_IPSocket

SOCKET NET_IPSocket( const char *net_interface, int port ) {
	SOCKET				newsocket;
	struct sockaddr_in	address;
	u_long			    _true = 1;
	int					i = 1;

	if( !net_interface || !net_interface[0] ) {
		net_interface = "localhost";
	}

	Com_Printf( "Opening IP socket: %s:%i\n", net_interface, port );

	if( ( newsocket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) == INVALID_SOCKET ) {
#ifdef _WIN32
		if( WSAGetLastError() != WSAEAFNOSUPPORT )
#endif
			Com_Printf ("WARNING: UDP_OpenSocket: socket: %s", NET_ErrorString() );
		return INVALID_SOCKET;
	}

	// make it non-blocking
	if( ioctlsocket( newsocket, FIONBIO, &_true ) == SOCKET_ERROR ) {
		Com_Printf ("WARNING: UDP_OpenSocket: ioctl FIONBIO: %s\n", NET_ErrorString() );
		closesocket( newsocket );
		return INVALID_SOCKET;
	}

	// make it broadcast capable
	if( setsockopt( newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof( i ) ) == SOCKET_ERROR ) {
		Com_Printf ("WARNING: UDP_OpenSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString() );
		closesocket( newsocket );
		return INVALID_SOCKET;
	}

	if( !Q_stricmp( net_interface, "localhost" ) ) {
		address.sin_addr.s_addr = INADDR_ANY;
	} else {
		NET_StringToSockaddr( net_interface, (struct sockaddr *)&address );
	}

	if( port == PORT_ANY ) {
		address.sin_port = 0;
	} else {
		address.sin_port = htons( (u_short)port );
	}

	address.sin_family = AF_INET;

	if( bind( newsocket, (void *)&address, sizeof( address ) ) == SOCKET_ERROR ) {
		Com_Printf ("WARNING: UDP_OpenSocket: bind: %s\n", NET_ErrorString() );
		closesocket( newsocket );
		return INVALID_SOCKET;
	}

	return newsocket;
}
开发者ID:chrisnew,项目名称:quake2,代码行数:56,代码来源:net.c

示例10: NET_IPXSocket

/*
====================
NET_IPXSocket
====================
*/
int NET_IPXSocket(int port)
{
	SOCKET          newsocket;
	struct sockaddr_ipx address;

//bani - was improper parameter
	unsigned long   _true = qtrue;
	int             err;

	if((newsocket = socket(AF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == INVALID_SOCKET)
	{
		err = WSAGetLastError();
		if(err != WSAEAFNOSUPPORT)
		{
			Com_Printf("WARNING: IPX_Socket: socket: %s\n", NET_ErrorString());
		}
		return 0;
	}

	// make it non-blocking
	if(ioctlsocket(newsocket, FIONBIO, &_true) == SOCKET_ERROR)
	{
		Com_Printf("WARNING: IPX_Socket: ioctl FIONBIO: %s\n", NET_ErrorString());
		return 0;
	}

	// make it broadcast capable
	if(setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof(_true)) == SOCKET_ERROR)
	{
		Com_Printf("WARNING: IPX_Socket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString());
		return 0;
	}

	address.sa_family = AF_IPX;
	memset(address.sa_netnum, 0, 4);
	memset(address.sa_nodenum, 0, 6);
	if(port == PORT_ANY)
	{
		address.sa_socket = 0;
	}
	else
	{
		address.sa_socket = htons((short)port);
	}

	if(bind(newsocket, (void *)&address, sizeof(address)) == SOCKET_ERROR)
	{
		Com_Printf("WARNING: IPX_Socket: bind: %s\n", NET_ErrorString());
		closesocket(newsocket);
		return 0;
	}

	return newsocket;
}
开发者ID:ethr,项目名称:ETXrealPro,代码行数:59,代码来源:win_net.c

示例11: SV_SendClientMessages

/*
* SV_SendClientMessages
*/
void SV_SendClientMessages( void )
{
	int i;
	client_t *client;

	// send a message to each connected client
	for( i = 0, client = svs.clients; i < sv_maxclients->integer; i++, client++ )
	{
		if( client->state == CS_FREE || client->state == CS_ZOMBIE )
			continue;

		if( client->edict && ( client->edict->r.svflags & SVF_FAKECLIENT ) )
		{
			client->lastSentFrameNum = sv.framenum;
			continue;
		}

		if( !client->tvclient ) {
			SV_UpdateActivity();
		}

		if( client->state == CS_SPAWNED )
		{
			if( !SV_SendClientDatagram( client ) )
			{
				Com_Printf( "Error sending message to %s: %s\n", client->name, NET_ErrorString() );
				if( client->reliable )
				{
					SV_DropClient( client, DROP_TYPE_GENERAL, "Error sending message: %s\n", NET_ErrorString() );
				}
			}
		}
		else
		{
			// send pending reliable commands, or send heartbeats for not timing out
			if( client->reliableSequence > client->reliableAcknowledge ||
				svs.realtime - client->lastPacketSentTime > 1000 )
			{
				SV_InitClientMessage( client, &tmpMessage, NULL, 0 );
				SV_AddReliableCommandsToMessage( client, &tmpMessage );
				if( !SV_SendMessageToClient( client, &tmpMessage ) )
				{
					Com_Printf( "Error sending message to %s: %s\n", client->name, NET_ErrorString() );
					if( client->reliable )
					{
						SV_DropClient( client, DROP_TYPE_GENERAL, "Error sending message: %s\n", NET_ErrorString() );
					}
				}
			}
		}
	}
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:55,代码来源:sv_send.c

示例12: Net_NetadrToSockadr

/*
==================
idTCP::Init
==================
*/
bool idTCP::Init( const char *host, short port )
{
    unsigned long	_true = 1;
    struct sockaddr sadr;

    if ( !Sys_StringToNetAdr( host, &address, true ) )
    {
        common->Printf( "Couldn't resolve server name \"%s\"\n", host );
        return false;
    }
    address.type = NA_IP;
    if ( !address.port )
    {
        address.port = port;
    }
    common->Printf( "\"%s\" resolved to %i.%i.%i.%i:%i\n", host,
                    address.ip[0], address.ip[1], address.ip[2], address.ip[3], address.port );
    Net_NetadrToSockadr( &address, &sadr );

    if ( fd )
    {
        common->Warning( "idTCP::Init: already initialized?" );
    }

    if ( ( fd = socket( AF_INET, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
    {
        fd = 0;
        common->Printf( "ERROR: idTCP::Init: socket: %s\n", NET_ErrorString() );
        return false;
    }

    if ( connect( fd, &sadr, sizeof(sadr)) == SOCKET_ERROR )
    {
        common->Printf( "ERROR: idTCP::Init: connect: %s\n", NET_ErrorString() );
        closesocket( fd );
        fd = 0;
        return false;
    }

    // make it non-blocking
    if( ioctlsocket( fd, FIONBIO, &_true ) == SOCKET_ERROR )
    {
        common->Printf( "ERROR: idTCP::Init: ioctl FIONBIO: %s\n", NET_ErrorString() );
        closesocket( fd );
        fd = 0;
        return false;
    }

    common->DPrintf( "Opened TCP connection\n" );
    return true;
}
开发者ID:revelator,项目名称:Revelator-Doom3,代码行数:56,代码来源:win_net.cpp

示例13: NET_JoinMulticast6

/*
====================
NET_JoinMulticast
Join an ipv6 multicast group
====================
*/
void NET_JoinMulticast6(void)
{
	int err;

	if (ip6_socket == INVALID_SOCKET || multicast6_socket != INVALID_SOCKET || (net_enabled->integer & NET_DISABLEMCAST))
	{
		return;
	}

	if (IN6_IS_ADDR_MULTICAST(&boundto.sin6_addr) || IN6_IS_ADDR_UNSPECIFIED(&boundto.sin6_addr))
	{
		// The way the socket was bound does not prohibit receiving multi-cast packets. So we don't need to open a new one.
		multicast6_socket = ip6_socket;
	}
	else
	{
		if ((multicast6_socket = NET_IP6Socket(net_mcast6addr->string, ntohs(boundto.sin6_port), NULL, &err)) == INVALID_SOCKET)
		{
			// If the OS does not support binding to multicast addresses, like WinXP, at least try with the normal file descriptor.
			multicast6_socket = ip6_socket;
		}
	}

	if (curgroup.ipv6mr_interface)
	{
		if (setsockopt(multicast6_socket, IPPROTO_IPV6, IPV6_MULTICAST_IF,
		               (char *) &curgroup.ipv6mr_interface, sizeof(curgroup.ipv6mr_interface)) < 0)
		{
			Com_Printf("NET_JoinMulticast6: Couldn't set scope on multicast socket: %s\n", NET_ErrorString());

			if (multicast6_socket != ip6_socket)
			{
				closesocket(multicast6_socket);
				multicast6_socket = INVALID_SOCKET;
				return;
			}
		}
	}

	if (setsockopt(multicast6_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *) &curgroup, sizeof(curgroup)))
	{
		Com_Printf("NET_JoinMulticast6: Couldn't join multicast group: %s\n", NET_ErrorString());

		if (multicast6_socket != ip6_socket)
		{
			closesocket(multicast6_socket);
			multicast6_socket = INVALID_SOCKET;
			return;
		}
	}
}
开发者ID:BulldogDrummond,项目名称:etlegacy-mysql,代码行数:57,代码来源:net_ip.c

示例14: NET_IPSocket

/*
====================
NET_Socket
====================
*/
int NET_IPSocket (char *net_interface, int port)
{
	int					newsocket;
	struct sockaddr_in	address;
	u_long				_true = true;
	int					i = 1;
	int					err;

	if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
	{
		err = WSAGetLastError();
		if (err != WSAEAFNOSUPPORT)
			Com_Printf ("WARNING: UDP_OpenSocket: socket: %s", NET_ErrorString());
		return 0;
	}

	// make it non-blocking
	if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
	{
		Com_Printf ("WARNING: UDP_OpenSocket: ioctl FIONBIO: %s\n", NET_ErrorString());
		return 0;
	}

	// make it broadcast capable
	if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
	{
		Com_Printf ("WARNING: UDP_OpenSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString());
		return 0;
	}

	if (!net_interface || !net_interface[0] || !_stricmp(net_interface, "localhost"))
		address.sin_addr.s_addr = INADDR_ANY;
	else
		NET_StringToSockaddr (net_interface, (struct sockaddr *)&address);

	if (port == PORT_ANY)
		address.sin_port = 0;
	else
		address.sin_port = htons((short)port);

	address.sin_family = AF_INET;

	if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
	{
		Com_Printf ("WARNING: UDP_OpenSocket: bind: %s\n", NET_ErrorString());
		closesocket (newsocket);
		return 0;
	}

	return newsocket;
}
开发者ID:petmac,项目名称:quake2-lite,代码行数:56,代码来源:net_wins.c

示例15: NET_IPXSocket

/*
====================
NET_IPXSocket
====================
*/
int NET_IPXSocket( int port )
{
#ifdef _XBOX
    assert(!"NET_IPXSocket() - Not supported");
    return INVALID_SOCKET;
#else
    SOCKET				newsocket;

    struct sockaddr_ipx	address;
    int					_true = 1;
    int					err;

    if( ( newsocket = socket( AF_IPX, SOCK_DGRAM, NSPROTO_IPX ) ) == INVALID_SOCKET ) {
        err = WSAGetLastError();
        if (err != WSAEAFNOSUPPORT) {
            Com_Printf( "WARNING: IPX_Socket: socket: %s\n", NET_ErrorString() );
        }
        return INVALID_SOCKET;
    }

    // make it non-blocking
    if( ioctlsocket( newsocket, FIONBIO, (unsigned long *)&_true ) == SOCKET_ERROR ) {
        Com_Printf( "WARNING: IPX_Socket: ioctl FIONBIO: %s\n", NET_ErrorString() );
        return INVALID_SOCKET;
    }

    // make it broadcast capable
    if( setsockopt( newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof( _true ) ) == SOCKET_ERROR ) {
        Com_Printf( "WARNING: IPX_Socket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString() );
        return INVALID_SOCKET;
    }

    address.sa_family = AF_IPX;
    memset( address.sa_netnum, 0, 4 );
    memset( address.sa_nodenum, 0, 6 );
    if( port == PORT_ANY ) {
        address.sa_socket = 0;
    }
    else {
        address.sa_socket = htons( (short)port );
    }

    if( bind( newsocket, (const struct sockaddr *)&address, sizeof(address) ) == SOCKET_ERROR ) {
        Com_Printf( "WARNING: IPX_Socket: bind: %s\n", NET_ErrorString() );
        closesocket( newsocket );
        return INVALID_SOCKET;
    }
    return newsocket;
#endif
}
开发者ID:Drakesinger,项目名称:jediacademypc,代码行数:55,代码来源:win_net.cpp


注:本文中的NET_ErrorString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。