summaryrefslogtreecommitdiff
path: root/src/common/net/net.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2014-11-30 19:59:24 +0300
committerAndrey Nazarov <skuller@skuller.net>2014-12-01 23:04:39 +0300
commit7525450fb6d79d7371375d7f710ba4fe484494b3 (patch)
treed4c85624c0d73900c26cc22518a0bc524e592471 /src/common/net/net.c
parent3762fe5c58439fc146325ea8707333bfead13317 (diff)
Add inet_ntop() and inet_pton() replacements for Windows.
These are implemented only on Vista and later. For XP sake, import replacement functions from liblwres included in ISC BIND distribution.
Diffstat (limited to 'src/common/net/net.c')
-rw-r--r--src/common/net/net.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/common/net/net.c b/src/common/net/net.c
index 19fe13f..8b65d72 100644
--- a/src/common/net/net.c
+++ b/src/common/net/net.c
@@ -202,6 +202,17 @@ static void NET_SockadrToNetadr(const struct sockaddr_storage *s, netadr_t *a)
}
}
+#ifdef _WIN32
+#define NS_INT16SZ 2
+#define NS_INADDRSZ 4
+#define NS_IN6ADDRSZ 16
+#include "inet_ntop.h"
+#include "inet_pton.h"
+#else
+#define os_inet_ntop inet_ntop
+#define os_inet_pton inet_pton
+#endif
+
char *NET_BaseAdrToString(const netadr_t *a)
{
static char s[MAX_QPATH];
@@ -213,7 +224,7 @@ char *NET_BaseAdrToString(const netadr_t *a)
return strcpy(s, "loopback");
case NA_IP:
case NA_BROADCAST:
- if (inet_ntop(AF_INET, &a->ip, s, sizeof(s)))
+ if (os_inet_ntop(AF_INET, &a->ip, s, sizeof(s)))
return s;
else
return strcpy(s, "<invalid>");
@@ -227,7 +238,7 @@ char *NET_BaseAdrToString(const netadr_t *a)
s, sizeof(s), NULL, 0, NI_NUMERICHOST) == 0)
return s;
}
- if (inet_ntop(AF_INET6, &a->ip, s, sizeof(s)))
+ if (os_inet_ntop(AF_INET6, &a->ip, s, sizeof(s)))
return s;
else
return strcpy(s, "<invalid>");
@@ -281,8 +292,8 @@ qboolean NET_StringPairToAdr(const char *host, const char *port, netadr_t *a)
if (net_enable_ipv6->integer < 1)
hints.ai_family = AF_INET;
- if (inet_pton(AF_INET, host, buf) == 1 ||
- inet_pton(AF_INET6, host, buf) == 1)
+ if (os_inet_pton(AF_INET, host, buf) == 1 ||
+ os_inet_pton(AF_INET6, host, buf) == 1)
hints.ai_flags |= AI_NUMERICHOST;
#ifdef AI_NUMERICSERV