24 #include "../qcommon/qcommon.h"
26 #define MAX_LOOPBACK 4
55 memset (s, 0,
sizeof(*s));
59 ((
struct sockaddr_in *)s)->sin_family = AF_INET;
60 ((
struct sockaddr_in *)s)->sin_port = a->
port;
61 ((
struct sockaddr_in *)s)->sin_addr.s_addr = INADDR_BROADCAST;
65 ((
struct sockaddr_in *)s)->sin_family = AF_INET;
66 ((
struct sockaddr_in *)s)->sin_addr.s_addr = *(
int *)&a->
ip;
67 ((
struct sockaddr_in *)s)->sin_port = a->
port;
71 ((
struct sockaddr_ipx *)s)->sa_family = AF_IPX;
72 memcpy(((
struct sockaddr_ipx *)s)->sa_netnum, &a->
ipx[0], 4);
73 memcpy(((
struct sockaddr_ipx *)s)->sa_nodenum, &a->
ipx[4], 6);
74 ((
struct sockaddr_ipx *)s)->sa_socket = a->
port;
78 ((
struct sockaddr_ipx *)s)->sa_family = AF_IPX;
79 memset(((
struct sockaddr_ipx *)s)->sa_netnum, 0, 4);
80 memset(((
struct sockaddr_ipx *)s)->sa_nodenum, 0xff, 6);
81 ((
struct sockaddr_ipx *)s)->sa_socket = a->
port;
87 if (s->sa_family == AF_INET)
90 *(
int *)&a->
ip = ((
struct sockaddr_in *)s)->sin_addr.s_addr;
91 a->
port = ((
struct sockaddr_in *)s)->sin_port;
93 else if (s->sa_family == AF_IPX)
96 memcpy(&a->
ipx[0], ((
struct sockaddr_ipx *)s)->sa_netnum, 4);
97 memcpy(&a->
ipx[4], ((
struct sockaddr_ipx *)s)->sa_nodenum, 6);
98 a->
port = ((
struct sockaddr_ipx *)s)->sa_socket;
143 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])
150 if ((memcmp(a.
ipx, b.
ipx, 10) == 0))
165 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));
182 #define DO(src,dest) \
184 copy[1] = s[src + 1]; \
185 sscanf (copy, "%x", &val); \
186 ((struct sockaddr_ipx *)sadr)->dest = val
195 memset (sadr, 0,
sizeof(*sadr));
197 if ((strlen(s) >= 23) && (s[8] ==
':') && (s[21] ==
':'))
199 ((
struct sockaddr_ipx *)sadr)->sa_family = AF_IPX;
205 DO(9, sa_nodenum[0]);
206 DO(11, sa_nodenum[1]);
207 DO(13, sa_nodenum[2]);
208 DO(15, sa_nodenum[3]);
209 DO(17, sa_nodenum[4]);
210 DO(19, sa_nodenum[5]);
211 sscanf (&s[22],
"%u", &val);
212 ((
struct sockaddr_ipx *)sadr)->sa_socket = htons((
unsigned short)val);
216 ((
struct sockaddr_in *)sadr)->sin_family = AF_INET;
218 ((
struct sockaddr_in *)sadr)->sin_port = 0;
222 for (colon = copy ; *colon ; colon++)
226 ((
struct sockaddr_in *)sadr)->sin_port = htons((
short)atoi(colon+1));
229 if (copy[0] >=
'0' && copy[0] <=
'9')
231 *(
int *)&((
struct sockaddr_in *)sadr)->sin_addr = inet_addr(copy);
235 if (! (h = gethostbyname(copy)) )
237 *(
int *)&((
struct sockaddr_in *)sadr)->sin_addr = *(
int *)h->h_addr_list[0];
259 struct sockaddr sadr;
261 if (!strcmp (s,
"localhost"))
263 memset (a, 0,
sizeof(*a));
325 memcpy (loop->
msgs[
i].
data, data, length);
334 struct sockaddr from;
343 for (protocol = 0 ; protocol < 2 ; protocol++)
353 fromlen =
sizeof(from);
355 , 0, (
struct sockaddr *)&from, &fromlen);
361 err = WSAGetLastError();
363 if (err == WSAEWOULDBLOCK)
365 if (err == WSAEMSGSIZE) {
366 Com_Printf (
"Warning: Oversize packet from %s\n",
398 struct sockaddr addr;
436 ret = sendto (net_socket, data, length, 0, &addr,
sizeof(addr) );
439 int err = WSAGetLastError();
442 if (err == WSAEWOULDBLOCK)
456 if (err == WSAEADDRNOTAVAIL)
482 struct sockaddr_in address;
487 if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
489 err = WSAGetLastError();
490 if (err != WSAEAFNOSUPPORT)
496 if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
503 if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (
char *)&
i,
sizeof(
i)) == -1)
509 if (!net_interface || !net_interface[0] || !stricmp(net_interface,
"localhost"))
510 address.sin_addr.s_addr = INADDR_ANY;
515 address.sin_port = 0;
517 address.sin_port = htons((
short)port);
519 address.sin_family = AF_INET;
521 if( bind (newsocket, (
void *)&address,
sizeof(address)) == -1)
524 closesocket (newsocket);
592 struct sockaddr_ipx address;
596 if ((newsocket = socket (PF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == -1)
598 err = WSAGetLastError();
599 if (err != WSAEAFNOSUPPORT)
605 if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
612 if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (
char *)&_true,
sizeof(_true)) == -1)
618 address.sa_family = AF_IPX;
619 memset (address.sa_netnum, 0, 4);
620 memset (address.sa_nodenum, 0, 6);
622 address.sa_socket = 0;
624 address.sa_socket = htons((
short)port);
626 if( bind (newsocket, (
void *)&address,
sizeof(address)) == -1)
629 closesocket (newsocket);
695 if (old_config == multiplayer)
698 old_config = multiplayer;
702 for (
i=0 ;
i<2 ;
i++)
748 timeout.tv_usec = (msec%1000)*1000;
764 WORD wVersionRequested;
767 wVersionRequested = MAKEWORD(1, 1);
805 code = WSAGetLastError ();
808 case WSAEINTR:
return "WSAEINTR";
809 case WSAEBADF:
return "WSAEBADF";
810 case WSAEACCES:
return "WSAEACCES";
811 case WSAEDISCON:
return "WSAEDISCON";
812 case WSAEFAULT:
return "WSAEFAULT";
813 case WSAEINVAL:
return "WSAEINVAL";
814 case WSAEMFILE:
return "WSAEMFILE";
815 case WSAEWOULDBLOCK:
return "WSAEWOULDBLOCK";
816 case WSAEINPROGRESS:
return "WSAEINPROGRESS";
817 case WSAEALREADY:
return "WSAEALREADY";
818 case WSAENOTSOCK:
return "WSAENOTSOCK";
819 case WSAEDESTADDRREQ:
return "WSAEDESTADDRREQ";
820 case WSAEMSGSIZE:
return "WSAEMSGSIZE";
821 case WSAEPROTOTYPE:
return "WSAEPROTOTYPE";
822 case WSAENOPROTOOPT:
return "WSAENOPROTOOPT";
823 case WSAEPROTONOSUPPORT:
return "WSAEPROTONOSUPPORT";
824 case WSAESOCKTNOSUPPORT:
return "WSAESOCKTNOSUPPORT";
825 case WSAEOPNOTSUPP:
return "WSAEOPNOTSUPP";
826 case WSAEPFNOSUPPORT:
return "WSAEPFNOSUPPORT";
827 case WSAEAFNOSUPPORT:
return "WSAEAFNOSUPPORT";
828 case WSAEADDRINUSE:
return "WSAEADDRINUSE";
829 case WSAEADDRNOTAVAIL:
return "WSAEADDRNOTAVAIL";
830 case WSAENETDOWN:
return "WSAENETDOWN";
831 case WSAENETUNREACH:
return "WSAENETUNREACH";
832 case WSAENETRESET:
return "WSAENETRESET";
833 case WSAECONNABORTED:
return "WSWSAECONNABORTEDAEINTR";
834 case WSAECONNRESET:
return "WSAECONNRESET";
835 case WSAENOBUFS:
return "WSAENOBUFS";
836 case WSAEISCONN:
return "WSAEISCONN";
837 case WSAENOTCONN:
return "WSAENOTCONN";
838 case WSAESHUTDOWN:
return "WSAESHUTDOWN";
839 case WSAETOOMANYREFS:
return "WSAETOOMANYREFS";
840 case WSAETIMEDOUT:
return "WSAETIMEDOUT";
841 case WSAECONNREFUSED:
return "WSAECONNREFUSED";
842 case WSAELOOP:
return "WSAELOOP";
843 case WSAENAMETOOLONG:
return "WSAENAMETOOLONG";
844 case WSAEHOSTDOWN:
return "WSAEHOSTDOWN";
845 case WSASYSNOTREADY:
return "WSASYSNOTREADY";
846 case WSAVERNOTSUPPORTED:
return "WSAVERNOTSUPPORTED";
847 case WSANOTINITIALISED:
return "WSANOTINITIALISED";
848 case WSAHOST_NOT_FOUND:
return "WSAHOST_NOT_FOUND";
849 case WSATRY_AGAIN:
return "WSATRY_AGAIN";
850 case WSANO_RECOVERY:
return "WSANO_RECOVERY";
851 case WSANO_DATA:
return "WSANO_DATA";
852 default:
return "NO ERROR";