diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 6 | ||||
-rw-r--r-- | toxcore/network.c | 37 | ||||
-rw-r--r-- | toxcore/network.h | 16 |
3 files changed, 56 insertions, 3 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 3f3aef05..151f59d3 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -115,7 +115,7 @@ static int client_id_cmp(ClientPair p1, ClientPair p2) | |||
115 | return c; | 115 | return c; |
116 | } | 116 | } |
117 | 117 | ||
118 | static int ipport_equal(IP_Port a, IP_Port b) | 118 | static int ip4port_equal(IP_Port a, IP_Port b) |
119 | { | 119 | { |
120 | return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port); | 120 | return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port); |
121 | } | 121 | } |
@@ -144,7 +144,7 @@ static int client_in_list(Client_data *list, uint32_t length, uint8_t *client_id | |||
144 | 144 | ||
145 | for (i = 0; i < length; ++i) { | 145 | for (i = 0; i < length; ++i) { |
146 | /* If ip_port is assigned to a different client_id replace it */ | 146 | /* If ip_port is assigned to a different client_id replace it */ |
147 | if (ipport_equal(list[i].ip_port, ip_port)) { | 147 | if (ip4port_equal(list[i].ip_port, ip_port)) { |
148 | memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); | 148 | memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); |
149 | } | 149 | } |
150 | 150 | ||
@@ -447,7 +447,7 @@ static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id) | |||
447 | if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) { | 447 | if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) { |
448 | pinging = 0; | 448 | pinging = 0; |
449 | 449 | ||
450 | if (ip_port.ip.uint32 != 0 && ipport_equal(dht->send_nodes[i].ip_port, ip_port)) | 450 | if (ip_port.ip.uint32 != 0 && ip4port_equal(dht->send_nodes[i].ip_port, ip_port)) |
451 | ++pinging; | 451 | ++pinging; |
452 | 452 | ||
453 | if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id) | 453 | if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id) |
diff --git a/toxcore/network.c b/toxcore/network.c index 31da833c..1fb5b77a 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -235,6 +235,43 @@ void kill_networking(Networking_Core *net) | |||
235 | return; | 235 | return; |
236 | } | 236 | } |
237 | 237 | ||
238 | /* ip_equal | ||
239 | * compares two IPAny structures | ||
240 | * unset means unequal | ||
241 | * | ||
242 | * returns 0 when not equal or when uninitialized | ||
243 | */ | ||
244 | int ip_equal(IPAny *a, IPAny *b) | ||
245 | { | ||
246 | if (!a || !b) | ||
247 | return 0; | ||
248 | |||
249 | if (a->family == AF_INET) | ||
250 | return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); | ||
251 | |||
252 | if (a->family == AF_INET6) | ||
253 | return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6); | ||
254 | |||
255 | return 0; | ||
256 | }; | ||
257 | |||
258 | /* ipport_equal | ||
259 | * compares two IPAny_Port structures | ||
260 | * unset means unequal | ||
261 | * | ||
262 | * returns 0 when not equal or when uninitialized | ||
263 | */ | ||
264 | int ipport_equal(IPAny_Port *a, IPAny_Port *b) | ||
265 | { | ||
266 | if (!a || !b) | ||
267 | return 0; | ||
268 | |||
269 | if (!a->port || (a->port != b->port)) | ||
270 | return 0; | ||
271 | |||
272 | return ip_equal(&a->ip, &b->ip); | ||
273 | }; | ||
274 | |||
238 | /* ipany_ntoa | 275 | /* ipany_ntoa |
239 | * converts ip into a string | 276 | * converts ip into a string |
240 | * uses a static buffer, so mustn't used multiple times in the same output | 277 | * uses a static buffer, so mustn't used multiple times in the same output |
diff --git a/toxcore/network.h b/toxcore/network.h index 15ca68e3..d52a02ae 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -115,6 +115,22 @@ typedef union { | |||
115 | uint8_t uint8[8]; | 115 | uint8_t uint8[8]; |
116 | } IP_Port; | 116 | } IP_Port; |
117 | 117 | ||
118 | |||
119 | /* will replace IP_Port as soon as the complete infrastructure is in place | ||
120 | * removed the unused union and padding also */ | ||
121 | typedef struct { | ||
122 | IPAny ip; | ||
123 | uint16_t port; | ||
124 | } IPAny_Port; | ||
125 | |||
126 | /* ipport_equal | ||
127 | * compares two IPAny_Port structures | ||
128 | * unset means unequal | ||
129 | * | ||
130 | * returns 0 when not equal or when uninitialized | ||
131 | */ | ||
132 | int ipport_equal(IPAny_Port *a, IPAny_Port *b); | ||
133 | |||
118 | typedef struct { | 134 | typedef struct { |
119 | int16_t family; | 135 | int16_t family; |
120 | uint16_t port; | 136 | uint16_t port; |