diff options
author | Diadlo <polsha3@gmail.com> | 2017-03-02 23:15:51 +0300 |
---|---|---|
committer | Diadlo <polsha3@gmail.com> | 2017-08-24 20:09:08 +0300 |
commit | 66b8a7685e8fdecd6104f01f840f5d792ce1e041 (patch) | |
tree | 7c65281aefeb21c55ba422ff7d9587675eeb7070 | |
parent | 8f19c926c0d5231ede61a831050664103e54000e (diff) |
AF_INET -> TOX_AF_INET
-rw-r--r-- | auto_tests/TCP_test.c | 12 | ||||
-rw-r--r-- | auto_tests/dht_test.c | 32 | ||||
-rw-r--r-- | auto_tests/network_test.c | 32 | ||||
-rw-r--r-- | testing/dns3_test.c | 2 | ||||
-rw-r--r-- | toxcore/DHT.c | 64 | ||||
-rw-r--r-- | toxcore/DHT.h | 6 | ||||
-rw-r--r-- | toxcore/LAN_discovery.c | 44 | ||||
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/TCP_client.c | 13 | ||||
-rw-r--r-- | toxcore/TCP_connection.c | 10 | ||||
-rw-r--r-- | toxcore/TCP_server.c | 6 | ||||
-rw-r--r-- | toxcore/friend_connection.c | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 18 | ||||
-rw-r--r-- | toxcore/network.c | 121 | ||||
-rw-r--r-- | toxcore/network.h | 29 | ||||
-rw-r--r-- | toxcore/onion.c | 13 | ||||
-rw-r--r-- | toxcore/onion.h | 4 | ||||
-rw-r--r-- | toxcore/onion_client.c | 8 | ||||
-rw-r--r-- | toxcore/ping.c | 2 | ||||
-rw-r--r-- | toxcore/tox.c | 4 |
20 files changed, 226 insertions, 198 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index f8412832..fbbb08cd 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -34,7 +34,7 @@ START_TEST(test_basic) | |||
34 | 34 | ||
35 | Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); | 35 | Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); |
36 | IP_Port ip_port_loopback; | 36 | IP_Port ip_port_loopback; |
37 | ip_port_loopback.ip.family = AF_INET6; | 37 | ip_port_loopback.ip.family = TOX_AF_INET6; |
38 | ip_port_loopback.ip.ip6.uint64[0] = 0; | 38 | ip_port_loopback.ip.ip6.uint64[0] = 0; |
39 | ip_port_loopback.ip.ip6.uint64[1] = 0; | 39 | ip_port_loopback.ip.ip6.uint64[1] = 0; |
40 | ip_port_loopback.ip.ip6.uint8[15] = 1; // ::1 | 40 | ip_port_loopback.ip.ip6.uint8[15] = 1; // ::1 |
@@ -135,7 +135,7 @@ static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | |||
135 | Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); | 135 | Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); |
136 | 136 | ||
137 | IP_Port ip_port_loopback; | 137 | IP_Port ip_port_loopback; |
138 | ip_port_loopback.ip.family = AF_INET6; | 138 | ip_port_loopback.ip.family = TOX_AF_INET6; |
139 | ip_port_loopback.ip.ip6.uint64[0] = 0; | 139 | ip_port_loopback.ip.ip6.uint64[0] = 0; |
140 | ip_port_loopback.ip.ip6.uint64[1] = 0; | 140 | ip_port_loopback.ip.ip6.uint64[1] = 0; |
141 | ip_port_loopback.ip.ip6.uint8[15] = 1; // ::1 | 141 | ip_port_loopback.ip.ip6.uint8[15] = 1; // ::1 |
@@ -405,7 +405,7 @@ START_TEST(test_client) | |||
405 | IP_Port ip_port_tcp_s; | 405 | IP_Port ip_port_tcp_s; |
406 | 406 | ||
407 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); | 407 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); |
408 | ip_port_tcp_s.ip.family = AF_INET6; | 408 | ip_port_tcp_s.ip.family = TOX_AF_INET6; |
409 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); | 409 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
410 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); | 410 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); |
411 | c_sleep(50); | 411 | c_sleep(50); |
@@ -503,7 +503,7 @@ START_TEST(test_client_invalid) | |||
503 | IP_Port ip_port_tcp_s; | 503 | IP_Port ip_port_tcp_s; |
504 | 504 | ||
505 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); | 505 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); |
506 | ip_port_tcp_s.ip.family = AF_INET6; | 506 | ip_port_tcp_s.ip.family = TOX_AF_INET6; |
507 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); | 507 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
508 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); | 508 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); |
509 | c_sleep(50); | 509 | c_sleep(50); |
@@ -572,7 +572,7 @@ START_TEST(test_tcp_connection) | |||
572 | IP_Port ip_port_tcp_s; | 572 | IP_Port ip_port_tcp_s; |
573 | 573 | ||
574 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); | 574 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); |
575 | ip_port_tcp_s.ip.family = AF_INET6; | 575 | ip_port_tcp_s.ip.family = TOX_AF_INET6; |
576 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); | 576 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
577 | 577 | ||
578 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); | 578 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); |
@@ -681,7 +681,7 @@ START_TEST(test_tcp_connection2) | |||
681 | IP_Port ip_port_tcp_s; | 681 | IP_Port ip_port_tcp_s; |
682 | 682 | ||
683 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); | 683 | ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); |
684 | ip_port_tcp_s.ip.family = AF_INET6; | 684 | ip_port_tcp_s.ip.family = TOX_AF_INET6; |
685 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); | 685 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
686 | 686 | ||
687 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); | 687 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); |
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index c04b67e4..5a4f8005 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -99,7 +99,7 @@ static void test_addto_lists_update(DHT *dht, | |||
99 | int used, test, test1, test2, found; | 99 | int used, test, test1, test2, found; |
100 | IP_Port test_ipp; | 100 | IP_Port test_ipp; |
101 | uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; | 101 | uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; |
102 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 102 | uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; |
103 | 103 | ||
104 | // check id update for existing ip_port | 104 | // check id update for existing ip_port |
105 | test = rand() % length; | 105 | test = rand() % length; |
@@ -174,7 +174,7 @@ static void test_addto_lists_bad(DHT *dht, | |||
174 | int used, test1, test2, test3; | 174 | int used, test1, test2, test3; |
175 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], | 175 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], |
176 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; | 176 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; |
177 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 177 | uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; |
178 | 178 | ||
179 | random_bytes(public_key, sizeof(public_key)); | 179 | random_bytes(public_key, sizeof(public_key)); |
180 | mark_all_good(list, length, ipv6); | 180 | mark_all_good(list, length, ipv6); |
@@ -218,7 +218,7 @@ static void test_addto_lists_possible_bad(DHT *dht, | |||
218 | int used, test1, test2, test3; | 218 | int used, test1, test2, test3; |
219 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], | 219 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], |
220 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; | 220 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; |
221 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 221 | uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; |
222 | 222 | ||
223 | random_bytes(public_key, sizeof(public_key)); | 223 | random_bytes(public_key, sizeof(public_key)); |
224 | mark_all_good(list, length, ipv6); | 224 | mark_all_good(list, length, ipv6); |
@@ -280,7 +280,7 @@ static void test_addto_lists_good(DHT *dht, | |||
280 | const uint8_t *comp_client_id) | 280 | const uint8_t *comp_client_id) |
281 | { | 281 | { |
282 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 282 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
283 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 283 | uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; |
284 | 284 | ||
285 | mark_all_good(list, length, ipv6); | 285 | mark_all_good(list, length, ipv6); |
286 | 286 | ||
@@ -703,10 +703,10 @@ static void random_ip(IP_Port *ipp, int family) | |||
703 | uint8_t *ip = NULL; | 703 | uint8_t *ip = NULL; |
704 | size_t size; | 704 | size_t size; |
705 | 705 | ||
706 | if (family == AF_INET || family == TCP_INET) { | 706 | if (family == TOX_AF_INET || family == TCP_INET) { |
707 | ip = (uint8_t *)&ipp->ip.ip4; | 707 | ip = (uint8_t *)&ipp->ip.ip4; |
708 | size = sizeof(ipp->ip.ip4); | 708 | size = sizeof(ipp->ip.ip4); |
709 | } else if (family == AF_INET6 || family == TCP_INET6) { | 709 | } else if (family == TOX_AF_INET6 || family == TCP_INET6) { |
710 | ip = (uint8_t *)&ipp->ip.ip6; | 710 | ip = (uint8_t *)&ipp->ip.ip6; |
711 | size = sizeof(ipp->ip.ip6); | 711 | size = sizeof(ipp->ip.ip6); |
712 | } else { | 712 | } else { |
@@ -734,18 +734,18 @@ START_TEST(test_dht_node_packing) | |||
734 | random_bytes(nodes[1].public_key, pk_size); | 734 | random_bytes(nodes[1].public_key, pk_size); |
735 | random_bytes(nodes[2].public_key, pk_size); | 735 | random_bytes(nodes[2].public_key, pk_size); |
736 | 736 | ||
737 | random_ip(&nodes[0].ip_port, AF_INET); | 737 | random_ip(&nodes[0].ip_port, TOX_AF_INET); |
738 | random_ip(&nodes[1].ip_port, AF_INET); | 738 | random_ip(&nodes[1].ip_port, TOX_AF_INET); |
739 | random_ip(&nodes[2].ip_port, AF_INET); | 739 | random_ip(&nodes[2].ip_port, TOX_AF_INET); |
740 | dht_pack_unpack(nodes, 3, data, length); | 740 | dht_pack_unpack(nodes, 3, data, length); |
741 | 741 | ||
742 | random_ip(&nodes[0].ip_port, AF_INET); | 742 | random_ip(&nodes[0].ip_port, TOX_AF_INET); |
743 | random_ip(&nodes[1].ip_port, AF_INET); | 743 | random_ip(&nodes[1].ip_port, TOX_AF_INET); |
744 | random_ip(&nodes[2].ip_port, TCP_INET); | 744 | random_ip(&nodes[2].ip_port, TCP_INET); |
745 | dht_pack_unpack(nodes, 3, data, length); | 745 | dht_pack_unpack(nodes, 3, data, length); |
746 | 746 | ||
747 | random_ip(&nodes[0].ip_port, AF_INET); | 747 | random_ip(&nodes[0].ip_port, TOX_AF_INET); |
748 | random_ip(&nodes[1].ip_port, AF_INET6); | 748 | random_ip(&nodes[1].ip_port, TOX_AF_INET6); |
749 | random_ip(&nodes[2].ip_port, TCP_INET6); | 749 | random_ip(&nodes[2].ip_port, TCP_INET6); |
750 | dht_pack_unpack(nodes, 3, data, length); | 750 | dht_pack_unpack(nodes, 3, data, length); |
751 | 751 | ||
@@ -754,9 +754,9 @@ START_TEST(test_dht_node_packing) | |||
754 | random_ip(&nodes[2].ip_port, TCP_INET); | 754 | random_ip(&nodes[2].ip_port, TCP_INET); |
755 | dht_pack_unpack(nodes, 3, data, length); | 755 | dht_pack_unpack(nodes, 3, data, length); |
756 | 756 | ||
757 | random_ip(&nodes[0].ip_port, AF_INET6); | 757 | random_ip(&nodes[0].ip_port, TOX_AF_INET6); |
758 | random_ip(&nodes[1].ip_port, AF_INET6); | 758 | random_ip(&nodes[1].ip_port, TOX_AF_INET6); |
759 | random_ip(&nodes[2].ip_port, AF_INET6); | 759 | random_ip(&nodes[2].ip_port, TOX_AF_INET6); |
760 | dht_pack_unpack(nodes, 3, data, length); | 760 | dht_pack_unpack(nodes, 3, data, length); |
761 | 761 | ||
762 | free(data); | 762 | free(data); |
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 67090f74..4a05d5c3 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -37,7 +37,7 @@ START_TEST(test_addr_resolv_localhost) | |||
37 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 37 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
38 | 38 | ||
39 | char ip_str[IP_NTOA_LEN]; | 39 | char ip_str[IP_NTOA_LEN]; |
40 | ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family); | 40 | ck_assert_msg(ip.family == TOX_AF_INET, "Expected family TOX_AF_INET, got %u.", ip.family); |
41 | ck_assert_msg(ip.ip4.uint32 == net_htonl(0x7F000001), "Expected 127.0.0.1, got %s.", | 41 | ck_assert_msg(ip.ip4.uint32 == net_htonl(0x7F000001), "Expected 127.0.0.1, got %s.", |
42 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 42 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
43 | 43 | ||
@@ -51,7 +51,7 @@ START_TEST(test_addr_resolv_localhost) | |||
51 | 51 | ||
52 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 52 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
53 | 53 | ||
54 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); | 54 | ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family); |
55 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", | 55 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", |
56 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 56 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
57 | 57 | ||
@@ -67,11 +67,11 @@ START_TEST(test_addr_resolv_localhost) | |||
67 | res = addr_resolve(localhost, &ip, &extra); | 67 | res = addr_resolve(localhost, &ip, &extra); |
68 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 68 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
69 | 69 | ||
70 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); | 70 | ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family); |
71 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", | 71 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", |
72 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 72 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
73 | 73 | ||
74 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET (%u), got %u.", AF_INET, extra.family); | 74 | ck_assert_msg(extra.family == TOX_AF_INET, "Expected family TOX_AF_INET (%u), got %u.", TOX_AF_INET, extra.family); |
75 | ck_assert_msg(extra.ip4.uint32 == net_htonl(0x7F000001), "Expected 127.0.0.1, got %s.", | 75 | ck_assert_msg(extra.ip4.uint32 == net_htonl(0x7F000001), "Expected 127.0.0.1, got %s.", |
76 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 76 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
77 | } | 77 | } |
@@ -93,24 +93,27 @@ START_TEST(test_ip_equal) | |||
93 | res = ip_equal(NULL, &ip1); | 93 | res = ip_equal(NULL, &ip1); |
94 | ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res); | 94 | ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res); |
95 | 95 | ||
96 | ip1.family = AF_INET; | 96 | ip1.family = TOX_AF_INET; |
97 | ip1.ip4.uint32 = net_htonl(0x7F000001); | 97 | ip1.ip4.uint32 = net_htonl(0x7F000001); |
98 | 98 | ||
99 | res = ip_equal(&ip1, &ip2); | 99 | res = ip_equal(&ip1, &ip2); |
100 | ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_UNSPEC, 0} ): expected result 0, got %u.", res); | 100 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {AF_UNSPEC, 0} ): " |
101 | "expected result 0, got %u.", res); | ||
101 | 102 | ||
102 | ip2.family = AF_INET; | 103 | ip2.family = TOX_AF_INET; |
103 | ip2.ip4.uint32 = net_htonl(0x7F000001); | 104 | ip2.ip4.uint32 = net_htonl(0x7F000001); |
104 | 105 | ||
105 | res = ip_equal(&ip1, &ip2); | 106 | res = ip_equal(&ip1, &ip2); |
106 | ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.1} ): expected result != 0, got 0."); | 107 | ck_assert_msg(res != 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET, 127.0.0.1} ): " |
108 | "expected result != 0, got 0."); | ||
107 | 109 | ||
108 | ip2.ip4.uint32 = net_htonl(0x7F000002); | 110 | ip2.ip4.uint32 = net_htonl(0x7F000002); |
109 | 111 | ||
110 | res = ip_equal(&ip1, &ip2); | 112 | res = ip_equal(&ip1, &ip2); |
111 | ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.2} ): expected result 0, got %u.", res); | 113 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET, 127.0.0.2} ): " |
114 | "expected result 0, got %u.", res); | ||
112 | 115 | ||
113 | ip2.family = AF_INET6; | 116 | ip2.family = TOX_AF_INET6; |
114 | ip2.ip6.uint32[0] = 0; | 117 | ip2.ip6.uint32[0] = 0; |
115 | ip2.ip6.uint32[1] = 0; | 118 | ip2.ip6.uint32[1] = 0; |
116 | ip2.ip6.uint32[2] = net_htonl(0xFFFF); | 119 | ip2.ip6.uint32[2] = net_htonl(0xFFFF); |
@@ -120,19 +123,20 @@ START_TEST(test_ip_equal) | |||
120 | "IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0."); | 123 | "IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0."); |
121 | 124 | ||
122 | res = ip_equal(&ip1, &ip2); | 125 | res = ip_equal(&ip1, &ip2); |
123 | ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0."); | 126 | ck_assert_msg(res != 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET6, ::ffff:127.0.0.1} ): " |
127 | "expected result != 0, got 0."); | ||
124 | 128 | ||
125 | memcpy(&ip2.ip6, &in6addr_loopback, sizeof(IP6)); | 129 | memcpy(&ip2.ip6, &in6addr_loopback, sizeof(IP6)); |
126 | res = ip_equal(&ip1, &ip2); | 130 | res = ip_equal(&ip1, &ip2); |
127 | ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::1} ): expected result 0, got %u.", res); | 131 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET6, ::1} ): expected result 0, got %u.", res); |
128 | 132 | ||
129 | memcpy(&ip1, &ip2, sizeof(IP)); | 133 | memcpy(&ip1, &ip2, sizeof(IP)); |
130 | res = ip_equal(&ip1, &ip2); | 134 | res = ip_equal(&ip1, &ip2); |
131 | ck_assert_msg(res != 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::1} ): expected result != 0, got 0."); | 135 | ck_assert_msg(res != 0, "ip_equal( {TOX_AF_INET6, ::1}, {TOX_AF_INET6, ::1} ): expected result != 0, got 0."); |
132 | 136 | ||
133 | ip2.ip6.uint8[15]++; | 137 | ip2.ip6.uint8[15]++; |
134 | res = ip_equal(&ip1, &ip2); | 138 | res = ip_equal(&ip1, &ip2); |
135 | ck_assert_msg(res == 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::2} ): expected result 0, got %res.", res); | 139 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET6, ::1}, {TOX_AF_INET6, ::2} ): expected result 0, got %res.", res); |
136 | } | 140 | } |
137 | END_TEST | 141 | END_TEST |
138 | 142 | ||
diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 4c03fc52..0df7ace2 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c | |||
@@ -40,7 +40,7 @@ int main(int argc, char *argv[]) | |||
40 | } | 40 | } |
41 | 41 | ||
42 | IP ip = {0}; | 42 | IP ip = {0}; |
43 | ip.family = AF_INET; | 43 | ip.family = TOX_AF_INET; |
44 | Socket sock = net_socket(ip.family, TOX_SOCK_DGRAM, TOX_PROTO_UDP); | 44 | Socket sock = net_socket(ip.family, TOX_SOCK_DGRAM, TOX_PROTO_UDP); |
45 | 45 | ||
46 | if (!sock_valid(sock)) { | 46 | if (!sock_valid(sock)) { |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index e12c4d64..193cb632 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -258,9 +258,9 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke | |||
258 | 258 | ||
259 | void to_net_family(IP *ip) | 259 | void to_net_family(IP *ip) |
260 | { | 260 | { |
261 | if (ip->family == AF_INET) { | 261 | if (ip->family == TOX_AF_INET) { |
262 | ip->family = TOX_AF_INET; | 262 | ip->family = TOX_AF_INET; |
263 | } else if (ip->family == AF_INET6) { | 263 | } else if (ip->family == TOX_AF_INET6) { |
264 | ip->family = TOX_AF_INET6; | 264 | ip->family = TOX_AF_INET6; |
265 | } | 265 | } |
266 | } | 266 | } |
@@ -268,12 +268,12 @@ void to_net_family(IP *ip) | |||
268 | int to_host_family(IP *ip) | 268 | int to_host_family(IP *ip) |
269 | { | 269 | { |
270 | if (ip->family == TOX_AF_INET) { | 270 | if (ip->family == TOX_AF_INET) { |
271 | ip->family = AF_INET; | 271 | ip->family = TOX_AF_INET; |
272 | return 0; | 272 | return 0; |
273 | } | 273 | } |
274 | 274 | ||
275 | if (ip->family == TOX_AF_INET6) { | 275 | if (ip->family == TOX_AF_INET6) { |
276 | ip->family = AF_INET6; | 276 | ip->family = TOX_AF_INET6; |
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | 279 | ||
@@ -289,11 +289,11 @@ int to_host_family(IP *ip) | |||
289 | int packed_node_size(uint8_t ip_family) | 289 | int packed_node_size(uint8_t ip_family) |
290 | { | 290 | { |
291 | switch (ip_family) { | 291 | switch (ip_family) { |
292 | case AF_INET: | 292 | case TOX_AF_INET: |
293 | case TCP_INET: | 293 | case TCP_INET: |
294 | return PACKED_NODE_SIZE_IP4; | 294 | return PACKED_NODE_SIZE_IP4; |
295 | 295 | ||
296 | case AF_INET6: | 296 | case TOX_AF_INET6: |
297 | case TCP_INET6: | 297 | case TCP_INET6: |
298 | return PACKED_NODE_SIZE_IP6; | 298 | return PACKED_NODE_SIZE_IP6; |
299 | 299 | ||
@@ -317,14 +317,14 @@ static int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port) | |||
317 | bool is_ipv4; | 317 | bool is_ipv4; |
318 | uint8_t net_family; | 318 | uint8_t net_family; |
319 | 319 | ||
320 | if (ip_port->ip.family == AF_INET) { | 320 | if (ip_port->ip.family == TOX_AF_INET) { |
321 | // TODO(irungentoo): use functions to convert endianness | 321 | // TODO(irungentoo): use functions to convert endianness |
322 | is_ipv4 = true; | 322 | is_ipv4 = true; |
323 | net_family = TOX_AF_INET; | 323 | net_family = TOX_AF_INET; |
324 | } else if (ip_port->ip.family == TCP_INET) { | 324 | } else if (ip_port->ip.family == TCP_INET) { |
325 | is_ipv4 = true; | 325 | is_ipv4 = true; |
326 | net_family = TOX_TCP_INET; | 326 | net_family = TOX_TCP_INET; |
327 | } else if (ip_port->ip.family == AF_INET6) { | 327 | } else if (ip_port->ip.family == TOX_AF_INET6) { |
328 | is_ipv4 = false; | 328 | is_ipv4 = false; |
329 | net_family = TOX_AF_INET6; | 329 | net_family = TOX_AF_INET6; |
330 | } else if (ip_port->ip.family == TCP_INET6) { | 330 | } else if (ip_port->ip.family == TCP_INET6) { |
@@ -397,7 +397,7 @@ static int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length | |||
397 | 397 | ||
398 | if (data[0] == TOX_AF_INET) { | 398 | if (data[0] == TOX_AF_INET) { |
399 | is_ipv4 = true; | 399 | is_ipv4 = true; |
400 | host_family = AF_INET; | 400 | host_family = TOX_AF_INET; |
401 | } else if (data[0] == TOX_TCP_INET) { | 401 | } else if (data[0] == TOX_TCP_INET) { |
402 | if (!tcp_enabled) { | 402 | if (!tcp_enabled) { |
403 | return -1; | 403 | return -1; |
@@ -407,7 +407,7 @@ static int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length | |||
407 | host_family = TCP_INET; | 407 | host_family = TCP_INET; |
408 | } else if (data[0] == TOX_AF_INET6) { | 408 | } else if (data[0] == TOX_AF_INET6) { |
409 | is_ipv4 = false; | 409 | is_ipv4 = false; |
410 | host_family = AF_INET6; | 410 | host_family = TOX_AF_INET6; |
411 | } else if (data[0] == TOX_TCP_INET6) { | 411 | } else if (data[0] == TOX_TCP_INET6) { |
412 | if (!tcp_enabled) { | 412 | if (!tcp_enabled) { |
413 | return -1; | 413 | return -1; |
@@ -551,8 +551,8 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const | |||
551 | static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) | 551 | static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) |
552 | { | 552 | { |
553 | for (uint32_t i = 0; i < size; ++i) { | 553 | for (uint32_t i = 0; i < size; ++i) { |
554 | if (ip_port->ip.family == AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) || | 554 | if (ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) || |
555 | ip_port->ip.family == AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) { | 555 | ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) { |
556 | return i; | 556 | return i; |
557 | } | 557 | } |
558 | } | 558 | } |
@@ -567,10 +567,10 @@ static void update_client(Logger *log, int index, Client_data *client, IP_Port i | |||
567 | IPPTsPng *assoc; | 567 | IPPTsPng *assoc; |
568 | int ip_version; | 568 | int ip_version; |
569 | 569 | ||
570 | if (ip_port.ip.family == AF_INET) { | 570 | if (ip_port.ip.family == TOX_AF_INET) { |
571 | assoc = &client->assoc4; | 571 | assoc = &client->assoc4; |
572 | ip_version = 4; | 572 | ip_version = 4; |
573 | } else if (ip_port.ip.family == AF_INET6) { | 573 | } else if (ip_port.ip.family == TOX_AF_INET6) { |
574 | assoc = &client->assoc6; | 574 | assoc = &client->assoc6; |
575 | ip_version = 6; | 575 | ip_version = 6; |
576 | } else { | 576 | } else { |
@@ -628,7 +628,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le | |||
628 | IPPTsPng *assoc; | 628 | IPPTsPng *assoc; |
629 | int ip_version; | 629 | int ip_version; |
630 | 630 | ||
631 | if (ip_port.ip.family == AF_INET) { | 631 | if (ip_port.ip.family == TOX_AF_INET) { |
632 | assoc = &list[index].assoc4; | 632 | assoc = &list[index].assoc4; |
633 | ip_version = 4; | 633 | ip_version = 4; |
634 | } else { | 634 | } else { |
@@ -692,7 +692,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_ | |||
692 | Family sa_family, const Client_data *client_list, uint32_t client_list_length, | 692 | Family sa_family, const Client_data *client_list, uint32_t client_list_length, |
693 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) | 693 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) |
694 | { | 694 | { |
695 | if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) { | 695 | if ((sa_family != TOX_AF_INET) && (sa_family != TOX_AF_INET6) && (sa_family != 0)) { |
696 | return; | 696 | return; |
697 | } | 697 | } |
698 | 698 | ||
@@ -708,9 +708,9 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_ | |||
708 | 708 | ||
709 | const IPPTsPng *ipptp = NULL; | 709 | const IPPTsPng *ipptp = NULL; |
710 | 710 | ||
711 | if (sa_family == AF_INET) { | 711 | if (sa_family == TOX_AF_INET) { |
712 | ipptp = &client->assoc4; | 712 | ipptp = &client->assoc4; |
713 | } else if (sa_family == AF_INET6) { | 713 | } else if (sa_family == TOX_AF_INET6) { |
714 | ipptp = &client->assoc6; | 714 | ipptp = &client->assoc6; |
715 | } else if (client->assoc4.timestamp >= client->assoc6.timestamp) { | 715 | } else if (client->assoc4.timestamp >= client->assoc6.timestamp) { |
716 | ipptp = &client->assoc4; | 716 | ipptp = &client->assoc4; |
@@ -879,7 +879,7 @@ static void update_client_with_reset(Client_data *client, const IP_Port *ip_port | |||
879 | IPPTsPng *ipptp_write = NULL; | 879 | IPPTsPng *ipptp_write = NULL; |
880 | IPPTsPng *ipptp_clear = NULL; | 880 | IPPTsPng *ipptp_clear = NULL; |
881 | 881 | ||
882 | if (ip_port->ip.family == AF_INET) { | 882 | if (ip_port->ip.family == TOX_AF_INET) { |
883 | ipptp_write = &client->assoc4; | 883 | ipptp_write = &client->assoc4; |
884 | ipptp_clear = &client->assoc6; | 884 | ipptp_clear = &client->assoc6; |
885 | } else { | 885 | } else { |
@@ -917,7 +917,7 @@ static int replace_all(Client_data *list, | |||
917 | IP_Port ip_port, | 917 | IP_Port ip_port, |
918 | const uint8_t *comp_public_key) | 918 | const uint8_t *comp_public_key) |
919 | { | 919 | { |
920 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) { | 920 | if ((ip_port.ip.family != TOX_AF_INET) && (ip_port.ip.family != TOX_AF_INET6)) { |
921 | return 0; | 921 | return 0; |
922 | } | 922 | } |
923 | 923 | ||
@@ -988,7 +988,7 @@ static bool is_pk_in_client_list(Client_data *list, unsigned int client_list_len | |||
988 | return 0; | 988 | return 0; |
989 | } | 989 | } |
990 | 990 | ||
991 | const IPPTsPng *assoc = ip_port.ip.family == AF_INET ? | 991 | const IPPTsPng *assoc = ip_port.ip.family == TOX_AF_INET ? |
992 | &list[index].assoc4 : | 992 | &list[index].assoc4 : |
993 | &list[index].assoc6; | 993 | &list[index].assoc6; |
994 | 994 | ||
@@ -1079,8 +1079,8 @@ uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key) | |||
1079 | uint32_t used = 0; | 1079 | uint32_t used = 0; |
1080 | 1080 | ||
1081 | /* convert IPv4-in-IPv6 to IPv4 */ | 1081 | /* convert IPv4-in-IPv6 to IPv4 */ |
1082 | if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { | 1082 | if ((ip_port.ip.family == TOX_AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { |
1083 | ip_port.ip.family = AF_INET; | 1083 | ip_port.ip.family = TOX_AF_INET; |
1084 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; | 1084 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; |
1085 | } | 1085 | } |
1086 | 1086 | ||
@@ -1140,9 +1140,9 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port, | |||
1140 | Client_data *data = &array[index]; | 1140 | Client_data *data = &array[index]; |
1141 | IPPTsPng *assoc; | 1141 | IPPTsPng *assoc; |
1142 | 1142 | ||
1143 | if (ip_port.ip.family == AF_INET) { | 1143 | if (ip_port.ip.family == TOX_AF_INET) { |
1144 | assoc = &data->assoc4; | 1144 | assoc = &data->assoc4; |
1145 | } else if (ip_port.ip.family == AF_INET6) { | 1145 | } else if (ip_port.ip.family == TOX_AF_INET6) { |
1146 | assoc = &data->assoc6; | 1146 | assoc = &data->assoc6; |
1147 | } else { | 1147 | } else { |
1148 | return true; | 1148 | return true; |
@@ -1159,8 +1159,8 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port, | |||
1159 | static void returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key) | 1159 | static void returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key) |
1160 | { | 1160 | { |
1161 | /* convert IPv4-in-IPv6 to IPv4 */ | 1161 | /* convert IPv4-in-IPv6 to IPv4 */ |
1162 | if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { | 1162 | if ((ip_port.ip.family == TOX_AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { |
1163 | ip_port.ip.family = AF_INET; | 1163 | ip_port.ip.family = TOX_AF_INET; |
1164 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; | 1164 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; |
1165 | } | 1165 | } |
1166 | 1166 | ||
@@ -2237,11 +2237,11 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Fam | |||
2237 | continue; | 2237 | continue; |
2238 | } | 2238 | } |
2239 | 2239 | ||
2240 | if (sa_family == AF_INET) { | 2240 | if (sa_family == TOX_AF_INET) { |
2241 | return &dht->close_clientlist[i].assoc4; | 2241 | return &dht->close_clientlist[i].assoc4; |
2242 | } | 2242 | } |
2243 | 2243 | ||
2244 | if (sa_family == AF_INET6) { | 2244 | if (sa_family == TOX_AF_INET6) { |
2245 | return &dht->close_clientlist[i].assoc6; | 2245 | return &dht->close_clientlist[i].assoc6; |
2246 | } | 2246 | } |
2247 | } | 2247 | } |
@@ -2464,10 +2464,10 @@ static void do_hardening(DHT *dht) | |||
2464 | 2464 | ||
2465 | if (i % 2 == 0) { | 2465 | if (i % 2 == 0) { |
2466 | cur_iptspng = &dht->close_clientlist[i / 2].assoc4; | 2466 | cur_iptspng = &dht->close_clientlist[i / 2].assoc4; |
2467 | sa_family = AF_INET; | 2467 | sa_family = TOX_AF_INET; |
2468 | } else { | 2468 | } else { |
2469 | cur_iptspng = &dht->close_clientlist[i / 2].assoc6; | 2469 | cur_iptspng = &dht->close_clientlist[i / 2].assoc6; |
2470 | sa_family = AF_INET6; | 2470 | sa_family = TOX_AF_INET6; |
2471 | } | 2471 | } |
2472 | 2472 | ||
2473 | if (is_timeout(cur_iptspng->timestamp, BAD_NODE_TIMEOUT)) { | 2473 | if (is_timeout(cur_iptspng->timestamp, BAD_NODE_TIMEOUT)) { |
@@ -2675,7 +2675,7 @@ uint32_t DHT_size(const DHT *dht) | |||
2675 | 2675 | ||
2676 | uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; | 2676 | uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; |
2677 | 2677 | ||
2678 | return size32 + sizesubhead + (packed_node_size(AF_INET) * numv4) + (packed_node_size(AF_INET6) * numv6); | 2678 | return size32 + sizesubhead + (packed_node_size(TOX_AF_INET) * numv4) + (packed_node_size(TOX_AF_INET6) * numv6); |
2679 | } | 2679 | } |
2680 | 2680 | ||
2681 | static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 2681 | static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 98fa18d6..edba0ad4 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -59,12 +59,6 @@ | |||
59 | #define PING_ROUNDTRIP 2 | 59 | #define PING_ROUNDTRIP 2 |
60 | #define BAD_NODE_TIMEOUT (PING_INTERVAL + PINGS_MISSED_NODE_GOES_BAD * (PING_INTERVAL + PING_ROUNDTRIP)) | 60 | #define BAD_NODE_TIMEOUT (PING_INTERVAL + PINGS_MISSED_NODE_GOES_BAD * (PING_INTERVAL + PING_ROUNDTRIP)) |
61 | 61 | ||
62 | /* Redefinitions of variables for safe transfer over wire. */ | ||
63 | #define TOX_AF_INET 2 | ||
64 | #define TOX_AF_INET6 10 | ||
65 | #define TOX_TCP_INET 130 | ||
66 | #define TOX_TCP_INET6 138 | ||
67 | |||
68 | /* The number of "fake" friends to add (for optimization purposes and so our paths for the onion part are more random) */ | 62 | /* The number of "fake" friends to add (for optimization purposes and so our paths for the onion part are more random) */ |
69 | #define DHT_FAKE_FRIEND_NUMBER 2 | 63 | #define DHT_FAKE_FRIEND_NUMBER 2 |
70 | 64 | ||
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index fdb374fa..ed8a346c 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -82,9 +82,9 @@ static void fetch_broadcast_info(uint16_t port) | |||
82 | 82 | ||
83 | if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask) | 83 | if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask) |
84 | && addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) { | 84 | && addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) { |
85 | if (gateway.family == AF_INET && subnet_mask.family == AF_INET) { | 85 | if (gateway.family == TOX_AF_INET && subnet_mask.family == TOX_AF_INET) { |
86 | IP_Port *ip_port = &ip_ports[count]; | 86 | IP_Port *ip_port = &ip_ports[count]; |
87 | ip_port->ip.family = AF_INET; | 87 | ip_port->ip.family = TOX_AF_INET; |
88 | uint32_t gateway_ip = net_ntohl(gateway.ip4.uint32), subnet_ip = net_ntohl(subnet_mask.ip4.uint32); | 88 | uint32_t gateway_ip = net_ntohl(gateway.ip4.uint32), subnet_ip = net_ntohl(subnet_mask.ip4.uint32); |
89 | uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; | 89 | uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; |
90 | ip_port->ip.ip4.uint32 = net_htonl(broadcast_ip); | 90 | ip_port->ip.ip4.uint32 = net_htonl(broadcast_ip); |
@@ -160,8 +160,8 @@ static void fetch_broadcast_info(uint16_t port) | |||
160 | continue; | 160 | continue; |
161 | } | 161 | } |
162 | 162 | ||
163 | /* moot check: only AF_INET returned (backwards compat.) */ | 163 | /* moot check: only TOX_AF_INET returned (backwards compat.) */ |
164 | if (i_faces[i].ifr_broadaddr.sa_family != AF_INET) { | 164 | if (i_faces[i].ifr_broadaddr.sa_family != TOX_AF_INET) { |
165 | continue; | 165 | continue; |
166 | } | 166 | } |
167 | 167 | ||
@@ -172,7 +172,7 @@ static void fetch_broadcast_info(uint16_t port) | |||
172 | } | 172 | } |
173 | 173 | ||
174 | IP_Port *ip_port = &ip_ports[count]; | 174 | IP_Port *ip_port = &ip_ports[count]; |
175 | ip_port->ip.family = AF_INET; | 175 | ip_port->ip.family = TOX_AF_INET; |
176 | ip_port->ip.ip4.uint32 = sock4->sin_addr.s_addr; | 176 | ip_port->ip.ip4.uint32 = sock4->sin_addr.s_addr; |
177 | 177 | ||
178 | if (ip_port->ip.ip4.uint32 == 0) { | 178 | if (ip_port->ip.ip4.uint32 == 0) { |
@@ -232,25 +232,25 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast) | |||
232 | IP ip; | 232 | IP ip; |
233 | ip_reset(&ip); | 233 | ip_reset(&ip); |
234 | 234 | ||
235 | if (family_socket == AF_INET6) { | 235 | if (family_socket == TOX_AF_INET6) { |
236 | if (family_broadcast == AF_INET6) { | 236 | if (family_broadcast == TOX_AF_INET6) { |
237 | ip.family = AF_INET6; | 237 | ip.family = TOX_AF_INET6; |
238 | /* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */ | 238 | /* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */ |
239 | /* FE80::*: MUST be exact, for that we would need to look over all | 239 | /* FE80::*: MUST be exact, for that we would need to look over all |
240 | * interfaces and check in which status they are */ | 240 | * interfaces and check in which status they are */ |
241 | ip.ip6.uint8[ 0] = 0xFF; | 241 | ip.ip6.uint8[ 0] = 0xFF; |
242 | ip.ip6.uint8[ 1] = 0x02; | 242 | ip.ip6.uint8[ 1] = 0x02; |
243 | ip.ip6.uint8[15] = 0x01; | 243 | ip.ip6.uint8[15] = 0x01; |
244 | } else if (family_broadcast == AF_INET) { | 244 | } else if (family_broadcast == TOX_AF_INET) { |
245 | ip.family = AF_INET6; | 245 | ip.family = TOX_AF_INET6; |
246 | ip.ip6.uint32[0] = 0; | 246 | ip.ip6.uint32[0] = 0; |
247 | ip.ip6.uint32[1] = 0; | 247 | ip.ip6.uint32[1] = 0; |
248 | ip.ip6.uint32[2] = net_htonl(0xFFFF); | 248 | ip.ip6.uint32[2] = net_htonl(0xFFFF); |
249 | ip.ip6.uint32[3] = INADDR_BROADCAST; | 249 | ip.ip6.uint32[3] = INADDR_BROADCAST; |
250 | } | 250 | } |
251 | } else if (family_socket == AF_INET) { | 251 | } else if (family_socket == TOX_AF_INET) { |
252 | if (family_broadcast == AF_INET) { | 252 | if (family_broadcast == TOX_AF_INET) { |
253 | ip.family = AF_INET; | 253 | ip.family = TOX_AF_INET; |
254 | ip.ip4.uint32 = INADDR_BROADCAST; | 254 | ip.ip4.uint32 = INADDR_BROADCAST; |
255 | } | 255 | } |
256 | } | 256 | } |
@@ -261,7 +261,7 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast) | |||
261 | /* Is IP a local ip or not. */ | 261 | /* Is IP a local ip or not. */ |
262 | bool Local_ip(IP ip) | 262 | bool Local_ip(IP ip) |
263 | { | 263 | { |
264 | if (ip.family == AF_INET) { | 264 | if (ip.family == TOX_AF_INET) { |
265 | IP4 ip4 = ip.ip4; | 265 | IP4 ip4 = ip.ip4; |
266 | 266 | ||
267 | /* Loopback. */ | 267 | /* Loopback. */ |
@@ -272,7 +272,7 @@ bool Local_ip(IP ip) | |||
272 | /* embedded IPv4-in-IPv6 */ | 272 | /* embedded IPv4-in-IPv6 */ |
273 | if (IPV6_IPV4_IN_V6(ip.ip6)) { | 273 | if (IPV6_IPV4_IN_V6(ip.ip6)) { |
274 | IP ip4; | 274 | IP ip4; |
275 | ip4.family = AF_INET; | 275 | ip4.family = TOX_AF_INET; |
276 | ip4.ip4.uint32 = ip.ip6.uint32[3]; | 276 | ip4.ip4.uint32 = ip.ip6.uint32[3]; |
277 | return Local_ip(ip4); | 277 | return Local_ip(ip4); |
278 | } | 278 | } |
@@ -295,7 +295,7 @@ int LAN_ip(IP ip) | |||
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | 297 | ||
298 | if (ip.family == AF_INET) { | 298 | if (ip.family == TOX_AF_INET) { |
299 | IP4 ip4 = ip.ip4; | 299 | IP4 ip4 = ip.ip4; |
300 | 300 | ||
301 | /* 10.0.0.0 to 10.255.255.255 range. */ | 301 | /* 10.0.0.0 to 10.255.255.255 range. */ |
@@ -324,7 +324,7 @@ int LAN_ip(IP ip) | |||
324 | if ((ip4.uint8[0] == 100) && ((ip4.uint8[1] & 0xC0) == 0x40)) { | 324 | if ((ip4.uint8[0] == 100) && ((ip4.uint8[1] & 0xC0) == 0x40)) { |
325 | return 0; | 325 | return 0; |
326 | } | 326 | } |
327 | } else if (ip.family == AF_INET6) { | 327 | } else if (ip.family == TOX_AF_INET6) { |
328 | 328 | ||
329 | /* autogenerated for each interface: FE80::* (up to FEBF::*) | 329 | /* autogenerated for each interface: FE80::* (up to FEBF::*) |
330 | FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */ | 330 | FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */ |
@@ -336,7 +336,7 @@ int LAN_ip(IP ip) | |||
336 | /* embedded IPv4-in-IPv6 */ | 336 | /* embedded IPv4-in-IPv6 */ |
337 | if (IPV6_IPV4_IN_V6(ip.ip6)) { | 337 | if (IPV6_IPV4_IN_V6(ip.ip6)) { |
338 | IP ip4; | 338 | IP ip4; |
339 | ip4.family = AF_INET; | 339 | ip4.family = TOX_AF_INET; |
340 | ip4.ip4.uint32 = ip.ip6.uint32[3]; | 340 | ip4.ip4.uint32 = ip.ip6.uint32[3]; |
341 | return LAN_ip(ip4); | 341 | return LAN_ip(ip4); |
342 | } | 342 | } |
@@ -375,8 +375,8 @@ int send_LANdiscovery(uint16_t port, DHT *dht) | |||
375 | ip_port.port = port; | 375 | ip_port.port = port; |
376 | 376 | ||
377 | /* IPv6 multicast */ | 377 | /* IPv6 multicast */ |
378 | if (dht->net->family == AF_INET6) { | 378 | if (dht->net->family == TOX_AF_INET6) { |
379 | ip_port.ip = broadcast_ip(AF_INET6, AF_INET6); | 379 | ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6); |
380 | 380 | ||
381 | if (ip_isset(&ip_port.ip)) { | 381 | if (ip_isset(&ip_port.ip)) { |
382 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) { | 382 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) { |
@@ -385,8 +385,8 @@ int send_LANdiscovery(uint16_t port, DHT *dht) | |||
385 | } | 385 | } |
386 | } | 386 | } |
387 | 387 | ||
388 | /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is AF_INET6 */ | 388 | /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */ |
389 | ip_port.ip = broadcast_ip(dht->net->family, AF_INET); | 389 | ip_port.ip = broadcast_ip(dht->net->family, TOX_AF_INET); |
390 | 390 | ||
391 | if (ip_isset(&ip_port.ip)) { | 391 | if (ip_isset(&ip_port.ip)) { |
392 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) { | 392 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) { |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c5638f03..c04c78c9 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2531,7 +2531,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2531 | /* Add self tcp server. */ | 2531 | /* Add self tcp server. */ |
2532 | IP_Port local_ip_port; | 2532 | IP_Port local_ip_port; |
2533 | local_ip_port.port = m->options.tcp_server_port; | 2533 | local_ip_port.port = m->options.tcp_server_port; |
2534 | local_ip_port.ip.family = AF_INET; | 2534 | local_ip_port.ip.family = TOX_AF_INET; |
2535 | local_ip_port.ip.ip4.uint32 = INADDR_LOOPBACK; | 2535 | local_ip_port.ip.ip4.uint32 = INADDR_LOOPBACK; |
2536 | add_tcp_relay(m->net_crypto, local_ip_port, | 2536 | add_tcp_relay(m->net_crypto, local_ip_port, |
2537 | tcp_server_public_key(m->tcp_server)); | 2537 | tcp_server_public_key(m->tcp_server)); |
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index e584b265..f44fabb3 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -145,7 +145,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *TCP_ | |||
145 | TCP_conn->last_packet[2] = 0; /* reserved, must be 0 */ | 145 | TCP_conn->last_packet[2] = 0; /* reserved, must be 0 */ |
146 | uint16_t length = 3; | 146 | uint16_t length = 3; |
147 | 147 | ||
148 | if (TCP_conn->ip_port.ip.family == AF_INET) { | 148 | if (TCP_conn->ip_port.ip.family == TOX_AF_INET) { |
149 | TCP_conn->last_packet[3] = 1; /* IPv4 address */ | 149 | TCP_conn->last_packet[3] = 1; /* IPv4 address */ |
150 | ++length; | 150 | ++length; |
151 | memcpy(TCP_conn->last_packet + length, TCP_conn->ip_port.ip.ip4.uint8, sizeof(IP4)); | 151 | memcpy(TCP_conn->last_packet + length, TCP_conn->ip_port.ip.ip4.uint8, sizeof(IP4)); |
@@ -170,7 +170,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *TCP_ | |||
170 | */ | 170 | */ |
171 | static int proxy_socks5_read_connection_response(TCP_Client_Connection *TCP_conn) | 171 | static int proxy_socks5_read_connection_response(TCP_Client_Connection *TCP_conn) |
172 | { | 172 | { |
173 | if (TCP_conn->ip_port.ip.family == AF_INET) { | 173 | if (TCP_conn->ip_port.ip.family == TOX_AF_INET) { |
174 | uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; | 174 | uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; |
175 | int ret = read_TCP_packet(TCP_conn->sock, data, sizeof(data)); | 175 | int ret = read_TCP_packet(TCP_conn->sock, data, sizeof(data)); |
176 | 176 | ||
@@ -251,7 +251,8 @@ static int client_send_pending_data_nonpriority(TCP_Client_Connection *con) | |||
251 | } | 251 | } |
252 | 252 | ||
253 | uint16_t left = con->last_packet_length - con->last_packet_sent; | 253 | uint16_t left = con->last_packet_length - con->last_packet_sent; |
254 | int len = send(con->sock, (const char *)(con->last_packet + con->last_packet_sent), left, MSG_NOSIGNAL); | 254 | const char *data = (const char *)(con->last_packet + con->last_packet_sent); |
255 | int len = send(con->sock, data, left, MSG_NOSIGNAL); | ||
255 | 256 | ||
256 | if (len <= 0) { | 257 | if (len <= 0) { |
257 | return -1; | 258 | return -1; |
@@ -614,12 +615,10 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
614 | return NULL; | 615 | return NULL; |
615 | } | 616 | } |
616 | 617 | ||
617 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) { | 618 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { |
618 | return NULL; | 619 | return NULL; |
619 | } | 620 | } |
620 | 621 | ||
621 | uint8_t family = ip_port.ip.family; | ||
622 | |||
623 | TCP_Proxy_Info default_proxyinfo; | 622 | TCP_Proxy_Info default_proxyinfo; |
624 | 623 | ||
625 | if (proxy_info == NULL) { | 624 | if (proxy_info == NULL) { |
@@ -627,6 +626,8 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
627 | proxy_info = &default_proxyinfo; | 626 | proxy_info = &default_proxyinfo; |
628 | } | 627 | } |
629 | 628 | ||
629 | uint8_t family = ip_port.ip.family; | ||
630 | |||
630 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { | 631 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { |
631 | family = proxy_info->ip_port.ip.family; | 632 | family = proxy_info->ip_port.ip.family; |
632 | } | 633 | } |
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index b9c75afe..25159491 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -1116,12 +1116,12 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe | |||
1116 | static int add_tcp_relay_instance(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk) | 1116 | static int add_tcp_relay_instance(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk) |
1117 | { | 1117 | { |
1118 | if (ip_port.ip.family == TCP_INET) { | 1118 | if (ip_port.ip.family == TCP_INET) { |
1119 | ip_port.ip.family = AF_INET; | 1119 | ip_port.ip.family = TOX_AF_INET; |
1120 | } else if (ip_port.ip.family == TCP_INET6) { | 1120 | } else if (ip_port.ip.family == TCP_INET6) { |
1121 | ip_port.ip.family = AF_INET6; | 1121 | ip_port.ip.family = TOX_AF_INET6; |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) { | 1124 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { |
1125 | return -1; | 1125 | return -1; |
1126 | } | 1126 | } |
1127 | 1127 | ||
@@ -1276,9 +1276,9 @@ unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_ | |||
1276 | memcpy(tcp_relays[copied].public_key, tcp_con->connection->public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1276 | memcpy(tcp_relays[copied].public_key, tcp_con->connection->public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1277 | tcp_relays[copied].ip_port = tcp_con->connection->ip_port; | 1277 | tcp_relays[copied].ip_port = tcp_con->connection->ip_port; |
1278 | 1278 | ||
1279 | if (tcp_relays[copied].ip_port.ip.family == AF_INET) { | 1279 | if (tcp_relays[copied].ip_port.ip.family == TOX_AF_INET) { |
1280 | tcp_relays[copied].ip_port.ip.family = TCP_INET; | 1280 | tcp_relays[copied].ip_port.ip.family = TCP_INET; |
1281 | } else if (tcp_relays[copied].ip_port.ip.family == AF_INET6) { | 1281 | } else if (tcp_relays[copied].ip_port.ip.family == TOX_AF_INET6) { |
1282 | tcp_relays[copied].ip_port.ip.family = TCP_INET6; | 1282 | tcp_relays[copied].ip_port.ip.family = TCP_INET6; |
1283 | } | 1283 | } |
1284 | 1284 | ||
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 3f2e554f..9b94667a 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -986,7 +986,7 @@ static Socket new_listening_TCP_socket(int family, uint16_t port) | |||
986 | 986 | ||
987 | int ok = set_socket_nonblock(sock); | 987 | int ok = set_socket_nonblock(sock); |
988 | 988 | ||
989 | if (ok && family == AF_INET6) { | 989 | if (ok && family == TOX_AF_INET6) { |
990 | ok = set_socket_dualstack(sock); | 990 | ok = set_socket_dualstack(sock); |
991 | } | 991 | } |
992 | 992 | ||
@@ -1042,9 +1042,9 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin | |||
1042 | uint8_t family; | 1042 | uint8_t family; |
1043 | 1043 | ||
1044 | if (ipv6_enabled) { | 1044 | if (ipv6_enabled) { |
1045 | family = AF_INET6; | 1045 | family = TOX_AF_INET6; |
1046 | } else { | 1046 | } else { |
1047 | family = AF_INET; | 1047 | family = TOX_AF_INET; |
1048 | } | 1048 | } |
1049 | 1049 | ||
1050 | uint32_t i; | 1050 | uint32_t i; |
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 0fbae406..ccf1621f 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -511,7 +511,7 @@ static int handle_new_connections(void *object, New_Connection *n_c) | |||
511 | connection_lossy_data_handler(fr_c->net_crypto, id, &handle_lossy_packet, fr_c, friendcon_id); | 511 | connection_lossy_data_handler(fr_c->net_crypto, id, &handle_lossy_packet, fr_c, friendcon_id); |
512 | friend_con->crypt_connection_id = id; | 512 | friend_con->crypt_connection_id = id; |
513 | 513 | ||
514 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { | 514 | if (n_c->source.ip.family != TOX_AF_INET && n_c->source.ip.family != TOX_AF_INET6) { |
515 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0); | 515 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0); |
516 | } else { | 516 | } else { |
517 | friend_con->dht_ip_port = n_c->source; | 517 | friend_con->dht_ip_port = n_c->source; |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 1d32a489..440db94a 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -431,7 +431,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por | |||
431 | return -1; | 431 | return -1; |
432 | } | 432 | } |
433 | 433 | ||
434 | if (ip_port.ip.family == AF_INET) { | 434 | if (ip_port.ip.family == TOX_AF_INET) { |
435 | if (!ipport_equal(&ip_port, &conn->ip_portv4) && LAN_ip(conn->ip_portv4.ip) != 0) { | 435 | if (!ipport_equal(&ip_port, &conn->ip_portv4) && LAN_ip(conn->ip_portv4.ip) != 0) { |
436 | if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { | 436 | if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { |
437 | return -1; | 437 | return -1; |
@@ -441,7 +441,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por | |||
441 | conn->ip_portv4 = ip_port; | 441 | conn->ip_portv4 = ip_port; |
442 | return 0; | 442 | return 0; |
443 | } | 443 | } |
444 | } else if (ip_port.ip.family == AF_INET6) { | 444 | } else if (ip_port.ip.family == TOX_AF_INET6) { |
445 | if (!ipport_equal(&ip_port, &conn->ip_portv6)) { | 445 | if (!ipport_equal(&ip_port, &conn->ip_portv6)) { |
446 | if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { | 446 | if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { |
447 | return -1; | 447 | return -1; |
@@ -486,11 +486,11 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) | |||
486 | return conn->ip_portv4; | 486 | return conn->ip_portv4; |
487 | } | 487 | } |
488 | 488 | ||
489 | if (v6 && conn->ip_portv6.ip.family == AF_INET6) { | 489 | if (v6 && conn->ip_portv6.ip.family == TOX_AF_INET6) { |
490 | return conn->ip_portv6; | 490 | return conn->ip_portv6; |
491 | } | 491 | } |
492 | 492 | ||
493 | if (conn->ip_portv4.ip.family == AF_INET) { | 493 | if (conn->ip_portv4.ip.family == TOX_AF_INET) { |
494 | return conn->ip_portv4; | 494 | return conn->ip_portv4; |
495 | } | 495 | } |
496 | 496 | ||
@@ -1695,12 +1695,12 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, | |||
1695 | return -1; | 1695 | return -1; |
1696 | } | 1696 | } |
1697 | 1697 | ||
1698 | if (source.ip.family == AF_INET || source.ip.family == AF_INET6) { | 1698 | if (source.ip.family == TOX_AF_INET || source.ip.family == TOX_AF_INET6) { |
1699 | if (add_ip_port_connection(c, crypt_connection_id, source) != 0) { | 1699 | if (add_ip_port_connection(c, crypt_connection_id, source) != 0) { |
1700 | return -1; | 1700 | return -1; |
1701 | } | 1701 | } |
1702 | 1702 | ||
1703 | if (source.ip.family == AF_INET) { | 1703 | if (source.ip.family == TOX_AF_INET) { |
1704 | conn->direct_lastrecv_timev4 = unix_time(); | 1704 | conn->direct_lastrecv_timev4 = unix_time(); |
1705 | } else { | 1705 | } else { |
1706 | conn->direct_lastrecv_timev6 = unix_time(); | 1706 | conn->direct_lastrecv_timev6 = unix_time(); |
@@ -1925,13 +1925,13 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
1925 | 1925 | ||
1926 | if (add_ip_port_connection(c, crypt_connection_id, ip_port) == 0) { | 1926 | if (add_ip_port_connection(c, crypt_connection_id, ip_port) == 0) { |
1927 | if (connected) { | 1927 | if (connected) { |
1928 | if (ip_port.ip.family == AF_INET) { | 1928 | if (ip_port.ip.family == TOX_AF_INET) { |
1929 | conn->direct_lastrecv_timev4 = unix_time(); | 1929 | conn->direct_lastrecv_timev4 = unix_time(); |
1930 | } else { | 1930 | } else { |
1931 | conn->direct_lastrecv_timev6 = unix_time(); | 1931 | conn->direct_lastrecv_timev6 = unix_time(); |
1932 | } | 1932 | } |
1933 | } else { | 1933 | } else { |
1934 | if (ip_port.ip.family == AF_INET) { | 1934 | if (ip_port.ip.family == TOX_AF_INET) { |
1935 | conn->direct_lastrecv_timev4 = 0; | 1935 | conn->direct_lastrecv_timev4 = 0; |
1936 | } else { | 1936 | } else { |
1937 | conn->direct_lastrecv_timev6 = 0; | 1937 | conn->direct_lastrecv_timev6 = 0; |
@@ -2271,7 +2271,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2271 | 2271 | ||
2272 | pthread_mutex_lock(&conn->mutex); | 2272 | pthread_mutex_lock(&conn->mutex); |
2273 | 2273 | ||
2274 | if (source.ip.family == AF_INET) { | 2274 | if (source.ip.family == TOX_AF_INET) { |
2275 | conn->direct_lastrecv_timev4 = unix_time(); | 2275 | conn->direct_lastrecv_timev4 = unix_time(); |
2276 | } else { | 2276 | } else { |
2277 | conn->direct_lastrecv_timev6 = unix_time(); | 2277 | conn->direct_lastrecv_timev6 = unix_time(); |
diff --git a/toxcore/network.c b/toxcore/network.c index edf6f11a..45805244 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -70,7 +70,7 @@ | |||
70 | 70 | ||
71 | static const char *inet_ntop(Family family, const void *addr, char *buf, size_t bufsize) | 71 | static const char *inet_ntop(Family family, const void *addr, char *buf, size_t bufsize) |
72 | { | 72 | { |
73 | if (family == AF_INET) { | 73 | if (family == TOX_AF_INET) { |
74 | struct sockaddr_in saddr; | 74 | struct sockaddr_in saddr; |
75 | memset(&saddr, 0, sizeof(saddr)); | 75 | memset(&saddr, 0, sizeof(saddr)); |
76 | 76 | ||
@@ -84,7 +84,7 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t | |||
84 | } | 84 | } |
85 | 85 | ||
86 | return buf; | 86 | return buf; |
87 | } else if (family == AF_INET6) { | 87 | } else if (family == TOX_AF_INET6) { |
88 | struct sockaddr_in6 saddr; | 88 | struct sockaddr_in6 saddr; |
89 | memset(&saddr, 0, sizeof(saddr)); | 89 | memset(&saddr, 0, sizeof(saddr)); |
90 | 90 | ||
@@ -105,7 +105,7 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t | |||
105 | 105 | ||
106 | static int inet_pton(Family family, const char *addrString, void *addrbuf) | 106 | static int inet_pton(Family family, const char *addrString, void *addrbuf) |
107 | { | 107 | { |
108 | if (family == AF_INET) { | 108 | if (family == TOX_AF_INET) { |
109 | struct sockaddr_in saddr; | 109 | struct sockaddr_in saddr; |
110 | memset(&saddr, 0, sizeof(saddr)); | 110 | memset(&saddr, 0, sizeof(saddr)); |
111 | 111 | ||
@@ -118,7 +118,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf) | |||
118 | *(struct in_addr *)addrbuf = saddr.sin_addr; | 118 | *(struct in_addr *)addrbuf = saddr.sin_addr; |
119 | 119 | ||
120 | return 1; | 120 | return 1; |
121 | } else if (family == AF_INET6) { | 121 | } else if (family == TOX_AF_INET6) { |
122 | struct sockaddr_in6 saddr; | 122 | struct sockaddr_in6 saddr; |
123 | memset(&saddr, 0, sizeof(saddr)); | 123 | memset(&saddr, 0, sizeof(saddr)); |
124 | 124 | ||
@@ -140,7 +140,8 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf) | |||
140 | 140 | ||
141 | static int make_proto(int proto); | 141 | static int make_proto(int proto); |
142 | static int make_socktype(int type); | 142 | static int make_socktype(int type); |
143 | static int make_family(int family); | 143 | static int make_family(int tox_family); |
144 | static int make_tox_family(int family); | ||
144 | 145 | ||
145 | /* Check if socket is valid. | 146 | /* Check if socket is valid. |
146 | * | 147 | * |
@@ -366,8 +367,8 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
366 | return -1; | 367 | return -1; |
367 | } | 368 | } |
368 | 369 | ||
369 | /* socket AF_INET, but target IP NOT: can't send */ | 370 | /* socket TOX_AF_INET, but target IP NOT: can't send */ |
370 | if ((net->family == AF_INET) && (ip_port.ip.family != AF_INET)) { | 371 | if ((net->family == TOX_AF_INET) && (ip_port.ip.family != TOX_AF_INET)) { |
371 | return -1; | 372 | return -1; |
372 | } | 373 | } |
373 | 374 | ||
@@ -375,8 +376,8 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
375 | 376 | ||
376 | size_t addrsize = 0; | 377 | size_t addrsize = 0; |
377 | 378 | ||
378 | if (ip_port.ip.family == AF_INET) { | 379 | if (ip_port.ip.family == TOX_AF_INET) { |
379 | if (net->family == AF_INET6) { | 380 | if (net->family == TOX_AF_INET6) { |
380 | /* must convert to IPV4-in-IPV6 address */ | 381 | /* must convert to IPV4-in-IPV6 address */ |
381 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; | 382 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; |
382 | 383 | ||
@@ -404,7 +405,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
404 | fill_addr4(ip_port.ip.ip4, &addr4->sin_addr); | 405 | fill_addr4(ip_port.ip.ip4, &addr4->sin_addr); |
405 | addr4->sin_port = ip_port.port; | 406 | addr4->sin_port = ip_port.port; |
406 | } | 407 | } |
407 | } else if (ip_port.ip.family == AF_INET6) { | 408 | } else if (ip_port.ip.family == TOX_AF_INET6) { |
408 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; | 409 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; |
409 | 410 | ||
410 | addrsize = sizeof(struct sockaddr_in6); | 411 | addrsize = sizeof(struct sockaddr_in6); |
@@ -457,17 +458,17 @@ static int receivepacket(Logger *log, Socket sock, IP_Port *ip_port, uint8_t *da | |||
457 | if (addr.ss_family == AF_INET) { | 458 | if (addr.ss_family == AF_INET) { |
458 | struct sockaddr_in *addr_in = (struct sockaddr_in *)&addr; | 459 | struct sockaddr_in *addr_in = (struct sockaddr_in *)&addr; |
459 | 460 | ||
460 | ip_port->ip.family = addr_in->sin_family; | 461 | ip_port->ip.family = make_tox_family(addr_in->sin_family); |
461 | get_ip4(&ip_port->ip.ip4, &addr_in->sin_addr); | 462 | get_ip4(&ip_port->ip.ip4, &addr_in->sin_addr); |
462 | ip_port->port = addr_in->sin_port; | 463 | ip_port->port = addr_in->sin_port; |
463 | } else if (addr.ss_family == AF_INET6) { | 464 | } else if (addr.ss_family == AF_INET6) { |
464 | struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; | 465 | struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; |
465 | ip_port->ip.family = addr_in6->sin6_family; | 466 | ip_port->ip.family = make_tox_family(addr_in6->sin6_family); |
466 | get_ip6(&ip_port->ip.ip6, &addr_in6->sin6_addr); | 467 | get_ip6(&ip_port->ip.ip6, &addr_in6->sin6_addr); |
467 | ip_port->port = addr_in6->sin6_port; | 468 | ip_port->port = addr_in6->sin6_port; |
468 | 469 | ||
469 | if (IPV6_IPV4_IN_V6(ip_port->ip.ip6)) { | 470 | if (IPV6_IPV4_IN_V6(ip_port->ip.ip6)) { |
470 | ip_port->ip.family = AF_INET; | 471 | ip_port->ip.family = TOX_AF_INET; |
471 | ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3]; | 472 | ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3]; |
472 | } | 473 | } |
473 | } else { | 474 | } else { |
@@ -602,7 +603,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
602 | } | 603 | } |
603 | 604 | ||
604 | /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ | 605 | /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ |
605 | if (ip.family != AF_INET && ip.family != AF_INET6) { | 606 | if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) { |
606 | LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family); | 607 | LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family); |
607 | return NULL; | 608 | return NULL; |
608 | } | 609 | } |
@@ -674,7 +675,9 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
674 | struct sockaddr_storage addr; | 675 | struct sockaddr_storage addr; |
675 | size_t addrsize; | 676 | size_t addrsize; |
676 | 677 | ||
677 | if (temp->family == AF_INET) { | 678 | memset(&addr, 0, sizeof(struct sockaddr_storage)); |
679 | |||
680 | if (temp->family == TOX_AF_INET) { | ||
678 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; | 681 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; |
679 | 682 | ||
680 | addrsize = sizeof(struct sockaddr_in); | 683 | addrsize = sizeof(struct sockaddr_in); |
@@ -683,7 +686,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
683 | fill_addr4(ip.ip4, &addr4->sin_addr); | 686 | fill_addr4(ip.ip4, &addr4->sin_addr); |
684 | 687 | ||
685 | portptr = &addr4->sin_port; | 688 | portptr = &addr4->sin_port; |
686 | } else if (temp->family == AF_INET6) { | 689 | } else if (temp->family == TOX_AF_INET6) { |
687 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; | 690 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; |
688 | 691 | ||
689 | addrsize = sizeof(struct sockaddr_in6); | 692 | addrsize = sizeof(struct sockaddr_in6); |
@@ -700,7 +703,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
700 | return NULL; | 703 | return NULL; |
701 | } | 704 | } |
702 | 705 | ||
703 | if (ip.family == AF_INET6) { | 706 | if (ip.family == TOX_AF_INET6) { |
704 | int is_dualstack = set_socket_dualstack(temp->sock); | 707 | int is_dualstack = set_socket_dualstack(temp->sock); |
705 | LOGGER_DEBUG(log, "Dual-stack socket: %s", | 708 | LOGGER_DEBUG(log, "Dual-stack socket: %s", |
706 | is_dualstack ? "enabled" : "Failed to enable, won't be able to receive from/send to IPv4 addresses"); | 709 | is_dualstack ? "enabled" : "Failed to enable, won't be able to receive from/send to IPv4 addresses"); |
@@ -812,7 +815,7 @@ int ip_equal(const IP *a, const IP *b) | |||
812 | 815 | ||
813 | /* same family */ | 816 | /* same family */ |
814 | if (a->family == b->family) { | 817 | if (a->family == b->family) { |
815 | if (a->family == AF_INET || a->family == TCP_INET) { | 818 | if (a->family == TOX_AF_INET || a->family == TCP_INET) { |
816 | struct in_addr addr_a; | 819 | struct in_addr addr_a; |
817 | struct in_addr addr_b; | 820 | struct in_addr addr_b; |
818 | fill_addr4(a->ip4, &addr_a); | 821 | fill_addr4(a->ip4, &addr_a); |
@@ -820,7 +823,7 @@ int ip_equal(const IP *a, const IP *b) | |||
820 | return addr_a.s_addr == addr_b.s_addr; | 823 | return addr_a.s_addr == addr_b.s_addr; |
821 | } | 824 | } |
822 | 825 | ||
823 | if (a->family == AF_INET6 || a->family == TCP_INET6) { | 826 | if (a->family == TOX_AF_INET6 || a->family == TCP_INET6) { |
824 | return a->ip6.uint64[0] == b->ip6.uint64[0] && | 827 | return a->ip6.uint64[0] == b->ip6.uint64[0] && |
825 | a->ip6.uint64[1] == b->ip6.uint64[1]; | 828 | a->ip6.uint64[1] == b->ip6.uint64[1]; |
826 | } | 829 | } |
@@ -829,13 +832,13 @@ int ip_equal(const IP *a, const IP *b) | |||
829 | } | 832 | } |
830 | 833 | ||
831 | /* different family: check on the IPv6 one if it is the IPv4 one embedded */ | 834 | /* different family: check on the IPv6 one if it is the IPv4 one embedded */ |
832 | if ((a->family == AF_INET) && (b->family == AF_INET6)) { | 835 | if ((a->family == TOX_AF_INET) && (b->family == TOX_AF_INET6)) { |
833 | if (IPV6_IPV4_IN_V6(b->ip6)) { | 836 | if (IPV6_IPV4_IN_V6(b->ip6)) { |
834 | struct in_addr addr_a; | 837 | struct in_addr addr_a; |
835 | fill_addr4(a->ip4, &addr_a); | 838 | fill_addr4(a->ip4, &addr_a); |
836 | return addr_a.s_addr == b->ip6.uint32[3]; | 839 | return addr_a.s_addr == b->ip6.uint32[3]; |
837 | } | 840 | } |
838 | } else if ((a->family == AF_INET6) && (b->family == AF_INET)) { | 841 | } else if ((a->family == TOX_AF_INET6) && (b->family == TOX_AF_INET)) { |
839 | if (IPV6_IPV4_IN_V6(a->ip6)) { | 842 | if (IPV6_IPV4_IN_V6(a->ip6)) { |
840 | struct in_addr addr_b; | 843 | struct in_addr addr_b; |
841 | fill_addr4(b->ip4, &addr_b); | 844 | fill_addr4(b->ip4, &addr_b); |
@@ -883,7 +886,7 @@ void ip_init(IP *ip, uint8_t ipv6enabled) | |||
883 | } | 886 | } |
884 | 887 | ||
885 | memset(ip, 0, sizeof(IP)); | 888 | memset(ip, 0, sizeof(IP)); |
886 | ip->family = ipv6enabled ? AF_INET6 : AF_INET; | 889 | ip->family = ipv6enabled ? TOX_AF_INET6 : TOX_AF_INET; |
887 | } | 890 | } |
888 | 891 | ||
889 | /* checks if ip is valid */ | 892 | /* checks if ip is valid */ |
@@ -947,20 +950,22 @@ const char *ip_ntoa(const IP *ip, char *ip_str, size_t length) | |||
947 | } | 950 | } |
948 | 951 | ||
949 | if (ip) { | 952 | if (ip) { |
950 | if (ip->family == AF_INET) { | 953 | const int family = make_family(ip->family); |
954 | |||
955 | if (ip->family == TOX_AF_INET) { | ||
951 | /* returns standard quad-dotted notation */ | 956 | /* returns standard quad-dotted notation */ |
952 | struct in_addr addr; | 957 | struct in_addr addr; |
953 | fill_addr4(ip->ip4, &addr); | 958 | fill_addr4(ip->ip4, &addr); |
954 | 959 | ||
955 | ip_str[0] = 0; | 960 | ip_str[0] = 0; |
956 | inet_ntop(ip->family, &addr, ip_str, length); | 961 | inet_ntop(family, &addr, ip_str, length); |
957 | } else if (ip->family == AF_INET6) { | 962 | } else if (ip->family == TOX_AF_INET6) { |
958 | /* returns hex-groups enclosed into square brackets */ | 963 | /* returns hex-groups enclosed into square brackets */ |
959 | struct in6_addr addr; | 964 | struct in6_addr addr; |
960 | fill_addr6(ip->ip6, &addr); | 965 | fill_addr6(ip->ip6, &addr); |
961 | 966 | ||
962 | ip_str[0] = '['; | 967 | ip_str[0] = '['; |
963 | inet_ntop(ip->family, &addr, &ip_str[1], length - 3); | 968 | inet_ntop(family, &addr, &ip_str[1], length - 3); |
964 | size_t len = strlen(ip_str); | 969 | size_t len = strlen(ip_str); |
965 | ip_str[len] = ']'; | 970 | ip_str[len] = ']'; |
966 | ip_str[len + 1] = 0; | 971 | ip_str[len + 1] = 0; |
@@ -981,10 +986,10 @@ const char *ip_ntoa(const IP *ip, char *ip_str, size_t length) | |||
981 | * parses IP structure into an address string | 986 | * parses IP structure into an address string |
982 | * | 987 | * |
983 | * input | 988 | * input |
984 | * ip: ip of AF_INET or AF_INET6 families | 989 | * ip: ip of TOX_AF_INET or TOX_AF_INET6 families |
985 | * length: length of the address buffer | 990 | * length: length of the address buffer |
986 | * Must be at least INET_ADDRSTRLEN for AF_INET | 991 | * Must be at least INET_ADDRSTRLEN for TOX_AF_INET |
987 | * and INET6_ADDRSTRLEN for AF_INET6 | 992 | * and INET6_ADDRSTRLEN for TOX_AF_INET6 |
988 | * | 993 | * |
989 | * output | 994 | * output |
990 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) | 995 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) |
@@ -997,12 +1002,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length) | |||
997 | return 0; | 1002 | return 0; |
998 | } | 1003 | } |
999 | 1004 | ||
1000 | if (ip->family == AF_INET) { | 1005 | if (ip->family == TOX_AF_INET) { |
1001 | const struct in_addr *addr = (const struct in_addr *)&ip->ip4; | 1006 | const struct in_addr *addr = (const struct in_addr *)&ip->ip4; |
1002 | return inet_ntop(ip->family, addr, address, length) != NULL; | 1007 | return inet_ntop(ip->family, addr, address, length) != NULL; |
1003 | } | 1008 | } |
1004 | 1009 | ||
1005 | if (ip->family == AF_INET6) { | 1010 | if (ip->family == TOX_AF_INET6) { |
1006 | const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; | 1011 | const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; |
1007 | return inet_ntop(ip->family, addr, address, length) != NULL; | 1012 | return inet_ntop(ip->family, addr, address, length) != NULL; |
1008 | } | 1013 | } |
@@ -1031,16 +1036,16 @@ int addr_parse_ip(const char *address, IP *to) | |||
1031 | 1036 | ||
1032 | struct in_addr addr4; | 1037 | struct in_addr addr4; |
1033 | 1038 | ||
1034 | if (1 == inet_pton(AF_INET, address, &addr4)) { | 1039 | if (inet_pton(AF_INET, address, &addr4) == 1) { |
1035 | to->family = AF_INET; | 1040 | to->family = TOX_AF_INET; |
1036 | get_ip4(&to->ip4, &addr4); | 1041 | get_ip4(&to->ip4, &addr4); |
1037 | return 1; | 1042 | return 1; |
1038 | } | 1043 | } |
1039 | 1044 | ||
1040 | struct in6_addr addr6; | 1045 | struct in6_addr addr6; |
1041 | 1046 | ||
1042 | if (1 == inet_pton(AF_INET6, address, &addr6)) { | 1047 | if (inet_pton(AF_INET6, address, &addr6) == 1) { |
1043 | to->family = AF_INET6; | 1048 | to->family = TOX_AF_INET6; |
1044 | get_ip6(&to->ip6, &addr6); | 1049 | get_ip6(&to->ip6, &addr6); |
1045 | return 1; | 1050 | return 1; |
1046 | } | 1051 | } |
@@ -1056,13 +1061,13 @@ int addr_parse_ip(const char *address, IP *to) | |||
1056 | * input | 1061 | * input |
1057 | * address: a hostname (or something parseable to an IP address) | 1062 | * address: a hostname (or something parseable to an IP address) |
1058 | * to: to.family MUST be initialized, either set to a specific IP version | 1063 | * to: to.family MUST be initialized, either set to a specific IP version |
1059 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | 1064 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both |
1060 | * IP versions are acceptable | 1065 | * IP versions are acceptable |
1061 | * extra can be NULL and is only set in special circumstances, see returns | 1066 | * extra can be NULL and is only set in special circumstances, see returns |
1062 | * | 1067 | * |
1063 | * returns in *to a valid IPAny (v4/v6), | 1068 | * returns in *to a valid IPAny (v4/v6), |
1064 | * prefers v6 if ip.family was AF_UNSPEC and both available | 1069 | * prefers v6 if ip.family was AF_UNSPEC and both available |
1065 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is AF_INET6 | 1070 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is TOX_AF_INET6 |
1066 | * returns 0 on failure, TOX_ADDR_RESOLVE_* on success. | 1071 | * returns 0 on failure, TOX_ADDR_RESOLVE_* on success. |
1067 | */ | 1072 | */ |
1068 | int addr_resolve(const char *address, IP *to, IP *extra) | 1073 | int addr_resolve(const char *address, IP *to, IP *extra) |
@@ -1071,7 +1076,8 @@ int addr_resolve(const char *address, IP *to, IP *extra) | |||
1071 | return 0; | 1076 | return 0; |
1072 | } | 1077 | } |
1073 | 1078 | ||
1074 | Family family = to->family; | 1079 | Family tox_family = to->family; |
1080 | Family family = make_family(tox_family); | ||
1075 | 1081 | ||
1076 | struct addrinfo *server = NULL; | 1082 | struct addrinfo *server = NULL; |
1077 | struct addrinfo *walker = NULL; | 1083 | struct addrinfo *walker = NULL; |
@@ -1160,7 +1166,7 @@ int addr_resolve(const char *address, IP *to, IP *extra) | |||
1160 | * | 1166 | * |
1161 | * address: a hostname (or something parseable to an IP address) | 1167 | * address: a hostname (or something parseable to an IP address) |
1162 | * to: to.family MUST be initialized, either set to a specific IP version | 1168 | * to: to.family MUST be initialized, either set to a specific IP version |
1163 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | 1169 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both |
1164 | * IP versions are acceptable | 1170 | * IP versions are acceptable |
1165 | * extra can be NULL and is only set in special circumstances, see returns | 1171 | * extra can be NULL and is only set in special circumstances, see returns |
1166 | * | 1172 | * |
@@ -1185,14 +1191,14 @@ int net_connect(Socket sock, IP_Port ip_port) | |||
1185 | struct sockaddr_storage addr = {0}; | 1191 | struct sockaddr_storage addr = {0}; |
1186 | size_t addrsize; | 1192 | size_t addrsize; |
1187 | 1193 | ||
1188 | if (ip_port.ip.family == AF_INET) { | 1194 | if (ip_port.ip.family == TOX_AF_INET) { |
1189 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; | 1195 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; |
1190 | 1196 | ||
1191 | addrsize = sizeof(struct sockaddr_in); | 1197 | addrsize = sizeof(struct sockaddr_in); |
1192 | addr4->sin_family = AF_INET; | 1198 | addr4->sin_family = AF_INET; |
1193 | fill_addr4(ip_port.ip.ip4, &addr4->sin_addr); | 1199 | fill_addr4(ip_port.ip.ip4, &addr4->sin_addr); |
1194 | addr4->sin_port = ip_port.port; | 1200 | addr4->sin_port = ip_port.port; |
1195 | } else if (ip_port.ip.family == AF_INET6) { | 1201 | } else if (ip_port.ip.family == TOX_AF_INET6) { |
1196 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; | 1202 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; |
1197 | 1203 | ||
1198 | addrsize = sizeof(struct sockaddr_in6); | 1204 | addrsize = sizeof(struct sockaddr_in6); |
@@ -1206,7 +1212,7 @@ int net_connect(Socket sock, IP_Port ip_port) | |||
1206 | return connect(sock, (struct sockaddr *)&addr, addrsize); | 1212 | return connect(sock, (struct sockaddr *)&addr, addrsize); |
1207 | } | 1213 | } |
1208 | 1214 | ||
1209 | int32_t net_getipport(const char *node, IP_Port **res, int type) | 1215 | int32_t net_getipport(const char *node, IP_Port **res, int tox_type) |
1210 | { | 1216 | { |
1211 | struct addrinfo *infos; | 1217 | struct addrinfo *infos; |
1212 | int ret = getaddrinfo(node, NULL, NULL, &infos); | 1218 | int ret = getaddrinfo(node, NULL, NULL, &infos); |
@@ -1218,6 +1224,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int type) | |||
1218 | 1224 | ||
1219 | // Used to avoid malloc parameter overflow | 1225 | // Used to avoid malloc parameter overflow |
1220 | const size_t MAX_COUNT = MIN(SIZE_MAX, INT32_MAX) / sizeof(IP_Port); | 1226 | const size_t MAX_COUNT = MIN(SIZE_MAX, INT32_MAX) / sizeof(IP_Port); |
1227 | int type = make_socktype(tox_type); | ||
1221 | struct addrinfo *cur; | 1228 | struct addrinfo *cur; |
1222 | int32_t count = 0; | 1229 | int32_t count = 0; |
1223 | 1230 | ||
@@ -1262,7 +1269,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int type) | |||
1262 | continue; | 1269 | continue; |
1263 | } | 1270 | } |
1264 | 1271 | ||
1265 | ip_port->ip.family = cur->ai_family; | 1272 | ip_port->ip.family = make_tox_family(cur->ai_family); |
1266 | 1273 | ||
1267 | ip_port++; | 1274 | ip_port++; |
1268 | } | 1275 | } |
@@ -1285,13 +1292,13 @@ int bind_to_port(Socket sock, int family, uint16_t port) | |||
1285 | struct sockaddr_storage addr = {0}; | 1292 | struct sockaddr_storage addr = {0}; |
1286 | size_t addrsize; | 1293 | size_t addrsize; |
1287 | 1294 | ||
1288 | if (family == AF_INET) { | 1295 | if (family == TOX_AF_INET) { |
1289 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; | 1296 | struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; |
1290 | 1297 | ||
1291 | addrsize = sizeof(struct sockaddr_in); | 1298 | addrsize = sizeof(struct sockaddr_in); |
1292 | addr4->sin_family = AF_INET; | 1299 | addr4->sin_family = AF_INET; |
1293 | addr4->sin_port = net_htons(port); | 1300 | addr4->sin_port = net_htons(port); |
1294 | } else if (family == AF_INET6) { | 1301 | } else if (family == TOX_AF_INET6) { |
1295 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; | 1302 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; |
1296 | 1303 | ||
1297 | addrsize = sizeof(struct sockaddr_in6); | 1304 | addrsize = sizeof(struct sockaddr_in6); |
@@ -1304,17 +1311,37 @@ int bind_to_port(Socket sock, int family, uint16_t port) | |||
1304 | return (bind(sock, (struct sockaddr *)&addr, addrsize) == 0); | 1311 | return (bind(sock, (struct sockaddr *)&addr, addrsize) == 0); |
1305 | } | 1312 | } |
1306 | 1313 | ||
1307 | static int make_family(int family) | 1314 | static int make_tox_family(int family) |
1308 | { | 1315 | { |
1309 | switch (family) { | 1316 | switch (family) { |
1317 | case AF_INET: | ||
1318 | return TOX_AF_INET; | ||
1319 | |||
1320 | case AF_INET6: | ||
1321 | return TOX_AF_INET6; | ||
1322 | |||
1323 | case AF_UNSPEC: | ||
1324 | return TOX_AF_UNSPEC; | ||
1325 | |||
1326 | default: | ||
1327 | return family; | ||
1328 | } | ||
1329 | } | ||
1330 | |||
1331 | static int make_family(int tox_family) | ||
1332 | { | ||
1333 | switch (tox_family) { | ||
1310 | case TOX_AF_INET: | 1334 | case TOX_AF_INET: |
1311 | return AF_INET; | 1335 | return AF_INET; |
1312 | 1336 | ||
1313 | case TOX_AF_INET6: | 1337 | case TOX_AF_INET6: |
1314 | return AF_INET6; | 1338 | return AF_INET6; |
1315 | 1339 | ||
1340 | case TOX_AF_UNSPEC: | ||
1341 | return AF_UNSPEC; | ||
1342 | |||
1316 | default: | 1343 | default: |
1317 | return family; | 1344 | return tox_family; |
1318 | } | 1345 | } |
1319 | } | 1346 | } |
1320 | 1347 | ||
diff --git a/toxcore/network.h b/toxcore/network.h index bdf4081f..350ec222 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -111,6 +111,7 @@ typedef enum NET_PACKET_TYPE { | |||
111 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM | 111 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM |
112 | 112 | ||
113 | /* Redefinitions of variables for safe transfer over wire. */ | 113 | /* Redefinitions of variables for safe transfer over wire. */ |
114 | #define TOX_AF_UNSPEC 0 | ||
114 | #define TOX_AF_INET 2 | 115 | #define TOX_AF_INET 2 |
115 | #define TOX_AF_INET6 10 | 116 | #define TOX_AF_INET6 10 |
116 | #define TOX_TCP_INET 130 | 117 | #define TOX_TCP_INET 130 |
@@ -123,10 +124,10 @@ typedef enum NET_PACKET_TYPE { | |||
123 | #define TOX_PROTO_UDP 2 | 124 | #define TOX_PROTO_UDP 2 |
124 | 125 | ||
125 | /* TCP related */ | 126 | /* TCP related */ |
126 | #define TCP_ONION_FAMILY (AF_INET6 + 1) | 127 | #define TCP_ONION_FAMILY (TOX_AF_INET6 + 1) |
127 | #define TCP_INET (AF_INET6 + 2) | 128 | #define TCP_INET (TOX_AF_INET6 + 2) |
128 | #define TCP_INET6 (AF_INET6 + 3) | 129 | #define TCP_INET6 (TOX_AF_INET6 + 3) |
129 | #define TCP_FAMILY (AF_INET6 + 4) | 130 | #define TCP_FAMILY (TOX_AF_INET6 + 4) |
130 | 131 | ||
131 | typedef union { | 132 | typedef union { |
132 | uint8_t uint8[4]; | 133 | uint8_t uint8[4]; |
@@ -174,7 +175,7 @@ uint32_t net_ntohl(uint32_t hostlong); | |||
174 | uint16_t net_ntohs(uint16_t hostshort); | 175 | uint16_t net_ntohs(uint16_t hostshort); |
175 | 176 | ||
176 | /* Does the IP6 struct a contain an IPv4 address in an IPv6 one? */ | 177 | /* Does the IP6 struct a contain an IPv4 address in an IPv6 one? */ |
177 | #define IPV6_IPV4_IN_V6(a) ((a.uint64[0] == 0) && (a.uint32[2] == htonl (0xffff))) | 178 | #define IPV6_IPV4_IN_V6(a) ((a.uint64[0] == 0) && (a.uint32[2] == net_htonl (0xffff))) |
178 | 179 | ||
179 | #define SIZE_IP4 4 | 180 | #define SIZE_IP4 4 |
180 | #define SIZE_IP6 16 | 181 | #define SIZE_IP6 16 |
@@ -206,10 +207,10 @@ const char *ip_ntoa(const IP *ip, char *ip_str, size_t length); | |||
206 | * parses IP structure into an address string | 207 | * parses IP structure into an address string |
207 | * | 208 | * |
208 | * input | 209 | * input |
209 | * ip: ip of AF_INET or AF_INET6 families | 210 | * ip: ip of TOX_AF_INET or TOX_AF_INET6 families |
210 | * length: length of the address buffer | 211 | * length: length of the address buffer |
211 | * Must be at least INET_ADDRSTRLEN for AF_INET | 212 | * Must be at least INET_ADDRSTRLEN for TOX_AF_INET |
212 | * and INET6_ADDRSTRLEN for AF_INET6 | 213 | * and INET6_ADDRSTRLEN for TOX_AF_INET6 |
213 | * | 214 | * |
214 | * output | 215 | * output |
215 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) | 216 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) |
@@ -270,13 +271,13 @@ void ipport_copy(IP_Port *target, const IP_Port *source); | |||
270 | * input | 271 | * input |
271 | * address: a hostname (or something parseable to an IP address) | 272 | * address: a hostname (or something parseable to an IP address) |
272 | * to: to.family MUST be initialized, either set to a specific IP version | 273 | * to: to.family MUST be initialized, either set to a specific IP version |
273 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | 274 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both |
274 | * IP versions are acceptable | 275 | * IP versions are acceptable |
275 | * extra can be NULL and is only set in special circumstances, see returns | 276 | * extra can be NULL and is only set in special circumstances, see returns |
276 | * | 277 | * |
277 | * returns in *to a valid IPAny (v4/v6), | 278 | * returns in *to a valid IPAny (v4/v6), |
278 | * prefers v6 if ip.family was AF_UNSPEC and both available | 279 | * prefers v6 if ip.family was TOX_AF_UNSPEC and both available |
279 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is AF_INET6 | 280 | * returns in *extra an IPv4 address, if family was TOX_AF_UNSPEC and *to is TOX_AF_INET6 |
280 | * returns 0 on failure | 281 | * returns 0 on failure |
281 | */ | 282 | */ |
282 | int addr_resolve(const char *address, IP *to, IP *extra); | 283 | int addr_resolve(const char *address, IP *to, IP *extra); |
@@ -287,12 +288,12 @@ int addr_resolve(const char *address, IP *to, IP *extra); | |||
287 | * | 288 | * |
288 | * address: a hostname (or something parseable to an IP address) | 289 | * address: a hostname (or something parseable to an IP address) |
289 | * to: to.family MUST be initialized, either set to a specific IP version | 290 | * to: to.family MUST be initialized, either set to a specific IP version |
290 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | 291 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both |
291 | * IP versions are acceptable | 292 | * IP versions are acceptable |
292 | * extra can be NULL and is only set in special circumstances, see returns | 293 | * extra can be NULL and is only set in special circumstances, see returns |
293 | * | 294 | * |
294 | * returns in *tro a matching address (IPv6 or IPv4) | 295 | * returns in *tro a matching address (IPv6 or IPv4) |
295 | * returns in *extra, if not NULL, an IPv4 address, if to->family was AF_UNSPEC | 296 | * returns in *extra, if not NULL, an IPv4 address, if to->family was TOX_AF_UNSPEC |
296 | * returns 1 on success | 297 | * returns 1 on success |
297 | * returns 0 on failure | 298 | * returns 0 on failure |
298 | */ | 299 | */ |
@@ -394,7 +395,7 @@ int net_connect(Socket sock, IP_Port ip_port); | |||
394 | * return number of elements in res array | 395 | * return number of elements in res array |
395 | * and -1 on error. | 396 | * and -1 on error. |
396 | */ | 397 | */ |
397 | int32_t net_getipport(const char *node, IP_Port **res, int type); | 398 | int32_t net_getipport(const char *node, IP_Port **res, int tox_type); |
398 | 399 | ||
399 | /* Deallocates memory allocated by net_getipport | 400 | /* Deallocates memory allocated by net_getipport |
400 | */ | 401 | */ |
diff --git a/toxcore/onion.c b/toxcore/onion.c index 60fdcce0..805770fa 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c | |||
@@ -78,12 +78,11 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bo | |||
78 | memcpy(target->ip6.uint8, data + 1, SIZE_IP6); | 78 | memcpy(target->ip6.uint8, data + 1, SIZE_IP6); |
79 | } | 79 | } |
80 | 80 | ||
81 | if (!disable_family_check) { | 81 | bool valid = disable_family_check || |
82 | return to_host_family(target); | 82 | target->family == TOX_AF_INET || |
83 | } | 83 | target->family == TOX_AF_INET6; |
84 | 84 | ||
85 | to_host_family(target); | 85 | return valid ? 0 : -1; |
86 | return 0; | ||
87 | } | 86 | } |
88 | 87 | ||
89 | static void ipport_pack(uint8_t *data, const IP_Port *source) | 88 | static void ipport_pack(uint8_t *data, const IP_Port *source) |
@@ -617,7 +616,9 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
617 | 616 | ||
618 | uint16_t data_len = length - (1 + RETURN_1); | 617 | uint16_t data_len = length - (1 + RETURN_1); |
619 | 618 | ||
620 | if (onion->recv_1_function && send_to.ip.family != AF_INET && send_to.ip.family != AF_INET6) { | 619 | if (onion->recv_1_function && |
620 | send_to.ip.family != TOX_AF_INET && | ||
621 | send_to.ip.family != TOX_AF_INET6) { | ||
621 | return onion->recv_1_function(onion->callback_object, send_to, packet + (1 + RETURN_1), data_len); | 622 | return onion->recv_1_function(onion->callback_object, send_to, packet + (1 + RETURN_1), data_len); |
622 | } | 623 | } |
623 | 624 | ||
diff --git a/toxcore/onion.h b/toxcore/onion.h index 1dcaa0fe..e81b3a52 100644 --- a/toxcore/onion.h +++ b/toxcore/onion.h | |||
@@ -145,12 +145,12 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, | |||
145 | * | 145 | * |
146 | * Used to handle these packets that are received in a non traditional way (by TCP for example). | 146 | * Used to handle these packets that are received in a non traditional way (by TCP for example). |
147 | * | 147 | * |
148 | * Source family must be set to something else than AF_INET6 or AF_INET so that the callback gets called | 148 | * Source family must be set to something else than TOX_AF_INET6 or TOX_AF_INET so that the callback gets called |
149 | * when the response is received. | 149 | * when the response is received. |
150 | */ | 150 | */ |
151 | int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce); | 151 | int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce); |
152 | 152 | ||
153 | /* Set the callback to be called when the dest ip_port doesn't have AF_INET6 or AF_INET as the family. | 153 | /* Set the callback to be called when the dest ip_port doesn't have TOX_AF_INET6 or TOX_AF_INET as the family. |
154 | * | 154 | * |
155 | * Format: function(void *object, IP_Port dest, uint8_t *data, uint16_t length) | 155 | * Format: function(void *object, IP_Port dest, uint8_t *data, uint16_t length) |
156 | */ | 156 | */ |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 91b5b067..94e9c916 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) | 44 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
45 | { | 45 | { |
46 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) { | 46 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { |
47 | return -1; | 47 | return -1; |
48 | } | 48 | } |
49 | 49 | ||
@@ -76,7 +76,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t | |||
76 | */ | 76 | */ |
77 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) | 77 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
78 | { | 78 | { |
79 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) { | 79 | if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { |
80 | return -1; | 80 | return -1; |
81 | } | 81 | } |
82 | 82 | ||
@@ -345,7 +345,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t | |||
345 | static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, IP_Port dest, | 345 | static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, IP_Port dest, |
346 | const uint8_t *data, uint16_t length) | 346 | const uint8_t *data, uint16_t length) |
347 | { | 347 | { |
348 | if (path->ip_port1.ip.family == AF_INET || path->ip_port1.ip.family == AF_INET6) { | 348 | if (path->ip_port1.ip.family == TOX_AF_INET || path->ip_port1.ip.family == TOX_AF_INET6) { |
349 | uint8_t packet[ONION_MAX_PACKET_SIZE]; | 349 | uint8_t packet[ONION_MAX_PACKET_SIZE]; |
350 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); | 350 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); |
351 | 351 | ||
@@ -866,7 +866,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con | |||
866 | for (i = 0; i < num_nodes; ++i) { | 866 | for (i = 0; i < num_nodes; ++i) { |
867 | uint8_t family = nodes[i].ip_port.ip.family; | 867 | uint8_t family = nodes[i].ip_port.ip.family; |
868 | 868 | ||
869 | if (family == AF_INET || family == AF_INET6) { | 869 | if (family == TOX_AF_INET || family == TOX_AF_INET6) { |
870 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); | 870 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); |
871 | } else if (family == TCP_INET || family == TCP_INET6) { | 871 | } else if (family == TCP_INET || family == TCP_INET6) { |
872 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { | 872 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { |
diff --git a/toxcore/ping.c b/toxcore/ping.c index 36c32c61..72b3fe62 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -249,7 +249,7 @@ static int in_list(const Client_data *list, uint16_t length, const uint8_t *publ | |||
249 | if (id_equal(list[i].public_key, public_key)) { | 249 | if (id_equal(list[i].public_key, public_key)) { |
250 | const IPPTsPng *ipptp; | 250 | const IPPTsPng *ipptp; |
251 | 251 | ||
252 | if (ip_port.ip.family == AF_INET) { | 252 | if (ip_port.ip.family == TOX_AF_INET) { |
253 | ipptp = &list[i].assoc4; | 253 | ipptp = &list[i].assoc4; |
254 | } else { | 254 | } else { |
255 | ipptp = &list[i].assoc6; | 255 | ipptp = &list[i].assoc6; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 572b4a84..db3ed4a5 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -246,7 +246,7 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t * | |||
246 | unsigned int i; | 246 | unsigned int i; |
247 | 247 | ||
248 | for (i = 0; i < count; i++) { | 248 | for (i = 0; i < count; i++) { |
249 | root[i].port = htons(port); | 249 | root[i].port = net_htons(port); |
250 | 250 | ||
251 | Messenger *m = tox; | 251 | Messenger *m = tox; |
252 | onion_add_bs_path_node(m->onion_c, root[i], public_key); | 252 | onion_add_bs_path_node(m->onion_c, root[i], public_key); |
@@ -290,7 +290,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8 | |||
290 | unsigned int i; | 290 | unsigned int i; |
291 | 291 | ||
292 | for (i = 0; i < count; i++) { | 292 | for (i = 0; i < count; i++) { |
293 | root[i].port = htons(port); | 293 | root[i].port = net_htons(port); |
294 | 294 | ||
295 | Messenger *m = tox; | 295 | Messenger *m = tox; |
296 | add_tcp_relay(m->net_crypto, root[i], public_key); | 296 | add_tcp_relay(m->net_crypto, root[i], public_key); |