Quake II RTX doxygen
1.0 dev
|
|
#include "shared/shared.h"
#include "common/common.h"
#include "common/cvar.h"
#include "common/fifo.h"
#include "common/msg.h"
#include "common/net/net.h"
#include "common/protocol.h"
#include "common/zone.h"
#include "client/client.h"
#include "server/server.h"
#include "system/system.h"
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include "inet_ntop.h"
#include "inet_pton.h"
#include "win.h"
Go to the source code of this file.
|
static size_t | NET_NetadrToSockadr (const netadr_t *a, struct sockaddr_storage *s) |
|
static void | NET_SockadrToNetadr (const struct sockaddr_storage *s, netadr_t *a) |
|
char * | NET_BaseAdrToString (const netadr_t *a) |
|
char * | NET_AdrToString (const netadr_t *a) |
|
static struct addrinfo * | NET_SearchAdrrInfo (struct addrinfo *rp, int family) |
|
qboolean | NET_StringPairToAdr (const char *host, const char *port, netadr_t *a) |
|
qboolean | NET_StringToAdr (const char *s, netadr_t *a, int default_port) |
|
void | NET_UpdateStats (void) |
|
static void | NET_Stats_f (void) |
|
static size_t | NET_UpRate_m (char *buffer, size_t size) |
|
static size_t | NET_DnRate_m (char *buffer, size_t size) |
|
const char * | NET_ErrorString (void) |
|
ioentry_t * | NET_AddFd (qsocket_t fd) |
|
void | NET_RemoveFd (qsocket_t fd) |
|
int | NET_Sleep (int msec) |
|
static void | NET_GetUdpPackets (qsocket_t sock, void(*packet_cb)(void)) |
|
void | NET_GetPackets (netsrc_t sock, void(*packet_cb)(void)) |
|
qboolean | NET_SendPacket (netsrc_t sock, const void *data, size_t len, const netadr_t *to) |
|
static qsocket_t | UDP_OpenSocket (const char *iface, int port, int family) |
|
static qsocket_t | TCP_OpenSocket (const char *iface, int port, int family, netsrc_t who) |
|
static void | NET_OpenServer (void) |
|
static void | NET_OpenServer6 (void) |
|
void | NET_Config (netflag_t flag) |
|
qboolean | NET_GetAddress (netsrc_t sock, netadr_t *adr) |
|
void | NET_CloseStream (netstream_t *s) |
|
static neterr_t | NET_Listen4 (qboolean arg) |
|
static neterr_t | NET_Listen6 (qboolean arg) |
|
neterr_t | NET_Listen (qboolean arg) |
|
static neterr_t | NET_AcceptSocket (netstream_t *s, qsocket_t sock) |
|
neterr_t | NET_Accept (netstream_t *s) |
|
neterr_t | NET_Connect (const netadr_t *peer, netstream_t *s) |
|
neterr_t | NET_RunConnect (netstream_t *s) |
|
void | NET_UpdateStream (netstream_t *s) |
|
neterr_t | NET_RunStream (netstream_t *s) |
|
static void | dump_addrinfo (struct addrinfo *ai) |
|
static void | dump_socket (qsocket_t s, const char *s1, const char *s2) |
|
static void | NET_ShowIP_f (void) |
|
static void | NET_Dns_f (void) |
|
static void | NET_Restart_f (void) |
|
static void | net_udp_param_changed (cvar_t *self) |
|
static const char * | NET_EnableIP6 (void) |
|
void | NET_Init (void) |
|
void | NET_Shutdown (void) |
|
◆ MAX_ERROR_RETRIES
#define MAX_ERROR_RETRIES 64 |
Definition at line 65 of file net.c.
◆ NS_IN6ADDRSZ
◆ NS_INADDRSZ
◆ NS_INT16SZ
◆ RATE_SECS
◆ WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN |
Definition at line 39 of file net.c.
◆ dump_addrinfo()
static void dump_addrinfo |
( |
struct addrinfo * |
ai | ) |
|
|
static |
Definition at line 1747 of file net.c.
1749 char buf1[MAX_QPATH], buf2[MAX_STRING_CHARS];
1750 char *fa = (ai->ai_addr->sa_family == AF_INET6) ?
"6" :
"";
1752 getnameinfo(ai->ai_addr, ai->ai_addrlen,
1753 buf1,
sizeof(buf1), NULL, 0, NI_NUMERICHOST);
1754 if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
1755 buf2,
sizeof(buf2), NULL, 0, NI_NAMEREQD) == 0)
1756 Com_Printf(
"IP%1s : %s (%s)\n", fa, buf1, buf2);
1758 Com_Printf(
"IP%1s : %s\n", fa, buf1);
Referenced by NET_Dns_f(), and NET_ShowIP_f().
◆ dump_socket()
static void dump_socket |
( |
qsocket_t |
s, |
|
|
const char * |
s1, |
|
|
const char * |
s2 |
|
) |
| |
|
static |
Definition at line 1761 of file net.c.
1769 Com_EPrintf(
"Couldn't get %s %s socket name: %s\n",
1774 Com_Printf(
"%s %s socket bound to %s\n",
Referenced by NET_ShowIP_f().
◆ NET_Accept()
neterr_t NET_Accept |
( |
netstream_t * |
s | ) |
|
◆ NET_AcceptSocket()
static neterr_t NET_AcceptSocket |
( |
netstream_t * |
s, |
|
|
qsocket_t |
sock |
|
) |
| |
|
static |
Definition at line 1482 of file net.c.
1485 qsocket_t newsocket;
1499 e->canread = qfalse;
1511 memset(s, 0,
sizeof(*s));
1512 s->socket = newsocket;
1514 s->state = NS_CONNECTED;
1519 e->wantread = qtrue;
Referenced by NET_Accept().
◆ NET_AddFd()
ioentry_t* NET_AddFd |
( |
qsocket_t |
fd | ) |
|
◆ NET_AdrToString()
char* NET_AdrToString |
( |
const netadr_t * |
a | ) |
|
Definition at line 257 of file net.c.
259 static char s[MAX_QPATH];
263 return strcpy(s,
"<unspecified>");
265 return strcpy(s,
"loopback");
267 Q_snprintf(s,
sizeof(s), (a->type == NA_IP6) ?
"[%s]:%u" :
"%s:%u",
Referenced by AC_ClientBegin(), AC_ParseFileViolation(), AC_ParseViolation(), AC_Reconnect(), AC_Run(), accept_client(), AddServer(), check_reconnect(), CL_ConnectionlessPacket(), CL_DumpStatusResponse(), CL_FollowIP_f(), CL_GTV_Run(), CL_GTV_Status_f(), CL_PacketEvent(), CL_PassiveConnect_f(), CL_RecentIP_g(), CL_ServerStatus_f(), drop_client(), dump_clients(), dump_socket(), find_client_slot(), gtv_run(), HTTP_SetServer(), MVD_Connect_f(), MVD_ListServers_f(), NET_GetUdpPackets(), NET_SendPacket(), NetchanNew_Process(), NetchanNew_Transmit(), NetchanOld_Process(), NetchanOld_Transmit(), parse_hello(), parse_stringcmd(), print_drop_reason(), process_error_queue(), resolve_masters(), SV_ConnectionlessPacket(), SV_CvarResult_f(), SV_ListMasters_f(), SV_MasterHeartbeat(), SV_MasterShutdown(), SV_MvdRunClients(), SV_SetMaster_f(), SV_UserinfoChanged(), SVC_Ack(), SVC_RemoteCommand(), SVC_Status(), UI_StatusEvent(), and userinfo_ip_string().
◆ NET_BaseAdrToString()
char* NET_BaseAdrToString |
( |
const netadr_t * |
a | ) |
|
Definition at line 216 of file net.c.
218 static char s[MAX_QPATH];
222 return strcpy(s,
"<unspecified>");
224 return strcpy(s,
"loopback");
230 return strcpy(s,
"<invalid>");
233 struct sockaddr_storage addr;
237 if (getnameinfo((
struct sockaddr *)&addr, addrlen,
238 s,
sizeof(s), NULL, 0, NI_NUMERICHOST) == 0)
244 return strcpy(s,
"<invalid>");
246 Com_Error(ERR_FATAL,
"%s: bad address type", __func__);
Referenced by format_mask(), and NET_AdrToString().
◆ NET_CloseStream()
void NET_CloseStream |
( |
netstream_t * |
s | ) |
|
◆ NET_Config()
void NET_Config |
( |
netflag_t |
flag | ) |
|
◆ NET_Connect()
neterr_t NET_Connect |
( |
const netadr_t * |
peer, |
|
|
netstream_t * |
s |
|
) |
| |
◆ NET_DnRate_m()
static size_t NET_DnRate_m |
( |
char * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
static |
◆ NET_Dns_f()
Definition at line 1831 of file net.c.
1833 char buffer[MAX_STRING_CHARS], *h, *p;
1834 struct addrinfo hints, *res, *rp;
1838 Com_Printf(
"Usage: %s <address>\n",
Cmd_Argv(0));
1850 Com_Printf(
"Bad IPv6 address\n");
1861 memset(&hints, 0,
sizeof(hints));
1862 hints.ai_flags = AI_CANONNAME;
1863 hints.ai_socktype = SOCK_STREAM;
1866 hints.ai_family = AF_INET;
1868 err = getaddrinfo(h, NULL, &hints, &res);
1870 Com_Printf(
"Couldn't resolve %s: %s\n", h, gai_strerror(
err));
1874 if (res->ai_canonname)
1875 Com_Printf(
"Hostname: %s\n", res->ai_canonname);
1877 for (rp = res; rp; rp = rp->ai_next)
Referenced by NET_Init().
◆ NET_EnableIP6()
static const char* NET_EnableIP6 |
( |
void |
| ) |
|
|
static |
◆ NET_ErrorString()
const char* NET_ErrorString |
( |
void |
| ) |
|
Definition at line 659 of file net.c.
Referenced by AC_Reconnect(), AC_Run(), check_reconnect(), CL_GTV_Start_f(), CL_ServerStatus_f(), dump_socket(), gtv_run(), MVD_Connect_f(), NET_GetUdpPackets(), NET_SendPacket(), NET_Sleep(), SV_MvdInit(), SV_MvdRunClients(), TCP_OpenSocket(), and UDP_OpenSocket().
◆ NET_GetAddress()
qboolean NET_GetAddress |
( |
netsrc_t |
sock, |
|
|
netadr_t * |
adr |
|
) |
| |
◆ NET_GetPackets()
void NET_GetPackets |
( |
netsrc_t |
sock, |
|
|
void(*)(void) |
packet_cb |
|
) |
| |
◆ NET_GetUdpPackets()
static void NET_GetUdpPackets |
( |
qsocket_t |
sock, |
|
|
void(*)(void) |
packet_cb |
|
) |
| |
|
static |
Definition at line 845 of file net.c.
859 if (ret == NET_AGAIN) {
864 if (ret == NET_ERROR) {
865 Com_DPrintf(
"%s: %s from %s\n", __func__,
872 if (net_log_enable->integer)
Referenced by NET_GetPackets().
◆ NET_Init()
Definition at line 1933 of file net.c.
1945 net_clientport =
Cvar_Get(
"net_clientport", STRINGIFY(PORT_ANY), 0);
1947 net_dropsim =
Cvar_Get(
"net_dropsim",
"0", 0);
1951 net_log_enable =
Cvar_Get(
"net_log_enable",
"0", 0);
1952 net_log_enable->changed = net_log_enable_changed;
1953 net_log_name =
Cvar_Get(
"net_log_name",
"network", 0);
1954 net_log_name->changed = net_log_param_changed;
1955 net_log_flush =
Cvar_Get(
"net_log_flush",
"0", 0);
1956 net_log_flush->changed = net_log_param_changed;
1963 net_ignore_icmp =
Cvar_Get(
"net_ignore_icmp",
"0", 0);
1967 net_log_enable_changed(net_log_enable);
Referenced by Qcommon_Init().
◆ NET_Listen()
neterr_t NET_Listen |
( |
qboolean |
arg | ) |
|
◆ NET_Listen4()
static neterr_t NET_Listen4 |
( |
qboolean |
arg | ) |
|
|
static |
◆ NET_Listen6()
static neterr_t NET_Listen6 |
( |
qboolean |
arg | ) |
|
|
static |
◆ NET_NetadrToSockadr()
static size_t NET_NetadrToSockadr |
( |
const netadr_t * |
a, |
|
|
struct sockaddr_storage * |
s |
|
) |
| |
|
static |
Definition at line 145 of file net.c.
147 struct sockaddr_in *s4 = (
struct sockaddr_in *)s;
148 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *)s;
150 memset(s, 0,
sizeof(*s));
154 s4->sin_family = AF_INET;
155 s4->sin_addr.s_addr = INADDR_BROADCAST;
156 s4->sin_port = a->port;
159 s4->sin_family = AF_INET;
160 memcpy(&s4->sin_addr, &a->ip, 4);
161 s4->sin_port = a->port;
164 s6->sin6_family = AF_INET6;
165 memcpy(&s6->sin6_addr, &a->ip, 16);
166 s6->sin6_port = a->port;
167 s6->sin6_scope_id = a->scope_id;
Referenced by NET_BaseAdrToString(), os_connect(), and os_udp_send().
◆ NET_OpenServer()
Definition at line 1195 of file net.c.
1197 static int saved_port;
1209 e->wantread = qtrue;
1213 if (saved_port && saved_port !=
net_port->integer) {
1215 Com_Printf(
"Reverting to the last valid port %d...\n", saved_port);
1222 Com_WPrintf(
"Couldn't open server UDP port.\n");
1227 Com_Error(ERR_FATAL,
"Couldn't open dedicated server UDP port");
Referenced by NET_Config().
◆ NET_OpenServer6()
◆ NET_RemoveFd()
void NET_RemoveFd |
( |
qsocket_t |
fd | ) |
|
◆ NET_Restart_f()
◆ NET_RunConnect()
neterr_t NET_RunConnect |
( |
netstream_t * |
s | ) |
|
Definition at line 1581 of file net.c.
1587 if (s->state != NS_CONNECTING) {
1609 s->state = NS_CONNECTED;
1610 e->wantwrite = qfalse;
1611 e->wantread = qtrue;
1613 e->wantexcept = qfalse;
1618 s->state = NS_BROKEN;
1619 e->wantwrite = qfalse;
1620 e->wantread = qfalse;
1622 e->wantexcept = qfalse;
Referenced by AC_Run(), and run_connect().
◆ NET_RunStream()
neterr_t NET_RunStream |
( |
netstream_t * |
s | ) |
|
Definition at line 1647 of file net.c.
1652 neterr_t result = NET_AGAIN;
1655 if (s->state != NS_CONNECTED) {
1660 if (e->wantread && e->canread) {
1662 data = FIFO_Reserve(&s->recv, &len);
1664 ret =
os_recv(s->socket, data, len, 0);
1668 if (ret == NET_ERROR) {
1671 if (ret == NET_AGAIN) {
1673 e->canread = qfalse;
1675 FIFO_Commit(&s->recv, ret);
1677 if (net_log_enable->integer) {
1678 NET_LogPacket(&s->address,
"TCP recv", data, ret);
1687 FIFO_Reserve(&s->recv, &len);
1689 e->wantread = qfalse;
1695 if (e->wantwrite && e->canwrite) {
1697 data = FIFO_Peek(&s->send, &len);
1699 ret =
os_send(s->socket, data, len, 0);
1703 if (ret == NET_ERROR) {
1706 if (ret == NET_AGAIN) {
1708 e->canwrite = qfalse;
1710 FIFO_Decommit(&s->send, ret);
1712 if (net_log_enable->integer) {
1713 NET_LogPacket(&s->address,
"TCP send", data, ret);
1722 FIFO_Peek(&s->send, &len);
1724 e->wantwrite = qfalse;
1734 s->state = NS_CLOSED;
1735 e->wantread = qfalse;
1739 s->state = NS_BROKEN;
1740 e->wantread = qfalse;
1741 e->wantwrite = qfalse;
Referenced by AC_Run(), CL_GTV_Run(), drop_client(), mvd_drop(), run_stream(), and SV_MvdRunClients().
◆ NET_SearchAdrrInfo()
static struct addrinfo* NET_SearchAdrrInfo |
( |
struct addrinfo * |
rp, |
|
|
int |
family |
|
) |
| |
|
static |
◆ NET_SendPacket()
qboolean NET_SendPacket |
( |
netsrc_t |
sock, |
|
|
const void * |
data, |
|
|
size_t |
len, |
|
|
const netadr_t * |
to |
|
) |
| |
Definition at line 918 of file net.c.
927 if (len > MAX_PACKETLEN) {
928 Com_EPrintf(
"%s: oversize packet to %s\n", __func__,
938 return NET_SendLoopPacket(sock, data, len, to);
948 Com_Error(ERR_FATAL,
"%s: bad address type", __func__);
955 if (ret == NET_AGAIN)
958 if (ret == NET_ERROR) {
959 Com_DPrintf(
"%s: %s to %s\n", __func__,
966 Com_WPrintf(
"%s: short send to %s\n", __func__,
970 if (net_log_enable->integer)
971 NET_LogPacket(to,
"UDP send", data, ret);
Referenced by Netchan_OutOfBand(), NetchanNew_Transmit(), NetchanNew_TransmitNextFragment(), NetchanOld_Transmit(), redirect(), SV_FlushRedirect(), SV_MasterHeartbeat(), SVC_Info(), and SVC_Status().
◆ NET_ShowIP_f()
Definition at line 1783 of file net.c.
1785 char buffer[MAX_STRING_CHARS];
1786 struct addrinfo hints, *res, *rp;
1789 if (gethostname(buffer,
sizeof(buffer)) == -1) {
1790 Com_EPrintf(
"Couldn't get system host name\n");
1794 memset(&hints, 0,
sizeof(hints));
1795 hints.ai_flags = AI_CANONNAME;
1796 hints.ai_socktype = SOCK_STREAM;
1799 hints.ai_family = AF_INET;
1801 err = getaddrinfo(buffer, NULL, &hints, &res);
1803 Com_Printf(
"Couldn't resolve %s: %s\n", buffer, gai_strerror(
err));
1807 if (res->ai_canonname)
1808 Com_Printf(
"Hostname: %s\n", res->ai_canonname);
1810 for (rp = res; rp; rp = rp->ai_next)
Referenced by NET_Init().
◆ NET_Shutdown()
◆ NET_Sleep()
Definition at line 712 of file net.c.
715 fd_set rfds, wfds, efds;
736 e->canwrite = qfalse;
737 e->canexcept = qfalse;
738 if (e->wantread) FD_SET(fd, &rfds);
739 if (e->wantwrite) FD_SET(fd, &wfds);
740 if (e->wantexcept) FD_SET(fd, &efds);
743 tv.tv_sec = msec / 1000;
744 tv.tv_usec = (msec % 1000) * 1000;
761 if (FD_ISSET(fd, &rfds)) e->canread = qtrue;
762 if (FD_ISSET(fd, &wfds)) e->canwrite = qtrue;
763 if (FD_ISSET(fd, &efds)) e->canexcept = qtrue;
Referenced by drop_client(), mvd_drop(), and Qcommon_Frame().
◆ NET_SockadrToNetadr()
static void NET_SockadrToNetadr |
( |
const struct sockaddr_storage * |
s, |
|
|
netadr_t * |
a |
|
) |
| |
|
static |
Definition at line 176 of file net.c.
178 const struct sockaddr_in *s4 = (
const struct sockaddr_in *)s;
179 const struct sockaddr_in6 *s6 = (
const struct sockaddr_in6 *)s;
181 memset(a, 0,
sizeof(*a));
183 switch (s->ss_family) {
186 memcpy(&a->ip, &s4->sin_addr, 4);
187 a->port = s4->sin_port;
190 if (IN6_IS_ADDR_V4MAPPED(&s6->sin6_addr)) {
192 memcpy(&a->ip, &s6->sin6_addr.s6_addr[12], 4);
195 memcpy(&a->ip, &s6->sin6_addr, 16);
196 a->scope_id = s6->sin6_scope_id;
198 a->port = s6->sin6_port;
Referenced by NET_StringPairToAdr(), os_accept(), os_getsockname(), os_udp_recv(), and process_error_queue().
◆ NET_Stats_f()
Definition at line 496 of file net.c.
498 time_t
diff, now = time(NULL);
499 char buffer[MAX_QPATH];
510 Com_Printf(
"Network uptime: %s\n", buffer);
511 Com_Printf(
"Bytes sent: %"PRIu64
" (%"PRIu64
" bytes/sec)\n",
513 Com_Printf(
"Bytes rcvd: %"PRIu64
" (%"PRIu64
" bytes/sec)\n",
515 Com_Printf(
"Packets sent: %"PRIu64
" (%"PRIu64
" packets/sec)\n",
517 Com_Printf(
"Packets rcvd: %"PRIu64
" (%"PRIu64
" packets/sec)\n",
520 Com_Printf(
"Total errors: %"PRIu64
"/%"PRIu64
"/%"PRIu64
" (send/recv/icmp)\n",
523 Com_Printf(
"Total errors: %"PRIu64
"/%"PRIu64
" (send/recv)\n",
526 Com_Printf(
"Current upload rate: %"PRIz
" bytes/sec\n",
net_rate_up);
527 Com_Printf(
"Current download rate: %"PRIz
" bytes/sec\n",
net_rate_dn);
Referenced by NET_Init().
◆ NET_StringPairToAdr()
qboolean NET_StringPairToAdr |
( |
const char * |
host, |
|
|
const char * |
port, |
|
|
netadr_t * |
a |
|
) |
| |
Definition at line 284 of file net.c.
287 struct addrinfo hints, *res, *rp;
290 memset(&hints, 0,
sizeof(hints));
293 hints.ai_family = AF_INET;
297 hints.ai_flags |= AI_NUMERICHOST;
299 #ifdef AI_NUMERICSERV
301 hints.ai_flags |= AI_NUMERICSERV;
304 err = getaddrinfo(host, port, &hints, &res);
Referenced by NET_StringToAdr().
◆ NET_StringToAdr()
qboolean NET_StringToAdr |
( |
const char * |
s, |
|
|
netadr_t * |
a, |
|
|
int |
default_port |
|
) |
| |
Definition at line 332 of file net.c.
334 char copy[MAX_STRING_CHARS], *h, *p;
338 if (len >=
sizeof(copy))
360 a->port = BigShort(default_port);
Referenced by AC_Reconnect(), AddServer(), check_reconnect(), CL_Connect_f(), CL_PingServers_f(), CL_Rcon_f(), CL_ServerStatus_f(), Con_RemoteMode_f(), MVD_Connect_f(), resolve_masters(), SV_PickClient_f(), and SV_SetMaster_f().
◆ net_udp_param_changed()
static void net_udp_param_changed |
( |
cvar_t * |
self | ) |
|
|
static |
◆ NET_UpdateStats()
◆ NET_UpdateStream()
void NET_UpdateStream |
( |
netstream_t * |
s | ) |
|
Definition at line 1628 of file net.c.
1633 if (s->state != NS_CONNECTED) {
1639 FIFO_Reserve(&s->recv, &len);
1640 e->wantread = len ? qtrue : qfalse;
1642 FIFO_Peek(&s->send, &len);
1643 e->wantwrite = len ? qtrue : qfalse;
Referenced by AC_Flush(), AC_Run(), AC_Write(), CL_GTV_Run(), CL_GTV_Transmit(), drop_client(), gtv_forward_cmd(), gtv_run(), gtv_wait_start(), mvd_drop(), resume_streams(), suspend_streams(), SV_MvdEndFrame(), SV_MvdMapChanged(), and SV_MvdRunClients().
◆ NET_UpRate_m()
static size_t NET_UpRate_m |
( |
char * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
static |
◆ TCP_OpenSocket()
static qsocket_t TCP_OpenSocket |
( |
const char * |
iface, |
|
|
int |
port, |
|
|
int |
family, |
|
|
netsrc_t |
who |
|
) |
| |
|
static |
Definition at line 1101 of file net.c.
1103 qsocket_t s, newsocket;
1104 struct addrinfo hints, *res, *rp;
1105 char buf[MAX_QPATH];
1106 const char *node, *service;
1109 Com_DPrintf(
"Opening TCP%s socket: %s:%d\n",
1110 (family == AF_INET6) ?
"6" :
"", iface, port);
1112 memset(&hints, 0,
sizeof(hints));
1113 hints.ai_flags = AI_PASSIVE;
1114 hints.ai_family = family;
1115 hints.ai_socktype = SOCK_STREAM;
1116 hints.ai_protocol = IPPROTO_TCP;
1125 if (port == PORT_ANY) {
1132 #ifdef AI_NUMERICSERV
1133 hints.ai_flags |= AI_NUMERICSERV;
1137 err = getaddrinfo(node, service, &hints, &res);
1139 Com_EPrintf(
"%s: %s:%d: bad interface address: %s\n",
1140 __func__, iface, port, gai_strerror(
err));
1145 for (rp = res; rp; rp = rp->ai_next) {
1146 s =
os_socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
1148 Com_EPrintf(
"%s: %s:%d: can't create socket: %s\n",
1155 Com_EPrintf(
"%s: %s:%d: can't make socket non-blocking: %s\n",
1161 if (who == NS_SERVER) {
1164 Com_WPrintf(
"%s: %s:%d: can't force socket to reuse address: %s\n",
1169 if (rp->ai_family == AF_INET6) {
1173 Com_WPrintf(
"%s: %s:%d: can't make socket IPv6-only: %s\n",
1179 if (
os_bind(s, rp->ai_addr, rp->ai_addrlen)) {
1180 Com_EPrintf(
"%s: %s:%d: can't bind socket: %s\n",
Referenced by NET_Connect(), NET_Listen4(), and NET_Listen6().
◆ UDP_OpenSocket()
static qsocket_t UDP_OpenSocket |
( |
const char * |
iface, |
|
|
int |
port, |
|
|
int |
family |
|
) |
| |
|
static |
Definition at line 983 of file net.c.
985 qsocket_t s, newsocket;
986 struct addrinfo hints, *res, *rp;
988 const char *node, *service;
991 Com_DPrintf(
"Opening UDP%s socket: %s:%d\n",
992 (family == AF_INET6) ?
"6" :
"", iface, port);
994 memset(&hints, 0,
sizeof(hints));
995 hints.ai_flags = AI_PASSIVE;
996 hints.ai_family = family;
997 hints.ai_socktype = SOCK_DGRAM;
998 hints.ai_protocol = IPPROTO_UDP;
1007 if (port == PORT_ANY) {
1014 #ifdef AI_NUMERICSERV
1015 hints.ai_flags |= AI_NUMERICSERV;
1019 err = getaddrinfo(node, service, &hints, &res);
1021 Com_EPrintf(
"%s: %s:%d: bad interface address: %s\n",
1022 __func__, iface, port, gai_strerror(
err));
1027 for (rp = res; rp; rp = rp->ai_next) {
1028 s =
os_socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
1030 Com_EPrintf(
"%s: %s:%d: can't create socket: %s\n",
1037 Com_EPrintf(
"%s: %s:%d: can't make socket non-blocking: %s\n",
1043 if (rp->ai_family == AF_INET) {
1046 Com_WPrintf(
"%s: %s:%d: can't make socket broadcast capable: %s\n",
1053 Com_WPrintf(
"%s: %s:%d: can't enable ICMP error queue: %s\n",
1058 #ifdef IP_MTU_DISCOVER
1060 if (
os_setsockopt(s, IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DONT)) {
1061 Com_WPrintf(
"%s: %s:%d: can't disable path MTU discovery: %s\n",
1067 if (rp->ai_family == AF_INET6) {
1071 Com_WPrintf(
"%s: %s:%d: can't enable ICMP6 error queue: %s\n",
1079 Com_WPrintf(
"%s: %s:%d: can't make socket IPv6-only: %s\n",
1085 if (
os_bind(s, rp->ai_addr, rp->ai_addrlen)) {
1086 Com_EPrintf(
"%s: %s:%d: can't bind socket: %s\n",
Referenced by NET_OpenServer(), and NET_OpenServer6().
◆ io_entries
ioentry_t io_entries[FD_SETSIZE] |
|
static |
◆ io_numfds
◆ net_active
◆ net_bytes_rcvd
◆ net_bytes_sent
◆ net_enable_ipv6
◆ net_error
Definition at line 110 of file net.c.
Referenced by NET_ErrorString(), NET_RunConnect(), os_bind(), os_connect(), os_get_error(), os_getsockname(), os_getsockopt(), os_listen(), os_make_nonblock(), os_select(), os_setsockopt(), os_socket(), os_udp_recv(), and os_udp_send().
◆ net_from
Definition at line 90 of file net.c.
Referenced by AC_ClientConnect(), CL_ConnectionlessPacket(), CL_DumpStatusResponse(), CL_FindRequest(), CL_PacketEvent(), CL_ParsePrintMessage(), find_client_slot(), NET_AcceptSocket(), NET_GetPackets(), NET_GetUdpPackets(), parse_packet_length(), permit_connection(), redirect(), send_connect_packet(), SV_ConnectionlessPacket(), SV_FlushRedirect(), SV_MvdRunClients(), SV_PacketEvent(), SVC_Ack(), SVC_DirectConnect(), SVC_GetChallenge(), SVC_Info(), SVC_Ping(), SVC_RemoteCommand(), SVC_Status(), UI_StatusEvent(), and userinfo_ip_string().
◆ net_ip
◆ net_ip6
◆ net_packets_rcvd
uint64_t net_packets_rcvd |
|
static |
◆ net_packets_sent
uint64_t net_packets_sent |
|
static |
◆ net_port
◆ net_rate_dn
◆ net_rate_rcvd
◆ net_rate_sent
◆ net_rate_time
◆ net_rate_up
◆ net_recv_errors
◆ net_send_errors
◆ tcp6_socket
qsocket_t tcp6_socket = -1 |
|
static |
◆ tcp_socket
qsocket_t tcp_socket = -1 |
|
static |
◆ udp6_sockets
qsocket_t udp6_sockets[NS_COUNT] = { -1, -1 } |
|
static |
◆ udp_sockets
qsocket_t udp_sockets[NS_COUNT] = { -1, -1 } |
|
static |
static qsocket_t os_get_fd(ioentry_t *e)
static cvar_t * net_enable_ipv6
static neterr_t NET_Listen4(qboolean arg)
static ssize_t os_recv(qsocket_t sock, void *data, size_t len, int flags)
static neterr_t os_bind(qsocket_t sock, const struct sockaddr *addr, size_t addrlen)
byte msg_read_buffer[MAX_MSGLEN]
char * NET_AdrToString(const netadr_t *a)
static neterr_t os_getsockname(qsocket_t sock, netadr_t *name)
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
static uint64_t net_packets_rcvd
static neterr_t os_connect(qsocket_t sock, const netadr_t *to)
static const char * NET_EnableIP6(void)
void Cmd_AddCommand(const char *name, xcommand_t function)
static qsocket_t TCP_OpenSocket(const char *iface, int port, int family, netsrc_t who)
void NET_RemoveFd(qsocket_t fd)
static void NET_Dns_f(void)
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
static ssize_t os_udp_recv(qsocket_t sock, void *data, size_t len, netadr_t *from)
static size_t net_rate_sent
static neterr_t os_accept(qsocket_t sock, qsocket_t *newsock, netadr_t *from)
static qsocket_t tcp6_socket
static uint64_t net_bytes_rcvd
static void os_closesocket(qsocket_t sock)
static size_t NET_UpRate_m(char *buffer, size_t size)
static ioentry_t * os_get_io(qsocket_t fd)
static void NET_OpenServer6(void)
float * tv(float x, float y, float z)
static qsocket_t udp_sockets[NS_COUNT]
static ioentry_t * os_add_io(qsocket_t fd)
static size_t NET_DnRate_m(char *buffer, size_t size)
static const char * os_error_string(int err)
void SZ_Init(sizebuf_t *buf, void *data, size_t size)
static uint64_t net_recv_errors
static neterr_t NET_Listen6(qboolean arg)
static int os_inet_pton(int af, const char *src, void *dst)
static qsocket_t UDP_OpenSocket(const char *iface, int port, int family)
static const char * os_inet_ntop(int af, const void *src, char *dst, size_t size)
void Com_Error(error_type_t type, const char *fmt,...)
void Cmd_RemoveCommand(const char *name)
neterr_t NET_Listen(qboolean arg)
static void NET_Stats_f(void)
static uint64_t net_packets_sent
size_t Com_FormatTime(char *buffer, size_t size, time_t t)
const char * NET_ErrorString(void)
char * NET_BaseAdrToString(const netadr_t *a)
void Cbuf_AddText(cmdbuf_t *buf, const char *text)
char * va(const char *format,...)
static qsocket_t os_socket(int domain, int type, int protocol)
static uint64_t net_bytes_sent
static struct addrinfo * NET_SearchAdrrInfo(struct addrinfo *rp, int family)
static void logfile_close(void)
static uint64_t net_send_errors
static void NET_SockadrToNetadr(const struct sockaddr_storage *s, netadr_t *a)
void NET_Config(netflag_t flag)
size_t Q_strlcpy(char *dst, const char *src, size_t size)
static size_t NET_NetadrToSockadr(const netadr_t *a, struct sockaddr_storage *s)
static neterr_t os_getsockopt(qsocket_t sock, int level, int name, int *val)
static ssize_t os_send(qsocket_t sock, const void *data, size_t len, int flags)
static neterr_t os_make_nonblock(qsocket_t sock, int val)
static void os_net_shutdown(void)
static void NET_OpenServer(void)
static ioentry_t io_entries[FD_SETSIZE]
qboolean COM_IsUint(const char *s)
ioentry_t * NET_AddFd(qsocket_t fd)
static neterr_t os_listen(qsocket_t sock, int backlog)
static void NET_ShowIP_f(void)
static size_t net_rate_rcvd
static void NET_GetUdpPackets(qsocket_t sock, void(*packet_cb)(void))
static int os_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
static neterr_t os_setsockopt(qsocket_t sock, int level, int name, int val)
qboolean NET_StringPairToAdr(const char *host, const char *port, netadr_t *a)
static q_noinline int diff(uint32_t A_u32, uint32_t B_u32)
size_t Cmd_ArgvBuffer(int arg, char *buffer, size_t size)
static neterr_t NET_AcceptSocket(netstream_t *s, qsocket_t sock)
static void os_net_init(void)
static unsigned net_rate_time
static ssize_t os_udp_send(qsocket_t sock, const void *data, size_t len, const netadr_t *to)
static size_t net_rate_dn
static void NET_Restart_f(void)
void Cmd_AddMacro(const char *name, xmacro_t function)
static qsocket_t tcp_socket
static qsocket_t udp6_sockets[NS_COUNT]
size_t Q_scnprintf(char *dest, size_t size, const char *fmt,...)
static void net_udp_param_changed(cvar_t *self)
static netflag_t net_active
static size_t net_rate_up
static void dump_socket(qsocket_t s, const char *s1, const char *s2)
static void dump_addrinfo(struct addrinfo *ai)