summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/DHT.c11
-rw-r--r--toxcore/DHT.h4
-rw-r--r--toxcore/onion.c12
3 files changed, 20 insertions, 7 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 594e3e7b..3e5486a5 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -164,12 +164,17 @@ void to_net_family(IP *ip)
164 ip->family = TOX_AF_INET6; 164 ip->family = TOX_AF_INET6;
165} 165}
166 166
167void to_host_family(IP *ip) 167int to_host_family(IP *ip)
168{ 168{
169 if (ip->family == TOX_AF_INET) 169 if (ip->family == TOX_AF_INET) {
170 ip->family = AF_INET; 170 ip->family = AF_INET;
171 else if (ip->family == TOX_AF_INET6) 171 return 0;
172 } else if (ip->family == TOX_AF_INET6) {
172 ip->family = AF_INET6; 173 ip->family = AF_INET6;
174 return 0;
175 } else {
176 return -1;
177 }
173} 178}
174 179
175/* Pack number of nodes into data of maxlength length. 180/* Pack number of nodes into data of maxlength length.
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index 3f7a820e..547f3887 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -65,7 +65,9 @@
65 65
66/* Functions to transfer ips safely across wire. */ 66/* Functions to transfer ips safely across wire. */
67void to_net_family(IP *ip); 67void to_net_family(IP *ip);
68void to_host_family(IP *ip); 68
69/* return 0 on success, -1 on failure. */
70int to_host_family(IP *ip);
69 71
70typedef struct { 72typedef struct {
71 IP_Port ip_port; 73 IP_Port ip_port;
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 0982a2b0..1ce8146e 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -294,7 +294,9 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
294 294
295 IP_Port send_to; 295 IP_Port send_to;
296 ipport_unpack(&send_to, plain); 296 ipport_unpack(&send_to, plain);
297 to_host_family(&send_to.ip); 297
298 if (to_host_family(&send_to.ip) == -1)
299 return 1;
298 300
299 uint8_t ip_port[SIZE_IPPORT]; 301 uint8_t ip_port[SIZE_IPPORT];
300 ipport_pack(ip_port, &source); 302 ipport_pack(ip_port, &source);
@@ -343,7 +345,9 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
343 345
344 IP_Port send_to; 346 IP_Port send_to;
345 ipport_unpack(&send_to, plain); 347 ipport_unpack(&send_to, plain);
346 to_host_family(&send_to.ip); 348
349 if (to_host_family(&send_to.ip) == -1)
350 return 1;
347 351
348 uint8_t data[ONION_MAX_PACKET_SIZE]; 352 uint8_t data[ONION_MAX_PACKET_SIZE];
349 data[0] = NET_PACKET_ONION_SEND_2; 353 data[0] = NET_PACKET_ONION_SEND_2;
@@ -392,7 +396,9 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
392 396
393 IP_Port send_to; 397 IP_Port send_to;
394 ipport_unpack(&send_to, plain); 398 ipport_unpack(&send_to, plain);
395 to_host_family(&send_to.ip); 399
400 if (to_host_family(&send_to.ip) == -1)
401 return 1;
396 402
397 uint8_t data[ONION_MAX_PACKET_SIZE]; 403 uint8_t data[ONION_MAX_PACKET_SIZE];
398 memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT); 404 memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT);