icculus quake2 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 182 of file net_wins.c.

◆ MAX_LOOPBACK

#define MAX_LOOPBACK   4

Definition at line 26 of file net_wins.c.

Function Documentation

◆ NET_AdrToString()

char* NET_AdrToString ( netadr_t  a)

Definition at line 156 of file net_wins.c.

157 {
158  static char s[64];
159 
160  if (a.type == NA_LOOPBACK)
161  Com_sprintf (s, sizeof(s), "loopback");
162  else if (a.type == NA_IP)
163  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));
164  else
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));
166 
167  return s;
168 }

Referenced by CL_ConnectionlessPacket(), CL_ReadPackets(), JoinServerFunc(), M_AddToServerList(), 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 103 of file net_wins.c.

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

Referenced by CL_ReadPackets().

◆ NET_CompareBaseAdr()

qboolean NET_CompareBaseAdr ( netadr_t  a,
netadr_t  b 
)

Definition at line 133 of file net_wins.c.

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

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

◆ NET_Config()

void NET_Config ( qboolean  multiplayer)

Definition at line 690 of file net_wins.c.

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

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 801 of file net_wins.c.

802 {
803  int code;
804 
805  code = WSAGetLastError ();
806  switch (code)
807  {
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";
853  }
854 }

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 290 of file net_wins.c.

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

Referenced by NET_GetPacket().

◆ NET_GetPacket()

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

Definition at line 331 of file net_wins.c.

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

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

◆ NET_Init()

void NET_Init ( void  )

Definition at line 762 of file net_wins.c.

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

Referenced by Qcommon_Init().

◆ NET_IPSocket()

int NET_IPSocket ( char *  net_interface,
int  port 
)

Definition at line 479 of file net_wins.c.

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

Referenced by NET_OpenIP().

◆ NET_IPXSocket()

int NET_IPXSocket ( int  port)

Definition at line 589 of file net_wins.c.

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

Referenced by NET_OpenIPX().

◆ NET_IsLocalAddress()

qboolean NET_IsLocalAddress ( netadr_t  adr)

Definition at line 277 of file net_wins.c.

278 {
279  return adr.type == NA_LOOPBACK;
280 }

Referenced by CL_ConnectionlessPacket(), and SVC_DirectConnect().

◆ NET_OpenIP()

void NET_OpenIP ( void  )

Definition at line 537 of file net_wins.c.

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

Referenced by NET_Config().

◆ NET_OpenIPX()

void NET_OpenIPX ( void  )

Definition at line 642 of file net_wins.c.

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

Referenced by NET_Config().

◆ NET_SendLoopPacket()

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

Definition at line 315 of file net_wins.c.

316 {
317  int i;
318  loopback_t *loop;
319 
320  loop = &loopbacks[sock^1];
321 
322  i = loop->send & (MAX_LOOPBACK-1);
323  loop->send++;
324 
325  memcpy (loop->msgs[i].data, data, length);
326  loop->msgs[i].datalen = length;
327 }

Referenced by NET_SendPacket().

◆ NET_SendPacket()

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

Definition at line 395 of file net_wins.c.

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

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

◆ NET_Shutdown()

void NET_Shutdown ( void  )

Definition at line 788 of file net_wins.c.

789 {
790  NET_Config (false); // close sockets
791 
792  WSACleanup ();
793 }

◆ NET_Sleep()

void NET_Sleep ( int  msec)

Definition at line 726 of file net_wins.c.

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

Referenced by SV_Frame().

◆ NET_StringToAdr()

qboolean NET_StringToAdr ( char *  s,
netadr_t a 
)

Definition at line 257 of file net_wins.c.

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

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 188 of file net_wins.c.

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

Referenced by NET_IPSocket(), and NET_StringToAdr().

◆ NetadrToSockadr()

void NetadrToSockadr ( netadr_t a,
struct sockaddr *  s 
)

Definition at line 53 of file net_wins.c.

54 {
55  memset (s, 0, sizeof(*s));
56 
57  if (a->type == NA_BROADCAST)
58  {
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;
62  }
63  else if (a->type == NA_IP)
64  {
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;
68  }
69  else if (a->type == NA_IPX)
70  {
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;
75  }
76  else if (a->type == NA_BROADCAST_IPX)
77  {
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;
82  }
83 }

Referenced by NET_SendPacket().

◆ SockadrToNetadr()

void SockadrToNetadr ( struct sockaddr *  s,
netadr_t a 
)

Definition at line 85 of file net_wins.c.

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

Referenced by NET_GetPacket(), and NET_StringToAdr().

Variable Documentation

◆ ip_sockets

int ip_sockets[2]

Definition at line 46 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 47 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 45 of file net_wins.c.

Referenced by NET_GetLoopPacket(), and NET_SendLoopPacket().

◆ net_shownet

cvar_t* net_shownet

Definition at line 41 of file net_wins.c.

Referenced by NET_Init().

◆ noipx

cvar_t* noipx
static

Definition at line 43 of file net_wins.c.

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

◆ noudp

cvar_t* noudp
static

Definition at line 42 of file net_wins.c.

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

◆ winsockdata

WSADATA winsockdata
static

Definition at line 755 of file net_wins.c.

Referenced by NET_Init().

loopback_t::get
int get
Definition: net_wins.c:37
NA_IPX
@ NA_IPX
Definition: qcommon.h:533
dedicated
cvar_t * dedicated
Definition: common.c:47
ipx_sockets
int ipx_sockets[2]
Definition: net_wins.c:47
NET_OpenIP
void NET_OpenIP(void)
Definition: net_wins.c:537
NS_SERVER
@ NS_SERVER
Definition: qcommon.h:536
CVAR_NOSET
#define CVAR_NOSET
Definition: q_shared.h:312
NET_Config
void NET_Config(qboolean multiplayer)
Definition: net_wins.c:690
net_message
sizebuf_t net_message
Definition: net_chan.c:82
NA_IP
@ NA_IP
Definition: qcommon.h:533
net_from
netadr_t net_from
Definition: net_chan.c:81
NET_AdrToString
char * NET_AdrToString(netadr_t a)
Definition: net_wins.c:156
PORT_ANY
#define PORT_ANY
Definition: qcommon.h:525
loopback_t
Definition: net_wins.c:34
cvar_s::string
char * string
Definition: q_shared.h:320
qboolean
qboolean
Definition: q_shared.h:56
loopback_t::send
int send
Definition: net_wins.c:37
i
int i
Definition: q_shared.c:305
loopback_t::msgs
loopmsg_t msgs[MAX_LOOPBACK]
Definition: net_wins.c:36
NET_OpenIPX
void NET_OpenIPX(void)
Definition: net_wins.c:642
sizebuf_s::data
byte * data
Definition: qcommon.h:79
NA_BROADCAST
@ NA_BROADCAST
Definition: qcommon.h:533
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:41
cvar_s
Definition: q_shared.h:317
va
char * va(char *format,...)
Definition: q_shared.c:1050
winsockdata
static WSADATA winsockdata
Definition: net_wins.c:755
sizebuf_s::maxsize
int maxsize
Definition: qcommon.h:80
loopmsg_t::datalen
int datalen
Definition: net_wins.c:31
SockadrToNetadr
void SockadrToNetadr(struct sockaddr *s, netadr_t *a)
Definition: net_wins.c:85
r
GLdouble GLdouble r
Definition: qgl_win.c:336
NET_IPXSocket
int NET_IPXSocket(int port)
Definition: net_wins.c:589
netadr_t::ip
byte ip[4]
Definition: qcommon.h:546
loopbacks
loopback_t loopbacks[2]
Definition: net_wins.c:45
netadr_t::ipx
byte ipx[10]
Definition: qcommon.h:548
cvar_s::value
float value
Definition: q_shared.h:324
MAX_LOOPBACK
#define MAX_LOOPBACK
Definition: net_wins.c:26
NULL
#define NULL
Definition: q_shared.h:60
noudp
static cvar_t * noudp
Definition: net_wins.c:42
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:203
NetadrToSockadr
void NetadrToSockadr(netadr_t *a, struct sockaddr *s)
Definition: net_wins.c:53
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:736
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:735
netadr_t::type
netadrtype_t type
Definition: qcommon.h:540
NET_SendLoopPacket
void NET_SendLoopPacket(netsrc_t sock, int length, void *data, netadr_t to)
Definition: net_wins.c:315
timeout
cvar_t * timeout
Definition: sv_main.c:32
loopmsg_t::data
byte data[MAX_MSGLEN]
Definition: net_wins.c:30
ip_sockets
int ip_sockets[2]
Definition: net_wins.c:46
PORT_CLIENT
#define PORT_CLIENT
Definition: qcommon.h:185
NS_CLIENT
@ NS_CLIENT
Definition: qcommon.h:536
netadr_t::port
unsigned short port
Definition: qcommon.h:550
NA_BROADCAST_IPX
@ NA_BROADCAST_IPX
Definition: qcommon.h:533
DO
#define DO(src, dest)
Definition: net_wins.c:182
sizebuf_s::cursize
int cursize
Definition: qcommon.h:81
Com_DPrintf
void Com_DPrintf(char *fmt,...)
Definition: common.c:155
NET_StringToSockaddr
qboolean NET_StringToSockaddr(char *s, struct sockaddr *sadr)
Definition: net_wins.c:188
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:102
NET_ErrorString
char * NET_ErrorString(void)
Definition: net_wins.c:801
NET_IPSocket
int NET_IPSocket(char *net_interface, int port)
Definition: net_wins.c:479
NET_GetLoopPacket
qboolean NET_GetLoopPacket(netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
Definition: net_wins.c:290
noipx
static cvar_t * noipx
Definition: net_wins.c:43
PORT_SERVER
#define PORT_SERVER
Definition: qcommon.h:186
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
NA_LOOPBACK
@ NA_LOOPBACK
Definition: qcommon.h:533
Cvar_VariableValue
float Cvar_VariableValue(char *var_name)
Definition: cvar.c:63