summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/network.c66
-rw-r--r--toxcore/network.h2
2 files changed, 67 insertions, 1 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index af9e8cdd..62bb4c34 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -32,6 +32,72 @@
32#define IPV6_V6ONLY 27 32#define IPV6_V6ONLY 27
33#endif 33#endif
34 34
35#ifdef WIN32
36
37static const char *inet_ntop(sa_family_t family, void *addr, char *buf, size_t bufsize)
38{
39 if(family == AF_INET)
40 {
41 struct sockaddr_in saddr = { 0 };
42 saddr.sin_family = AF_INET;
43 saddr.sin_addr = *(struct in_addr*)addr;
44
45 DWORD len = bufsize;
46 if(WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len))
47 return NULL;
48
49 return buf;
50 }
51 else if(family == AF_INET6)
52 {
53 struct sockaddr_in6 saddr = { 0 };
54 saddr.sin6_family = AF_INET6;
55 saddr.sin6_addr = *(struct in6_addr*)addr;
56
57 DWORD len = bufsize;
58 if(WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len))
59 return NULL;
60
61 return buf;
62 }
63
64 return NULL;
65}
66
67static int inet_pton(sa_family_t family, const char *addrString, void *addrbuf)
68{
69 if(family == AF_INET)
70 {
71 struct sockaddr_in saddr = { 0 };
72
73 INT len = sizeof(saddr);
74
75 if(WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len))
76 return 0;
77
78 *(struct in_addr*)addrbuf = saddr.sin_addr;
79
80 return 1;
81 }
82 else if(family == AF_INET6)
83 {
84 struct sockaddr_in6 saddr = { 0 };
85
86 INT len = sizeof(saddr);
87
88 if(WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len))
89 return 0;
90
91 *(struct in6_addr*)addrbuf = saddr.sin6_addr;
92
93 return 1;
94 }
95
96 return 0;
97}
98
99#endif
100
35/* return current UNIX time in microseconds (us). */ 101/* return current UNIX time in microseconds (us). */
36uint64_t current_time(void) 102uint64_t current_time(void)
37{ 103{
diff --git a/toxcore/network.h b/toxcore/network.h
index f6256ab4..0d2b5786 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -40,7 +40,7 @@
40#include <ws2tcpip.h> 40#include <ws2tcpip.h>
41 41
42typedef unsigned int sock_t; 42typedef unsigned int sock_t;
43typedef unsigned int sa_family_t; 43typedef INT sa_family_t;
44 44
45#ifndef IN6_ARE_ADDR_EQUAL 45#ifndef IN6_ARE_ADDR_EQUAL
46#define IN6_ARE_ADDR_EQUAL(a,b) \ 46#define IN6_ARE_ADDR_EQUAL(a,b) \