vkQuake2 doxygen  1.0 dev
net_wins.c File Reference
#include "winsock.h"
#include "wsipx.h"
#include "../qcommon/qcommon.h"

Go to the source code of this file.

Classes

struct  loopmsg_t
 
struct  loopback_t
 

Macros

#define MAX_LOOPBACK   4
 
#define DO(src, dest)
 

Functions

char * NET_ErrorString (void)
 
void NetadrToSockadr (netadr_t *a, struct sockaddr *s)
 
void SockadrToNetadr (struct sockaddr *s, netadr_t *a)
 
qboolean NET_CompareAdr (netadr_t a, netadr_t b)
 
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
 
char * NET_AdrToString (netadr_t a)
 
qboolean NET_StringToSockaddr (char *s, struct sockaddr *sadr)
 
qboolean NET_StringToAdr (char *s, netadr_t *a)
 
qboolean NET_IsLocalAddress (netadr_t adr)
 
qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
 
void NET_SendLoopPacket (netsrc_t sock, int length, void *data, netadr_t to)
 
qboolean NET_GetPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
 
void NET_SendPacket (netsrc_t sock, int length, void *data, netadr_t to)
 
int NET_IPSocket (char *net_interface, int port)
 
void NET_OpenIP (void)
 
int NET_IPXSocket (int port)
 
void NET_OpenIPX (void)
 
void NET_Config (qboolean multiplayer)
 
void NET_Sleep (int msec)
 
void NET_Init (void)
 
void NET_Shutdown (void)
 

Variables

cvar_tnet_shownet
 
static cvar_tnoudp
 
static cvar_tnoipx
 
loopback_t loopbacks [2]
 
int ip_sockets [2]
 
int ipx_sockets [2]
 
static WSADATA winsockdata
 

Macro Definition Documentation

◆ DO

#define DO (   src,
  dest 
)
Value:
copy[0] = s[src]; \
copy[1] = s[src + 1]; \
sscanf (copy, "%x", &val); \
((struct sockaddr_ipx *)sadr)->dest = val

Definition at line 187 of file net_wins.c.

◆ MAX_LOOPBACK

#define MAX_LOOPBACK   4

Definition at line 27 of file net_wins.c.

Function Documentation

◆ NET_AdrToString()

char* NET_AdrToString ( netadr_t  a)

Definition at line 161 of file net_wins.c.

162 {
163  static char s[64];
164 
165  if (a.type == NA_LOOPBACK)
166  Com_sprintf (s, sizeof(s), "loopback");
167  else if (a.type == NA_IP)
168  Com_sprintf (s, sizeof(s), "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs(a.port));
169  else
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));
171 
172  return s;
173 }

Referenced by CL_ConnectionlessPacket(), CL_ReadPackets(), JoinServerFunc(), Master_Heartbeat(), Master_Shutdown(), NET_GetPacket(), NET_SendPacket(), Netchan_Process(), Netchan_Transmit(), SV_ConnectionlessPacket(), SV_SetMaster_f(), SV_Status_f(), SVC_Ack(), SVC_DirectConnect(), and SVC_RemoteCommand().

◆ NET_CompareAdr()

qboolean NET_CompareAdr ( netadr_t  a,
netadr_t  b 
)

Definition at line 104 of file net_wins.c.

105 {
106  if (a.type != b.type)
107  return false;
108 
109  if (a.type == NA_LOOPBACK)
110  return TRUE;
111 
112  if (a.type == NA_IP)
113  {
114  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] && a.port == b.port)
115  return true;
116  return false;
117  }
118 
119  if (a.type == NA_IPX)
120  {
121  if ((memcmp(a.ipx, b.ipx, 10) == 0) && a.port == b.port)
122  return true;
123  return false;
124  }
125 
126  return TRUE;
127 }

Referenced by CL_ReadPackets().

◆ NET_CompareBaseAdr()

qboolean NET_CompareBaseAdr ( netadr_t  a,
netadr_t  b 
)

Definition at line 136 of file net_wins.c.

137 {
138  if (a.type != b.type)
139  return false;
140 
141  if (a.type == NA_LOOPBACK)
142  return TRUE;
143 
144  if (a.type == NA_IP)
145  {
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])
147  return true;
148  return false;
149  }
150 
151  if (a.type == NA_IPX)
152  {
153  if ((memcmp(a.ipx, b.ipx, 10) == 0))
154  return true;
155  return false;
156  }
157 
158  return TRUE;
159 }

Referenced by SV_ReadPackets(), SVC_DirectConnect(), and SVC_GetChallenge().

◆ NET_Config()

void NET_Config ( qboolean  multiplayer)

Definition at line 695 of file net_wins.c.

696 {
697  int i;
698  static qboolean old_config;
699 
700  if (old_config == multiplayer)
701  return;
702 
703  old_config = multiplayer;
704 
705  if (!multiplayer)
706  { // shut down any existing sockets
707  for (i=0 ; i<2 ; i++)
708  {
709  if (ip_sockets[i])
710  {
711  closesocket (ip_sockets[i]);
712  ip_sockets[i] = 0;
713  }
714  if (ipx_sockets[i])
715  {
716  closesocket (ipx_sockets[i]);
717  ipx_sockets[i] = 0;
718  }
719  }
720  }
721  else
722  { // open sockets
723  if (! noudp->value)
724  NET_OpenIP ();
725  if (! noipx->value)
726  NET_OpenIPX ();
727  }
728 }

Referenced by CL_Connect_f(), CL_Packet_f(), CL_PingServers_f(), CL_Rcon_f(), NET_Shutdown(), SV_InitGame(), and SV_KillServer_f().

◆ NET_ErrorString()

char * NET_ErrorString ( void  )

Definition at line 806 of file net_wins.c.

807 {
808  int code;
809 
810  code = WSAGetLastError ();
811  switch (code)
812  {
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";
858  }
859 }

Referenced by NET_GetPacket(), NET_IPSocket(), NET_IPXSocket(), and NET_SendPacket().

◆ NET_GetLoopPacket()

qboolean NET_GetLoopPacket ( netsrc_t  sock,
netadr_t net_from,
sizebuf_t net_message 
)

Definition at line 295 of file net_wins.c.

296 {
297  int i;
298  loopback_t *loop;
299 
300  loop = &loopbacks[sock];
301 
302  if (loop->send - loop->get > MAX_LOOPBACK)
303  loop->get = loop->send - MAX_LOOPBACK;
304 
305  if (loop->get >= loop->send)
306  return false;
307 
308  i = loop->get & (MAX_LOOPBACK-1);
309  loop->get++;
310 
311  memcpy (net_message->data, loop->msgs[i].data, loop->msgs[i].datalen);
312  net_message->cursize = loop->msgs[i].datalen;
313  memset (net_from, 0, sizeof(*net_from));
315  return true;
316 
317 }

Referenced by NET_GetPacket().

◆ NET_GetPacket()

qboolean NET_GetPacket ( netsrc_t  sock,
netadr_t net_from,
sizebuf_t net_message 
)

Definition at line 336 of file net_wins.c.

337 {
338  int ret;
339  struct sockaddr from;
340  int fromlen;
341  int net_socket;
342  int protocol;
343  int err;
344 
346  return true;
347 
348  for (protocol = 0 ; protocol < 2 ; protocol++)
349  {
350  if (protocol == 0)
351  net_socket = ip_sockets[sock];
352  else
353  net_socket = ipx_sockets[sock];
354 
355  if (!net_socket)
356  continue;
357 
358  fromlen = sizeof(from);
359  ret = recvfrom (net_socket, net_message->data, net_message->maxsize
360  , 0, (struct sockaddr *)&from, &fromlen);
361 
362  SockadrToNetadr (&from, net_from);
363 
364  if (ret == -1)
365  {
366  err = WSAGetLastError();
367 
368  if (err == WSAEWOULDBLOCK)
369  continue;
370  if (err == WSAEMSGSIZE) {
371  Com_Printf ("Warning: Oversize packet from %s\n",
373  continue;
374  }
375 
376  if (dedicated->value) // let dedicated servers continue after errors
377  Com_Printf ("NET_GetPacket: %s from %s\n", NET_ErrorString(),
379  else
380  Com_Error (ERR_DROP, "NET_GetPacket: %s from %s",
382  continue;
383  }
384 
385  if (ret == net_message->maxsize)
386  {
387  Com_Printf ("Oversize packet from %s\n", NET_AdrToString (*net_from));
388  continue;
389  }
390 
391  net_message->cursize = ret;
392  return true;
393  }
394 
395  return false;
396 }

Referenced by CL_DumpPackets(), CL_ReadPackets(), and SV_ReadPackets().

◆ NET_Init()

void NET_Init ( void  )

Definition at line 767 of file net_wins.c.

768 {
769  WORD wVersionRequested;
770  int r;
771 
772  wVersionRequested = MAKEWORD(1, 1);
773 
774  r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
775 
776  if (r)
777  Com_Error (ERR_FATAL,"Winsock initialization failed.");
778 
779  Com_Printf("Winsock Initialized\n");
780 
781  noudp = Cvar_Get ("noudp", "0", CVAR_NOSET);
782  noipx = Cvar_Get ("noipx", "0", CVAR_NOSET);
783 
784  net_shownet = Cvar_Get ("net_shownet", "0", 0);
785 }

Referenced by Qcommon_Init().

◆ NET_IPSocket()

int NET_IPSocket ( char *  net_interface,
int  port 
)

Definition at line 484 of file net_wins.c.

485 {
486  int newsocket;
487  struct sockaddr_in address;
488  u_long _true = 1;
489  int i = 1;
490  int err;
491 
492  if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
493  {
494  err = WSAGetLastError();
495  if (err != WSAEAFNOSUPPORT)
496  Com_Printf ("WARNING: UDP_OpenSocket: socket: %s", NET_ErrorString());
497  return 0;
498  }
499 
500  // make it non-blocking
501  if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
502  {
503  Com_Printf ("WARNING: UDP_OpenSocket: ioctl FIONBIO: %s\n", NET_ErrorString());
504  return 0;
505  }
506 
507  // make it broadcast capable
508  if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
509  {
510  Com_Printf ("WARNING: UDP_OpenSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString());
511  return 0;
512  }
513 
514  if (!net_interface || !net_interface[0] || !stricmp(net_interface, "localhost"))
515  address.sin_addr.s_addr = INADDR_ANY;
516  else
517  NET_StringToSockaddr (net_interface, (struct sockaddr *)&address);
518 
519  if (port == PORT_ANY)
520  address.sin_port = 0;
521  else
522  address.sin_port = htons((short)port);
523 
524  address.sin_family = AF_INET;
525 
526  if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
527  {
528  Com_Printf ("WARNING: UDP_OpenSocket: bind: %s\n", NET_ErrorString());
529  closesocket (newsocket);
530  return 0;
531  }
532 
533  return newsocket;
534 }

Referenced by NET_OpenIP().

◆ NET_IPXSocket()

int NET_IPXSocket ( int  port)

Definition at line 594 of file net_wins.c.

595 {
596  int newsocket;
597  struct sockaddr_ipx address;
598  int _true = 1;
599  int err;
600 
601  if ((newsocket = socket (PF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == -1)
602  {
603  err = WSAGetLastError();
604  if (err != WSAEAFNOSUPPORT)
605  Com_Printf ("WARNING: IPX_Socket: socket: %s\n", NET_ErrorString());
606  return 0;
607  }
608 
609  // make it non-blocking
610  if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
611  {
612  Com_Printf ("WARNING: IPX_Socket: ioctl FIONBIO: %s\n", NET_ErrorString());
613  return 0;
614  }
615 
616  // make it broadcast capable
617  if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof(_true)) == -1)
618  {
619  Com_Printf ("WARNING: IPX_Socket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString());
620  return 0;
621  }
622 
623  address.sa_family = AF_IPX;
624  memset (address.sa_netnum, 0, 4);
625  memset (address.sa_nodenum, 0, 6);
626  if (port == PORT_ANY)
627  address.sa_socket = 0;
628  else
629  address.sa_socket = htons((short)port);
630 
631  if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
632  {
633  Com_Printf ("WARNING: IPX_Socket: bind: %s\n", NET_ErrorString());
634  closesocket (newsocket);
635  return 0;
636  }
637 
638  return newsocket;
639 }

Referenced by NET_OpenIPX().

◆ NET_IsLocalAddress()

qboolean NET_IsLocalAddress ( netadr_t  adr)

Definition at line 282 of file net_wins.c.

283 {
284  return adr.type == NA_LOOPBACK;
285 }

Referenced by CL_ConnectionlessPacket(), and SVC_DirectConnect().

◆ NET_OpenIP()

void NET_OpenIP ( void  )

Definition at line 542 of file net_wins.c.

543 {
544  cvar_t *ip;
545  int port;
546  int dedicated;
547 
548  ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);
549 
550  dedicated = Cvar_VariableValue ("dedicated");
551 
552  if (!ip_sockets[NS_SERVER])
553  {
554  port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->value;
555  if (!port)
556  {
557  port = Cvar_Get("hostport", "0", CVAR_NOSET)->value;
558  if (!port)
559  {
560  port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value;
561  }
562  }
563  ip_sockets[NS_SERVER] = NET_IPSocket (ip->string, port);
564  if (!ip_sockets[NS_SERVER] && dedicated)
565  Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port");
566  }
567 
568 
569  // dedicated servers don't need client ports
570  if (dedicated)
571  return;
572 
573  if (!ip_sockets[NS_CLIENT])
574  {
575  port = Cvar_Get("ip_clientport", "0", CVAR_NOSET)->value;
576  if (!port)
577  {
578  port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_NOSET)->value;
579  if (!port)
580  port = PORT_ANY;
581  }
582  ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, port);
583  if (!ip_sockets[NS_CLIENT])
585  }
586 }

Referenced by NET_Config().

◆ NET_OpenIPX()

void NET_OpenIPX ( void  )

Definition at line 647 of file net_wins.c.

648 {
649  int port;
650  int dedicated;
651 
652  dedicated = Cvar_VariableValue ("dedicated");
653 
654  if (!ipx_sockets[NS_SERVER])
655  {
656  port = Cvar_Get("ipx_hostport", "0", CVAR_NOSET)->value;
657  if (!port)
658  {
659  port = Cvar_Get("hostport", "0", CVAR_NOSET)->value;
660  if (!port)
661  {
662  port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value;
663  }
664  }
666  }
667 
668  // dedicated servers don't need client ports
669  if (dedicated)
670  return;
671 
672  if (!ipx_sockets[NS_CLIENT])
673  {
674  port = Cvar_Get("ipx_clientport", "0", CVAR_NOSET)->value;
675  if (!port)
676  {
677  port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_NOSET)->value;
678  if (!port)
679  port = PORT_ANY;
680  }
682  if (!ipx_sockets[NS_CLIENT])
684  }
685 }

Referenced by NET_Config().

◆ NET_SendLoopPacket()

void NET_SendLoopPacket ( netsrc_t  sock,
int  length,
void data,
netadr_t  to 
)

Definition at line 320 of file net_wins.c.

321 {
322  int i;
323  loopback_t *loop;
324 
325  loop = &loopbacks[sock^1];
326 
327  i = loop->send & (MAX_LOOPBACK-1);
328  loop->send++;
329 
330  memcpy (loop->msgs[i].data, data, length);
331  loop->msgs[i].datalen = length;
332 }

Referenced by NET_SendPacket().

◆ NET_SendPacket()

void NET_SendPacket ( netsrc_t  sock,
int  length,
void data,
netadr_t  to 
)

Definition at line 400 of file net_wins.c.

401 {
402  int ret;
403  struct sockaddr addr;
404  int net_socket;
405 
406  if ( to.type == NA_LOOPBACK )
407  {
408  NET_SendLoopPacket (sock, length, data, to);
409  return;
410  }
411 
412  if (to.type == NA_BROADCAST)
413  {
414  net_socket = ip_sockets[sock];
415  if (!net_socket)
416  return;
417  }
418  else if (to.type == NA_IP)
419  {
420  net_socket = ip_sockets[sock];
421  if (!net_socket)
422  return;
423  }
424  else if (to.type == NA_IPX)
425  {
426  net_socket = ipx_sockets[sock];
427  if (!net_socket)
428  return;
429  }
430  else if (to.type == NA_BROADCAST_IPX)
431  {
432  net_socket = ipx_sockets[sock];
433  if (!net_socket)
434  return;
435  }
436  else
437  Com_Error (ERR_FATAL, "NET_SendPacket: bad address type");
438 
439  NetadrToSockadr (&to, &addr);
440 
441  ret = sendto (net_socket, data, length, 0, &addr, sizeof(addr) );
442  if (ret == -1)
443  {
444  int err = WSAGetLastError();
445 
446  // wouldblock is silent
447  if (err == WSAEWOULDBLOCK)
448  return;
449 
450  // some PPP links dont allow broadcasts
451  if ((err == WSAEADDRNOTAVAIL) && ((to.type == NA_BROADCAST) || (to.type == NA_BROADCAST_IPX)))
452  return;
453 
454  if (dedicated->value) // let dedicated servers continue after errors
455  {
456  Com_Printf ("NET_SendPacket ERROR: %s to %s\n", NET_ErrorString(),
457  NET_AdrToString (to));
458  }
459  else
460  {
461  if (err == WSAEADDRNOTAVAIL)
462  {
463  Com_DPrintf ("NET_SendPacket Warning: %s : %s\n",
465  }
466  else
467  {
468  Com_Error (ERR_DROP, "NET_SendPacket ERROR: %s to %s\n",
470  }
471  }
472  }
473 }

Referenced by CL_Packet_f(), CL_Rcon_f(), Netchan_OutOfBand(), and Netchan_Transmit().

◆ NET_Shutdown()

void NET_Shutdown ( void  )

Definition at line 793 of file net_wins.c.

794 {
795  NET_Config (false); // close sockets
796 
797  WSACleanup ();
798 }

◆ NET_Sleep()

void NET_Sleep ( int  msec)

Definition at line 731 of file net_wins.c.

732 {
733  struct timeval timeout;
734  fd_set fdset;
735  extern cvar_t *dedicated;
736  int i;
737 
738  if (!dedicated || !dedicated->value)
739  return; // we're not a server, just run full speed
740 
741  FD_ZERO(&fdset);
742  i = 0;
743  if (ip_sockets[NS_SERVER]) {
744  FD_SET(ip_sockets[NS_SERVER], &fdset); // network socket
746  }
747  if (ipx_sockets[NS_SERVER]) {
748  FD_SET(ipx_sockets[NS_SERVER], &fdset); // network socket
749  if (ipx_sockets[NS_SERVER] > i)
751  }
752  timeout.tv_sec = msec/1000;
753  timeout.tv_usec = (msec%1000)*1000;
754  select(i+1, &fdset, NULL, NULL, &timeout);
755 }

Referenced by SV_Frame().

◆ NET_StringToAdr()

qboolean NET_StringToAdr ( char *  s,
netadr_t a 
)

Definition at line 262 of file net_wins.c.

263 {
264  struct sockaddr sadr;
265 
266  if (!strcmp (s, "localhost"))
267  {
268  memset (a, 0, sizeof(*a));
269  a->type = NA_LOOPBACK;
270  return true;
271  }
272 
273  if (!NET_StringToSockaddr (s, &sadr))
274  return false;
275 
276  SockadrToNetadr (&sadr, a);
277 
278  return true;
279 }

Referenced by CL_CheckForResend(), CL_Packet_f(), CL_PingServers_f(), CL_Rcon_f(), CL_SendConnectPacket(), SV_InitGame(), and SV_SetMaster_f().

◆ NET_StringToSockaddr()

qboolean NET_StringToSockaddr ( char *  s,
struct sockaddr *  sadr 
)

Definition at line 193 of file net_wins.c.

194 {
195  struct hostent *h;
196  char *colon;
197  int val;
198  char copy[128];
199 
200  memset (sadr, 0, sizeof(*sadr));
201 
202  if ((strlen(s) >= 23) && (s[8] == ':') && (s[21] == ':')) // check for an IPX address
203  {
204  ((struct sockaddr_ipx *)sadr)->sa_family = AF_IPX;
205  copy[2] = 0;
206  DO(0, sa_netnum[0]);
207  DO(2, sa_netnum[1]);
208  DO(4, sa_netnum[2]);
209  DO(6, sa_netnum[3]);
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);
218  }
219  else
220  {
221  ((struct sockaddr_in *)sadr)->sin_family = AF_INET;
222 
223  ((struct sockaddr_in *)sadr)->sin_port = 0;
224 
225  strcpy (copy, s);
226  // strip off a trailing :port if present
227  for (colon = copy ; *colon ; colon++)
228  if (*colon == ':')
229  {
230  *colon = 0;
231  ((struct sockaddr_in *)sadr)->sin_port = htons((short)atoi(colon+1));
232  }
233 
234  if (copy[0] >= '0' && copy[0] <= '9')
235  {
236  *(int *)&((struct sockaddr_in *)sadr)->sin_addr = inet_addr(copy);
237  }
238  else
239  {
240  if (! (h = gethostbyname(copy)) )
241  return 0;
242  *(int *)&((struct sockaddr_in *)sadr)->sin_addr = *(int *)h->h_addr_list[0];
243  }
244  }
245 
246  return true;
247 }

Referenced by NET_IPSocket(), and NET_StringToAdr().

◆ NetadrToSockadr()

void NetadrToSockadr ( netadr_t a,
struct sockaddr *  s 
)

Definition at line 54 of file net_wins.c.

55 {
56  memset (s, 0, sizeof(*s));
57 
58  if (a->type == NA_BROADCAST)
59  {
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;
63  }
64  else if (a->type == NA_IP)
65  {
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;
69  }
70  else if (a->type == NA_IPX)
71  {
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;
76  }
77  else if (a->type == NA_BROADCAST_IPX)
78  {
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;
83  }
84 }

Referenced by NET_SendPacket().

◆ SockadrToNetadr()

void SockadrToNetadr ( struct sockaddr *  s,
netadr_t a 
)

Definition at line 86 of file net_wins.c.

87 {
88  if (s->sa_family == AF_INET)
89  {
90  a->type = NA_IP;
91  *(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
92  a->port = ((struct sockaddr_in *)s)->sin_port;
93  }
94  else if (s->sa_family == AF_IPX)
95  {
96  a->type = NA_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;
100  }
101 }

Referenced by NET_GetPacket(), and NET_StringToAdr().

Variable Documentation

◆ ip_sockets

int ip_sockets[2]

Definition at line 47 of file net_wins.c.

Referenced by NET_Config(), NET_GetPacket(), NET_OpenIP(), NET_SendPacket(), and NET_Sleep().

◆ ipx_sockets

int ipx_sockets[2]

Definition at line 48 of file net_wins.c.

Referenced by NET_Config(), NET_GetPacket(), NET_OpenIPX(), NET_SendPacket(), and NET_Sleep().

◆ loopbacks

loopback_t loopbacks[2]

Definition at line 46 of file net_wins.c.

Referenced by NET_GetLoopPacket(), and NET_SendLoopPacket().

◆ net_shownet

cvar_t* net_shownet

Definition at line 42 of file net_wins.c.

Referenced by NET_Init().

◆ noipx

cvar_t* noipx
static

Definition at line 44 of file net_wins.c.

Referenced by CL_PingServers_f(), NET_Config(), and NET_Init().

◆ noudp

cvar_t* noudp
static

Definition at line 43 of file net_wins.c.

Referenced by CL_PingServers_f(), NET_Config(), and NET_Init().

◆ winsockdata

WSADATA winsockdata
static

Definition at line 760 of file net_wins.c.

Referenced by NET_Init().

loopback_t::get
int get
Definition: net_wins.c:38
NA_IPX
@ NA_IPX
Definition: qcommon.h:547
dedicated
cvar_t * dedicated
Definition: common.c:47
ipx_sockets
int ipx_sockets[2]
Definition: net_wins.c:48
NET_OpenIP
void NET_OpenIP(void)
Definition: net_wins.c:542
TRUE
#define TRUE
Definition: stb_vorbis.c:617
NS_SERVER
@ NS_SERVER
Definition: qcommon.h:549
CVAR_NOSET
#define CVAR_NOSET
Definition: q_shared.h:319
NET_Config
void NET_Config(qboolean multiplayer)
Definition: net_wins.c:695
net_message
sizebuf_t net_message
Definition: net_chan.c:82
NA_IP
@ NA_IP
Definition: qcommon.h:547
net_from
netadr_t net_from
Definition: net_chan.c:81
NET_AdrToString
char * NET_AdrToString(netadr_t a)
Definition: net_wins.c:161
PORT_ANY
#define PORT_ANY
Definition: qcommon.h:542
loopback_t
Definition: net_wins.c:35
cvar_s::string
char * string
Definition: q_shared.h:327
qboolean
qboolean
Definition: q_shared.h:63
loopback_t::send
int send
Definition: net_wins.c:38
i
int i
Definition: q_shared.c:305
loopback_t::msgs
loopmsg_t msgs[MAX_LOOPBACK]
Definition: net_wins.c:37
NET_OpenIPX
void NET_OpenIPX(void)
Definition: net_wins.c:647
sizebuf_s::data
byte * data
Definition: qcommon.h:96
NA_BROADCAST
@ NA_BROADCAST
Definition: qcommon.h:547
Cvar_Get
cvar_t * Cvar_Get(char *var_name, char *var_value, int flags)
Definition: cvar.c:127
net_shownet
cvar_t * net_shownet
Definition: net_wins.c:42
cvar_s
Definition: q_shared.h:324
va
char * va(char *format,...)
Definition: q_shared.c:1050
winsockdata
static WSADATA winsockdata
Definition: net_wins.c:760
sizebuf_s::maxsize
int maxsize
Definition: qcommon.h:97
loopmsg_t::datalen
int datalen
Definition: net_wins.c:32
SockadrToNetadr
void SockadrToNetadr(struct sockaddr *s, netadr_t *a)
Definition: net_wins.c:86
r
GLdouble GLdouble r
Definition: qgl_win.c:336
NET_IPXSocket
int NET_IPXSocket(int port)
Definition: net_wins.c:594
netadr_t::ip
byte ip[4]
Definition: qcommon.h:555
loopbacks
loopback_t loopbacks[2]
Definition: net_wins.c:46
netadr_t::ipx
byte ipx[10]
Definition: qcommon.h:556
cvar_s::value
float value
Definition: q_shared.h:331
MAX_LOOPBACK
#define MAX_LOOPBACK
Definition: net_wins.c:27
NULL
#define NULL
Definition: q_shared.h:67
noudp
static cvar_t * noudp
Definition: net_wins.c:43
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:181
NetadrToSockadr
void NetadrToSockadr(netadr_t *a, struct sockaddr *s)
Definition: net_wins.c:54
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:744
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
s
static fixed16_t s
Definition: r_scan.c:30
netadr_t::type
netadrtype_t type
Definition: qcommon.h:553
NET_SendLoopPacket
void NET_SendLoopPacket(netsrc_t sock, int length, void *data, netadr_t to)
Definition: net_wins.c:320
loopmsg_t::data
byte data[MAX_MSGLEN]
Definition: net_wins.c:31
ip_sockets
int ip_sockets[2]
Definition: net_wins.c:47
PORT_CLIENT
#define PORT_CLIENT
Definition: qcommon.h:202
NS_CLIENT
@ NS_CLIENT
Definition: qcommon.h:549
netadr_t::port
unsigned short port
Definition: qcommon.h:558
NA_BROADCAST_IPX
@ NA_BROADCAST_IPX
Definition: qcommon.h:547
DO
#define DO(src, dest)
Definition: net_wins.c:187
sizebuf_s::cursize
int cursize
Definition: qcommon.h:98
Com_DPrintf
void Com_DPrintf(char *fmt,...)
Definition: common.c:157
NET_StringToSockaddr
qboolean NET_StringToSockaddr(char *s, struct sockaddr *sadr)
Definition: net_wins.c:193
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:104
NET_ErrorString
char * NET_ErrorString(void)
Definition: net_wins.c:806
NET_IPSocket
int NET_IPSocket(char *net_interface, int port)
Definition: net_wins.c:484
NET_GetLoopPacket
qboolean NET_GetLoopPacket(netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
Definition: net_wins.c:295
noipx
static cvar_t * noipx
Definition: net_wins.c:44
PORT_SERVER
#define PORT_SERVER
Definition: qcommon.h:203
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
NA_LOOPBACK
@ NA_LOOPBACK
Definition: qcommon.h:547
Cvar_VariableValue
float Cvar_VariableValue(char *var_name)
Definition: cvar.c:63