Code cleanup

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-04-06 10:11:00 +00:00
parent 2f304c1afc
commit 7fde67f3d3

13
mud.c
View File

@@ -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);