summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authorDiadlo <polsha3@gmail.com>2017-11-14 20:14:06 +0300
committerDiadlo <polsha3@gmail.com>2017-11-15 15:21:39 +0300
commitd037f938111c148c6956b58ebfba717e7c7cfb00 (patch)
treea5fce4555ee485686c1c74333139659d066eda67 /toxcore/network.c
parentbb5f8a17103537caa09bcf14130debe3210fb61f (diff)
Fix IPv4 and IPv6 loopbacks
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index aeaf4d79..5c43bf57 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -138,21 +138,6 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
138 138
139#endif 139#endif
140 140
141#if !defined(INADDR_LOOPBACK)
142#define INADDR_LOOPBACK 0x7f000001
143#endif
144
145const IP4 IP4_LOOPBACK = { INADDR_LOOPBACK };
146const IP6 IP6_LOOPBACK = {
147 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
148};
149
150
151const IP4 IP4_BROADCAST = { INADDR_BROADCAST };
152const IP6 IP6_BROADCAST = {
153 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
154};
155
156#if TOX_INET6_ADDRSTRLEN < INET6_ADDRSTRLEN 141#if TOX_INET6_ADDRSTRLEN < INET6_ADDRSTRLEN
157#error TOX_INET6_ADDRSTRLEN should be greater or equal to INET6_ADDRSTRLEN (#INET6_ADDRSTRLEN) 142#error TOX_INET6_ADDRSTRLEN should be greater or equal to INET6_ADDRSTRLEN (#INET6_ADDRSTRLEN)
158#endif 143#endif
@@ -188,6 +173,29 @@ static void fill_addr6(IP6 ip, struct in6_addr *addr)
188 memcpy(addr->s6_addr, ip.uint8, sizeof(ip.uint8)); 173 memcpy(addr->s6_addr, ip.uint8, sizeof(ip.uint8));
189} 174}
190 175
176#if !defined(INADDR_LOOPBACK)
177#define INADDR_LOOPBACK 0x7f000001
178#endif
179
180const IP4 IP4_BROADCAST = { INADDR_BROADCAST };
181const IP6 IP6_BROADCAST = {
182 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
183};
184
185IP4 get_ip4_loopback()
186{
187 IP4 loopback;
188 loopback.uint32 = htonl(INADDR_LOOPBACK);
189 return loopback;
190}
191
192IP6 get_ip6_loopback()
193{
194 IP6 loopback;
195 get_ip6(&loopback, &in6addr_loopback);
196 return loopback;
197}
198
191/* Check if socket is valid. 199/* Check if socket is valid.
192 * 200 *
193 * return 1 if valid 201 * return 1 if valid
@@ -1436,4 +1444,3 @@ uint16_t net_ntohs(uint16_t hostshort)
1436{ 1444{
1437 return ntohs(hostshort); 1445 return ntohs(hostshort);
1438} 1446}
1439