25 #include "../qcommon/qcommon.h"
27 #define MAX_LOOPBACK 4
56 memset (
s, 0,
sizeof(*
s));
60 ((
struct sockaddr_in *)
s)->sin_family = AF_INET;
61 ((
struct sockaddr_in *)
s)->sin_port = a->
port;
62 ((
struct sockaddr_in *)
s)->sin_addr.s_addr = INADDR_BROADCAST;
66 ((
struct sockaddr_in *)
s)->sin_family = AF_INET;
67 ((
struct sockaddr_in *)
s)->sin_addr.s_addr = *(
int *)&a->
ip;
68 ((
struct sockaddr_in *)
s)->sin_port = a->
port;
72 ((
struct sockaddr_ipx *)
s)->sa_family = AF_IPX;
73 memcpy(((
struct sockaddr_ipx *)
s)->sa_netnum, &a->
ipx[0], 4);
74 memcpy(((
struct sockaddr_ipx *)
s)->sa_nodenum, &a->
ipx[4], 6);
75 ((
struct sockaddr_ipx *)
s)->sa_socket = a->
port;
79 ((
struct sockaddr_ipx *)
s)->sa_family = AF_IPX;
80 memset(((
struct sockaddr_ipx *)
s)->sa_netnum, 0, 4);
81 memset(((
struct sockaddr_ipx *)
s)->sa_nodenum, 0xff, 6);
82 ((
struct sockaddr_ipx *)
s)->sa_socket = a->
port;
88 if (
s->sa_family == AF_INET)
91 *(
int *)&a->
ip = ((
struct sockaddr_in *)
s)->sin_addr.s_addr;
92 a->
port = ((
struct sockaddr_in *)
s)->sin_port;
94 else if (
s->sa_family == AF_IPX)
97 memcpy(&a->
ipx[0], ((
struct sockaddr_ipx *)
s)->sa_netnum, 4);
98 memcpy(&a->
ipx[4], ((
struct sockaddr_ipx *)
s)->sa_nodenum, 6);
99 a->
port = ((
struct sockaddr_ipx *)
s)->sa_socket;
146 if (a.
ip[0] == b.
ip[0] && a.
ip[1] == b.
ip[1] && a.
ip[2] == b.
ip[2] && a.
ip[3] == b.
ip[3])
153 if ((memcmp(a.
ipx, b.
ipx, 10) == 0))
170 Com_sprintf (
s,
sizeof(
s),
"%02x%02x%02x%02x:%02x%02x%02x%02x%02x%02x:%i", a.
ipx[0], a.
ipx[1], a.
ipx[2], a.
ipx[3], a.
ipx[4], a.
ipx[5], a.
ipx[6], a.
ipx[7], a.
ipx[8], a.
ipx[9], ntohs(a.
port));
187 #define DO(src,dest) \
189 copy[1] = s[src + 1]; \
190 sscanf (copy, "%x", &val); \
191 ((struct sockaddr_ipx *)sadr)->dest = val
200 memset (sadr, 0,
sizeof(*sadr));
202 if ((strlen(
s) >= 23) && (
s[8] ==
':') && (
s[21] ==
':'))
204 ((
struct sockaddr_ipx *)sadr)->sa_family = AF_IPX;
210 DO(9, sa_nodenum[0]);
211 DO(11, sa_nodenum[1]);
212 DO(13, sa_nodenum[2]);
213 DO(15, sa_nodenum[3]);
214 DO(17, sa_nodenum[4]);
215 DO(19, sa_nodenum[5]);
216 sscanf (&
s[22],
"%u", &val);
217 ((
struct sockaddr_ipx *)sadr)->sa_socket = htons((
unsigned short)val);
221 ((
struct sockaddr_in *)sadr)->sin_family = AF_INET;
223 ((
struct sockaddr_in *)sadr)->sin_port = 0;
227 for (colon = copy ; *colon ; colon++)
231 ((
struct sockaddr_in *)sadr)->sin_port = htons((
short)atoi(colon+1));
234 if (copy[0] >=
'0' && copy[0] <=
'9')
236 *(
int *)&((
struct sockaddr_in *)sadr)->sin_addr = inet_addr(copy);
240 if (! (h = gethostbyname(copy)) )
242 *(
int *)&((
struct sockaddr_in *)sadr)->sin_addr = *(
int *)h->h_addr_list[0];
264 struct sockaddr sadr;
266 if (!strcmp (
s,
"localhost"))
268 memset (a, 0,
sizeof(*a));
330 memcpy (loop->
msgs[
i].
data, data, length);
339 struct sockaddr from;
348 for (protocol = 0 ; protocol < 2 ; protocol++)
358 fromlen =
sizeof(from);
360 , 0, (
struct sockaddr *)&from, &fromlen);
366 err = WSAGetLastError();
368 if (err == WSAEWOULDBLOCK)
370 if (err == WSAEMSGSIZE) {
371 Com_Printf (
"Warning: Oversize packet from %s\n",
403 struct sockaddr addr;
441 ret = sendto (net_socket, data, length, 0, &addr,
sizeof(addr) );
444 int err = WSAGetLastError();
447 if (err == WSAEWOULDBLOCK)
461 if (err == WSAEADDRNOTAVAIL)
487 struct sockaddr_in address;
492 if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
494 err = WSAGetLastError();
495 if (err != WSAEAFNOSUPPORT)
501 if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
508 if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (
char *)&
i,
sizeof(
i)) == -1)
514 if (!net_interface || !net_interface[0] || !stricmp(net_interface,
"localhost"))
515 address.sin_addr.s_addr = INADDR_ANY;
520 address.sin_port = 0;
522 address.sin_port = htons((
short)port);
524 address.sin_family = AF_INET;
526 if( bind (newsocket, (
void *)&address,
sizeof(address)) == -1)
529 closesocket (newsocket);
597 struct sockaddr_ipx address;
601 if ((newsocket = socket (PF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == -1)
603 err = WSAGetLastError();
604 if (err != WSAEAFNOSUPPORT)
610 if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
617 if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (
char *)&_true,
sizeof(_true)) == -1)
623 address.sa_family = AF_IPX;
624 memset (address.sa_netnum, 0, 4);
625 memset (address.sa_nodenum, 0, 6);
627 address.sa_socket = 0;
629 address.sa_socket = htons((
short)port);
631 if( bind (newsocket, (
void *)&address,
sizeof(address)) == -1)
634 closesocket (newsocket);
700 if (old_config == multiplayer)
703 old_config = multiplayer;
707 for (
i=0 ;
i<2 ;
i++)
733 struct timeval timeout;
752 timeout.tv_sec = msec/1000;
753 timeout.tv_usec = (msec%1000)*1000;
754 select(
i+1, &fdset,
NULL,
NULL, &timeout);
769 WORD wVersionRequested;
772 wVersionRequested = MAKEWORD(1, 1);
810 code = WSAGetLastError ();
813 case WSAEINTR:
return "WSAEINTR";
814 case WSAEBADF:
return "WSAEBADF";
815 case WSAEACCES:
return "WSAEACCES";
816 case WSAEDISCON:
return "WSAEDISCON";
817 case WSAEFAULT:
return "WSAEFAULT";
818 case WSAEINVAL:
return "WSAEINVAL";
819 case WSAEMFILE:
return "WSAEMFILE";
820 case WSAEWOULDBLOCK:
return "WSAEWOULDBLOCK";
821 case WSAEINPROGRESS:
return "WSAEINPROGRESS";
822 case WSAEALREADY:
return "WSAEALREADY";
823 case WSAENOTSOCK:
return "WSAENOTSOCK";
824 case WSAEDESTADDRREQ:
return "WSAEDESTADDRREQ";
825 case WSAEMSGSIZE:
return "WSAEMSGSIZE";
826 case WSAEPROTOTYPE:
return "WSAEPROTOTYPE";
827 case WSAENOPROTOOPT:
return "WSAENOPROTOOPT";
828 case WSAEPROTONOSUPPORT:
return "WSAEPROTONOSUPPORT";
829 case WSAESOCKTNOSUPPORT:
return "WSAESOCKTNOSUPPORT";
830 case WSAEOPNOTSUPP:
return "WSAEOPNOTSUPP";
831 case WSAEPFNOSUPPORT:
return "WSAEPFNOSUPPORT";
832 case WSAEAFNOSUPPORT:
return "WSAEAFNOSUPPORT";
833 case WSAEADDRINUSE:
return "WSAEADDRINUSE";
834 case WSAEADDRNOTAVAIL:
return "WSAEADDRNOTAVAIL";
835 case WSAENETDOWN:
return "WSAENETDOWN";
836 case WSAENETUNREACH:
return "WSAENETUNREACH";
837 case WSAENETRESET:
return "WSAENETRESET";
838 case WSAECONNABORTED:
return "WSWSAECONNABORTEDAEINTR";
839 case WSAECONNRESET:
return "WSAECONNRESET";
840 case WSAENOBUFS:
return "WSAENOBUFS";
841 case WSAEISCONN:
return "WSAEISCONN";
842 case WSAENOTCONN:
return "WSAENOTCONN";
843 case WSAESHUTDOWN:
return "WSAESHUTDOWN";
844 case WSAETOOMANYREFS:
return "WSAETOOMANYREFS";
845 case WSAETIMEDOUT:
return "WSAETIMEDOUT";
846 case WSAECONNREFUSED:
return "WSAECONNREFUSED";
847 case WSAELOOP:
return "WSAELOOP";
848 case WSAENAMETOOLONG:
return "WSAENAMETOOLONG";
849 case WSAEHOSTDOWN:
return "WSAEHOSTDOWN";
850 case WSASYSNOTREADY:
return "WSASYSNOTREADY";
851 case WSAVERNOTSUPPORTED:
return "WSAVERNOTSUPPORTED";
852 case WSANOTINITIALISED:
return "WSANOTINITIALISED";
853 case WSAHOST_NOT_FOUND:
return "WSAHOST_NOT_FOUND";
854 case WSATRY_AGAIN:
return "WSATRY_AGAIN";
855 case WSANO_RECOVERY:
return "WSANO_RECOVERY";
856 case WSANO_DATA:
return "WSANO_DATA";
857 default:
return "NO ERROR";