diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index 213e70570ce..18c0f1f8658 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -36,34 +36,38 @@ static const struct BootstrapNodes { const uint8_t key[32]; } bootstrap_nodes[] = { { - "tox.abilinski.com", 33445, - 0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E, - 0x34, 0x3E, 0x2A, 0xEB, 0xA0, 0x71, 0x15, 0xA5, - 0xC2, 0x89, 0x20, 0xE9, 0xC8, 0xD2, 0x94, 0x92, - 0xF6, 0xD0, 0x0B, 0x29, 0x04, 0x9E, 0xDC, 0x7E, + "tox.abilinski.com", 33445, { + 0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E, + 0x34, 0x3E, 0x2A, 0xEB, 0xA0, 0x71, 0x15, 0xA5, + 0xC2, 0x89, 0x20, 0xE9, 0xC8, 0xD2, 0x94, 0x92, + 0xF6, 0xD0, 0x0B, 0x29, 0x04, 0x9E, 0xDC, 0x7E, + }, }, { - "tox.initramfs.io", 33445, - 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, - 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, - 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, - 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, + "tox.initramfs.io", 33445, { + 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, + 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, + 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, + 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, + }, }, { - "tox.plastiras.org", 33445, - 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, - 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, - 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, - 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, + "tox.plastiras.org", 33445, { + 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, + 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, + 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, + 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, + }, }, { - "tox.novg.net", 33445, - 0xD5, 0x27, 0xE5, 0x84, 0x7F, 0x83, 0x30, 0xD6, - 0x28, 0xDA, 0xB1, 0x81, 0x4F, 0x0A, 0x42, 0x2F, - 0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57, - 0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63, + "tox.novg.net", 33445, { + 0xD5, 0x27, 0xE5, 0x84, 0x7F, 0x83, 0x30, 0xD6, + 0x28, 0xDA, 0xB1, 0x81, 0x4F, 0x0A, 0x42, 0x2F, + 0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57, + 0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63, + }, }, - { nullptr, 0, 0 }, + { nullptr, 0, {0} }, }; void bootstrap_tox_live_network(Tox *tox, bool enable_tcp) diff --git a/auto_tests/forwarding_test.c b/auto_tests/forwarding_test.c index 9cad1d3715a..75e330a73e9 100644 --- a/auto_tests/forwarding_test.c +++ b/auto_tests/forwarding_test.c @@ -126,7 +126,7 @@ static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp, subtox->dht = new_dht(subtox->log, mem, rng, ns, subtox->mono_time, subtox->net, true, true); - const TCP_Proxy_Info inf = {{{0}}}; + const TCP_Proxy_Info inf = {{{{0}}}}; subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf); subtox->forwarding = new_forwarding(subtox->log, rng, subtox->mono_time, subtox->dht); diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index b55bdb9e5c2..ef0c7ba2a00 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -36,7 +36,7 @@ static void test_addr_resolv_localhost(void) net_kill_strerror(strerror); Ip_Ntoa ip_str; - ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4, got %u.", ip.family); + ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4, got %u.", ip.family.value); const uint32_t loopback = get_ip4_loopback().uint32; ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", net_ip_ntoa(&ip, &ip_str)); @@ -59,7 +59,7 @@ static void test_addr_resolv_localhost(void) net_kill_strerror(strerror); ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family NET_FAMILY_IPV6 (%d), got %u.", NET_FAMILY_IPV6, - ip.family); + ip.family.value); IP6 ip6_loopback = get_ip6_loopback(); ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", net_ip_ntoa(&ip, &ip_str)); @@ -83,17 +83,17 @@ static void test_addr_resolv_localhost(void) #if USE_IPV6 ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family NET_FAMILY_IPV6 (%d), got %u.", NET_FAMILY_IPV6, - ip.family); + ip.family.value); ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", net_ip_ntoa(&ip, &ip_str)); ck_assert_msg(net_family_is_ipv4(extra.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4, - extra.family); + extra.family.value); ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", net_ip_ntoa(&ip, &ip_str)); #elif 0 // TODO(iphydf): Fix this to work on IPv6-supporting systems. - ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4, ip.family); + ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family NET_FAMILY_IPV4 (%d), got %u.", NET_FAMILY_IPV4, ip.family.value); ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", net_ip_ntoa(&ip, &ip_str)); #endif diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 0815a9bcdc1..3a81df41b8f 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -471,7 +471,7 @@ static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, u return nullptr; } - TCP_Proxy_Info inf = {{{0}}}; + TCP_Proxy_Info inf = {{{{0}}}}; on->onion_c = new_onion_client(on->log, mem, rng, on->mono_time, new_net_crypto(on->log, mem, rng, ns, on->mono_time, dht, &inf)); if (!on->onion_c) { diff --git a/toxcore/DHT.c b/toxcore/DHT.c index c427fdcd1cb..2567d1b5a8f 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -606,7 +606,7 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv%d)", index, ip_version); /* kill the other address, if it was set */ - const IPPTsPng empty_ipptspng = {{{0}}}; + const IPPTsPng empty_ipptspng = {{{{0}}}}; *assoc = empty_ipptspng; return true; } @@ -964,7 +964,7 @@ static void update_client_with_reset(const Mono_Time *mono_time, Client_data *cl ipptp_write->ret_ip_self = false; /* zero out other address */ - const IPPTsPng empty_ipptp = {{{0}}}; + const IPPTsPng empty_ipptp = {{{{0}}}}; *ipptp_clear = empty_ipptp; } diff --git a/toxcore/DHT_test.cc b/toxcore/DHT_test.cc index 20dd9beea90..6fba834239a 100644 --- a/toxcore/DHT_test.cc +++ b/toxcore/DHT_test.cc @@ -116,7 +116,7 @@ TEST(AddToList, OverridesKeysWithCloserKeys) std::array nodes{}; - IP_Port ip_port = {NET_FAMILY_UNSPEC}; + IP_Port ip_port = {{{NET_FAMILY_UNSPEC}}}; EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[0].data(), &ip_port, self_pk.data())); EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[1].data(), &ip_port, self_pk.data())); EXPECT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[2].data(), &ip_port, self_pk.data())); @@ -355,7 +355,7 @@ TEST(AnnounceNodes, SetAndTest) PublicKey pk2(to_array(pk_data)); ASSERT_NE(pk2, pk1); - IP_Port ip_port = {NET_FAMILY_UNSPEC}; + IP_Port ip_port = {{{NET_FAMILY_UNSPEC}}}; ip_port.ip.family = net_family_ipv4(); set_announce_node(dht.get(), pk1.data()); diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 34d7840ea06..2b8c6e448f5 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -594,7 +594,7 @@ TCP_Client_Connection *new_tcp_connection( return nullptr; } - const TCP_Proxy_Info default_proxyinfo = {{{0}}}; + const TCP_Proxy_Info default_proxyinfo = {{{{0}}}}; if (proxy_info == nullptr) { proxy_info = &default_proxyinfo; diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 096420271fc..7892feb6369 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -578,7 +578,7 @@ void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c, */ IP_Port tcp_connections_number_to_ip_port(unsigned int tcp_connections_number) { - IP_Port ip_port = {{0}}; + IP_Port ip_port = {{{0}}}; ip_port.ip.family = net_family_tcp_server(); ip_port.ip.ip.v6.uint32[0] = tcp_connections_number; return ip_port; diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 70831cbff9a..1363d902207 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -355,7 +355,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con return -1; } - const IP_Port ipp = {{0}}; + const IP_Port ipp = {{{0}}}; if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp)) { crypto_memzero(shared_key, sizeof(shared_key)); @@ -584,7 +584,7 @@ static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *co */ static IP_Port con_id_to_ip_port(uint32_t con_id, uint64_t identifier) { - IP_Port ip_port = {{0}}; + IP_Port ip_port = {{{0}}}; ip_port.ip.family = net_family_tcp_client(); ip_port.ip.ip.v6.uint32[0] = con_id; ip_port.ip.ip.v6.uint64[1] = identifier; @@ -919,7 +919,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns, const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP); if (!sock_valid(sock)) { - LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family); + LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family.value); return net_invalid_socket(); } @@ -938,7 +938,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns, if (!ok) { char *const error = net_new_strerror(net_error()); LOGGER_WARNING(logger, "could not bind to TCP port %d (family = %d): %s", - port, family, error != nullptr ? error : "(null)"); + port, family.value, error != nullptr ? error : "(null)"); net_kill_strerror(error); kill_sock(ns, sock); return net_invalid_socket(); diff --git a/toxcore/group_announce_test.cc b/toxcore/group_announce_test.cc index 2918dc76c67..e50bd627f94 100644 --- a/toxcore/group_announce_test.cc +++ b/toxcore/group_announce_test.cc @@ -215,7 +215,7 @@ TEST_F(AnnouncesPack, AnnouncesValidationCheck) EXPECT_EQ(gca_is_valid_announce(nullptr), false); #endif - GC_Announce announce = {0}; + GC_Announce announce = {{{{0}}}}; EXPECT_EQ(gca_is_valid_announce(&announce), false); EXPECT_EQ(gca_is_valid_announce(&announces_[0]), true); EXPECT_EQ(gca_is_valid_announce(&announces_[1]), true); diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index c113107270e..fae54c62122 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -2491,7 +2491,7 @@ static int handle_gc_ping(GC_Chat *chat, GC_Connection *gconn, const uint8_t *da do_gc_peer_state_sync(chat, gconn, data, length); if (length > GC_PING_PACKET_MIN_DATA_SIZE) { - IP_Port ip_port = {{0}}; + IP_Port ip_port = {{{0}}}; if (unpack_ip_port(&ip_port, data + GC_PING_PACKET_MIN_DATA_SIZE, length - GC_PING_PACKET_MIN_DATA_SIZE, false) > 0) { diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 798422c7958..dfac7e8e968 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -624,7 +624,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, const non_null() static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connection_id) { - const IP_Port empty = {{0}}; + const IP_Port empty = {{{0}}}; const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -2023,7 +2023,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, const IP_Port *source, return -1; } - New_Connection n_c = {{{0}}}; + New_Connection n_c = {{{{0}}}}; n_c.cookie = cookie; n_c.source = *source; n_c.cookie_length = COOKIE_LENGTH; diff --git a/toxcore/network.c b/toxcore/network.c index f86ce1ba346..68a2b8e84cd 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -277,16 +277,15 @@ static int make_family(Family tox_family) } } -// TODO(https://github.com/TokTok/c-toxcore/pull/2595): Remove casts. -static const Family family_unspec = (force Family)NET_FAMILY_UNSPEC; -static const Family family_ipv4 = (force Family)NET_FAMILY_IPV4; -static const Family family_ipv6 = (force Family)NET_FAMILY_IPV6; -static const Family family_tcp_server = (force Family)NET_FAMILY_TCP_SERVER; -static const Family family_tcp_client = (force Family)NET_FAMILY_TCP_CLIENT; -static const Family family_tcp_ipv4 = (force Family)NET_FAMILY_TCP_IPV4; -static const Family family_tcp_ipv6 = (force Family)NET_FAMILY_TCP_IPV6; -static const Family family_tox_tcp_ipv4 = (force Family)NET_FAMILY_TOX_TCP_IPV4; -static const Family family_tox_tcp_ipv6 = (force Family)NET_FAMILY_TOX_TCP_IPV6; +static const Family family_unspec = {(force Family_Value)NET_FAMILY_UNSPEC}; +static const Family family_ipv4 = {(force Family_Value)NET_FAMILY_IPV4}; +static const Family family_ipv6 = {(force Family_Value)NET_FAMILY_IPV6}; +static const Family family_tcp_server = {(force Family_Value)NET_FAMILY_TCP_SERVER}; +static const Family family_tcp_client = {(force Family_Value)NET_FAMILY_TCP_CLIENT}; +static const Family family_tcp_ipv4 = {(force Family_Value)NET_FAMILY_TCP_IPV4}; +static const Family family_tcp_ipv6 = {(force Family_Value)NET_FAMILY_TCP_IPV6}; +static const Family family_tox_tcp_ipv4 = {(force Family_Value)NET_FAMILY_TOX_TCP_IPV4}; +static const Family family_tox_tcp_ipv6 = {(force Family_Value)NET_FAMILY_TOX_TCP_IPV6}; static const Family *make_tox_family(int family) { @@ -351,15 +350,15 @@ bool net_family_from_int(uint8_t family, Net_Family *out) } } -Family family_from_net_family(Net_Family family) +Family family_from_net_family(Net_Family value) { - return (force Family)family; + const Family family = {(force Family_Value)value}; + return family; } uint8_t family_to_int(Family family) { - // TODO(https://github.com/TokTok/c-toxcore/pull/2595): Remove force. - return (force uint8_t)family; + return (force uint8_t)family.value; } non_null() @@ -490,47 +489,47 @@ Family net_family_tox_tcp_ipv6(void) bool net_family_is_unspec(Family family) { - return family == family_unspec; + return family.value == family_unspec.value; } bool net_family_is_ipv4(Family family) { - return family == family_ipv4; + return family.value == family_ipv4.value; } bool net_family_is_ipv6(Family family) { - return family == family_ipv6; + return family.value == family_ipv6.value; } bool net_family_is_tcp_server(Family family) { - return family == family_tcp_server; + return family.value == family_tcp_server.value; } bool net_family_is_tcp_client(Family family) { - return family == family_tcp_client; + return family.value == family_tcp_client.value; } bool net_family_is_tcp_ipv4(Family family) { - return family == family_tcp_ipv4; + return family.value == family_tcp_ipv4.value; } bool net_family_is_tcp_ipv6(Family family) { - return family == family_tcp_ipv6; + return family.value == family_tcp_ipv6.value; } bool net_family_is_tox_tcp_ipv4(Family family) { - return family == family_tox_tcp_ipv4; + return family.value == family_tox_tcp_ipv4.value; } bool net_family_is_tox_tcp_ipv6(Family family) { - return family == family_tox_tcp_ipv6; + return family.value == family_tox_tcp_ipv6.value; } bool sock_valid(Socket sock) @@ -1011,7 +1010,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe // all-zero ip_port. Ip_Ntoa ip_str; LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket (%s)", - ipp_copy.ip.family, net_ip_ntoa(&ipp_copy.ip, &ip_str)); + ipp_copy.ip.family.value, net_ip_ntoa(&ipp_copy.ip, &ip_str)); return -1; } @@ -1050,7 +1049,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe addr6->sin6_flowinfo = 0; addr6->sin6_scope_id = 0; } else { - LOGGER_ERROR(net->log, "unknown address type: %d", ipp_copy.ip.family); + LOGGER_ERROR(net->log, "unknown address type: %d", ipp_copy.ip.family.value); return -1; } @@ -1212,7 +1211,7 @@ Networking_Core *new_networking_ex( /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ if (!net_family_is_ipv4(ip->family) && !net_family_is_ipv6(ip->family)) { - LOGGER_ERROR(log, "invalid address family: %u", ip->family); + LOGGER_ERROR(log, "invalid address family: %u", ip->family.value); return nullptr; } @@ -1455,7 +1454,7 @@ bool ip_equal(const IP *a, const IP *b) } /* same family */ - if (a->family == b->family) { + if (a->family.value == b->family.value) { if (net_family_is_ipv4(a->family) || net_family_is_tcp_ipv4(a->family)) { struct in_addr addr_a; struct in_addr addr_b; @@ -1563,7 +1562,7 @@ int ipport_cmp_handler(const void *a, const void *b, size_t size) return cmp_uint(ipp_a->port, ipp_b->port); } -static const IP empty_ip = {0}; +static const IP empty_ip = {{0}}; /** nulls out ip */ void ip_reset(IP *ip) @@ -1575,7 +1574,7 @@ void ip_reset(IP *ip) *ip = empty_ip; } -static const IP_Port empty_ip_port = {{0}}; +static const IP_Port empty_ip_port = {{{0}}}; /** nulls out ip_port */ void ipport_reset(IP_Port *ipport) @@ -1799,7 +1798,7 @@ const char *net_ip_ntoa(const IP *ip, Ip_Ntoa *ip_str) } if (!ip_parse_addr(ip, ip_str->buf, sizeof(ip_str->buf))) { - snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid, family %u)", ip->family); + snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid, family %u)", ip->family.value); ip_str->length = (uint16_t)strlen(ip_str->buf); return ip_str->buf; } @@ -2043,7 +2042,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, Tox_So assert(node != nullptr); // Try parsing as IP address first. - IP_Port parsed = {{0}}; + IP_Port parsed = {{{0}}}; // Initialise to nullptr. In error paths, at least we initialise the out // parameter. *res = nullptr; diff --git a/toxcore/network.h b/toxcore/network.h index b6877f01c40..3cb29f0c714 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -96,15 +96,16 @@ typedef enum Net_Family { NET_FAMILY_TCP_SERVER = NET_FAMILY_IPV6 + 4, } Net_Family; -// TODO(https://github.com/TokTok/c-toxcore/pull/2595): Use the enum. -typedef bitwise uint8_t Family; +typedef bitwise uint8_t Family_Value; + +typedef struct Family { + Family_Value value; +} Family; non_null() bool net_family_from_int(uint8_t family, Net_Family *out); -// TODO(https://github.com/TokTok/c-toxcore/pull/2595): Remove. -Family family_from_net_family(Net_Family family); -// TODO(https://github.com/TokTok/c-toxcore/pull/2595): Rename to family_to_int. +Family family_from_net_family(Net_Family value); uint8_t family_to_int(Family family); bool net_family_is_unspec(Family family); diff --git a/toxcore/network_test.cc b/toxcore/network_test.cc index cd0df523ca8..a9fa6d800f4 100644 --- a/toxcore/network_test.cc +++ b/toxcore/network_test.cc @@ -74,8 +74,8 @@ TEST(IpportCmp, BehavesLikeMemcmp) { auto cmp_val = [](int val) { return val < 0 ? -1 : val > 0 ? 1 : 0; }; - IP_Port a = {NET_FAMILY_UNSPEC}; - IP_Port b = {NET_FAMILY_UNSPEC}; + IP_Port a = {{{NET_FAMILY_UNSPEC}}}; + IP_Port b = {{{NET_FAMILY_UNSPEC}}}; a.ip.family = net_family_ipv4(); b.ip.family = net_family_ipv4(); @@ -109,8 +109,8 @@ TEST(IpportCmp, BehavesLikeMemcmp) TEST(IpportCmp, Ipv6BeginAndEndCompareCorrectly) { - IP_Port a = {NET_FAMILY_UNSPEC}; - IP_Port b = {NET_FAMILY_UNSPEC}; + IP_Port a = {{{NET_FAMILY_UNSPEC}}}; + IP_Port b = {{{NET_FAMILY_UNSPEC}}}; a.ip.family = net_family_ipv6(); b.ip.family = net_family_ipv6(); @@ -130,8 +130,8 @@ TEST(IpportCmp, Ipv6BeginAndEndCompareCorrectly) TEST(IpportCmp, UnspecAlwaysComparesEqual) { - IP_Port a = {NET_FAMILY_UNSPEC}; - IP_Port b = {NET_FAMILY_UNSPEC}; + IP_Port a = {{{NET_FAMILY_UNSPEC}}}; + IP_Port b = {{{NET_FAMILY_UNSPEC}}}; a.ip.family = net_family_unspec(); b.ip.family = net_family_unspec(); diff --git a/toxcore/network_test_util.cc b/toxcore/network_test_util.cc index 10a24c896fc..fdf55f2a63e 100644 --- a/toxcore/network_test_util.cc +++ b/toxcore/network_test_util.cc @@ -106,6 +106,8 @@ IP_Port random_ip_port(const Random *rng) return ip_port; } +bool operator==(Family const &a, Family const &b) { return a.value == b.value; } + bool operator==(IP4 const &a, IP4 const &b) { return a.uint32 == b.uint32; } bool operator==(IP6 const &a, IP6 const &b) diff --git a/toxcore/network_test_util.hh b/toxcore/network_test_util.hh index de66f51e08d..b8254e35b7a 100644 --- a/toxcore/network_test_util.hh +++ b/toxcore/network_test_util.hh @@ -83,6 +83,7 @@ public: IP_Port operator()(); }; +bool operator==(Family const &a, Family const &b); bool operator==(IP4 const &a, IP4 const &b); bool operator==(IP6 const &a, IP6 const &b); bool operator==(IP const &a, IP const &b); diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index bd72522dd5d..9b0ac96102a 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1236,7 +1236,7 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length, return 1; } - IP_Port ip_port = {{0}}; + IP_Port ip_port = {{{0}}}; ip_port.ip.family = net_family_tcp_server(); if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) {