]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: add union inaddr
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 20 Feb 2017 07:06:57 +0000 (08:06 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 20 Feb 2017 10:40:09 +0000 (11:40 +0100)
It will be a useful idiom for IP address storage and correct conversion
of sockaddr* pointers.

daemon/worker.h
lib/nsrep.h
lib/utils.h

index 49fc855e7179a6eed60bba30afd6634ff902a4b3..5e9b168d7faec64e738241bbf3813f5a5e3ab5b7 100644 (file)
@@ -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;
index 5e4eed8388532b83dcf7ff8c993a486b1bd5a969..a0d9aeb90d56081cce1673a14f2968de7e35cee1 100644 (file)
@@ -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. */
index 041edc017c84c684d41ee22437545349b9b49f85..fe50417ba00b0655988016700a5b4b7769e2ff59 100644 (file)
@@ -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);