From 83224a68d70de47c4be89878be412dc73ee7d118 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 20 Feb 2017 08:06:57 +0100 Subject: [PATCH] utils: add union inaddr It will be a useful idiom for IP address storage and correct conversion of sockaddr* pointers. --- daemon/worker.h | 10 ++-------- lib/nsrep.h | 6 +----- lib/utils.h | 7 +++++++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/daemon/worker.h b/daemon/worker.h index 49fc855e7..5e9b168d7 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -120,14 +120,8 @@ struct qr_task worker_cb_t on_complete; void *baton; struct { - union { - struct sockaddr_in ip4; - struct sockaddr_in6 ip6; - } addr; - union { - struct sockaddr_in ip4; - struct sockaddr_in6 ip6; - } dst_addr; + union inaddr addr; + union inaddr dst_addr; uv_handle_t *handle; } source; uint32_t refs; diff --git a/lib/nsrep.h b/lib/nsrep.h index 5e4eed838..a0d9aeb90 100644 --- a/lib/nsrep.h +++ b/lib/nsrep.h @@ -78,11 +78,7 @@ struct kr_nsrep unsigned reputation; /**< NS reputation */ const knot_dname_t *name; /**< NS name */ struct kr_context *ctx; /**< Resolution context */ - union { - struct sockaddr ip; - struct sockaddr_in ip4; - struct sockaddr_in6 ip6; - } addr[KR_NSREP_MAXADDR]; /**< NS address(es) */ + union inaddr addr[KR_NSREP_MAXADDR]; /**< NS address(es) */ }; /** @internal Address bytes for given family. */ diff --git a/lib/utils.h b/lib/utils.h index 041edc017..fe50417ba 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -137,6 +137,13 @@ KR_EXPORT int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl, uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen); +/** Simple storage for IPx address or AF_UNSPEC. */ +union inaddr { + struct sockaddr ip; + struct sockaddr_in ip4; + struct sockaddr_in6 ip6; +}; + /** Address bytes for given family. */ KR_EXPORT KR_PURE const char *kr_inaddr(const struct sockaddr *addr); -- 2.47.2