From 7fde67f3d33b3ccd7b2ff8918e1cfb1857c8d691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Fri, 6 Apr 2018 10:11:00 +0000 Subject: [PATCH] Code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mud.c b/mud.c index fd0c3bb..e03fe1b 100644 --- a/mud.c +++ b/mud.c @@ -184,6 +184,17 @@ struct mud { } remote, local; }; +static int +mud_addr_is_v6(struct mud_addr *addr) +{ + static const unsigned char v4mapped[] = { + [10] = 255, + [11] = 255, + }; + + return memcmp(addr->v6, v4mapped, sizeof(v4mapped)); +} + static int mud_encrypt_opt(const struct mud_crypto_key *k, const struct mud_crypto_opt *c) { @@ -1175,7 +1186,7 @@ mud_compute_rtt(const uint64_t rtt, const uint64_t new_rtt) static void mud_ss_from_packet(struct sockaddr_storage *ss, struct mud_packet *pkt) { - if (memcmp(pkt->hdr.addr.v6, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12)) { + if (mud_addr_is_v6(&pkt->hdr.addr)) { ss->ss_family = AF_INET6; memcpy(&((struct sockaddr_in6 *)ss)->sin6_addr, pkt->hdr.addr.v6, 16); memcpy(&((struct sockaddr_in6 *)ss)->sin6_port, pkt->hdr.addr.port, 2);