]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Reduce use of s6_addr
authorRoy Marples <roy@marples.name>
Fri, 11 Jul 2014 13:24:29 +0000 (13:24 +0000)
committerRoy Marples <roy@marples.name>
Fri, 11 Jul 2014 13:24:29 +0000 (13:24 +0000)
if-bsd.c
ipv6.c
ipv6nd.c

index ca2eb8c8d8b281b7cb6db6d378264095cb1ed373..5bc30fd4947f50300c776b1d2a160e26e07d19d8 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -888,9 +888,7 @@ if_managelink(struct dhcpcd_ctx *ctx)
                        case AF_INET6:
                                sin6 = (struct sockaddr_in6*)(void *)
                                    rti_info[RTAX_IFA];
-                               memcpy(ia6.s6_addr,
-                                   sin6->sin6_addr.s6_addr,
-                                   sizeof(ia6.s6_addr));
+                               ia6 = sin6->sin6_addr;
                                if (rtm->rtm_type == RTM_NEWADDR) {
                                        ifa_flags = if_addrflags6(ifname, &ia6);
                                        if (ifa_flags == -1)
diff --git a/ipv6.c b/ipv6.c
index 44cca62cafcb150488d7f107f2edd5ca0f3eb2cf..3bf4bc05b4261d90a4c3bfcdc2b7ad418ad177fd 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -783,8 +783,7 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
                        if (ap == NULL) {
                                ap = calloc(1, sizeof(*ap));
                                ap->iface = ifp;
-                               memcpy(ap->addr.s6_addr, addr->s6_addr,
-                                   sizeof(ap->addr.s6_addr));
+                               ap->addr = *addr;
                                TAILQ_INSERT_TAIL(&state->addrs,
                                    ap, next);
                        }
@@ -1113,10 +1112,8 @@ desc_route(const char *cmd, const struct rt6 *rt)
        char gatebuf[INET6_ADDRSTRLEN];
        const char *ifname = rt->iface->name, *dest, *gate;
 
-       dest = inet_ntop(AF_INET6, &rt->dest.s6_addr,
-           destbuf, INET6_ADDRSTRLEN);
-       gate = inet_ntop(AF_INET6, &rt->gate.s6_addr,
-           gatebuf, INET6_ADDRSTRLEN);
+       dest = inet_ntop(AF_INET6, &rt->dest, destbuf, INET6_ADDRSTRLEN);
+       gate = inet_ntop(AF_INET6, &rt->gate, gatebuf, INET6_ADDRSTRLEN);
        if (IN6_ARE_ADDR_EQUAL(&rt->gate, &in6addr_any))
                syslog(LOG_INFO, "%s: %s route to %s/%d", ifname, cmd,
                    dest, ipv6_prefixlen(&rt->net));
index f75115290c6d5453eea85a20a366a69b15f67a2e..26878914a43218468904814dbb9b6db9363927ad 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -279,7 +279,7 @@ ipv6nd_sendrsprobe(void *arg)
        dst.sin6_len = sizeof(dst);
 #endif
        dst.sin6_scope_id = ifp->index;
-       if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr.s6_addr) != 1) {
+       if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr) != 1) {
                syslog(LOG_ERR, "%s: %m", __func__);
                return;
        }
@@ -624,8 +624,7 @@ ipv6nd_dadcallback(void *arg)
                        ap->dadcounter = dadcounter;
                        ap->flags &= ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
                        ap->flags |= IPV6_AF_NEW;
-                       p = inet_ntop(AF_INET6, ap->addr.s6_addr,
-                           buf, sizeof(buf));
+                       p = inet_ntop(AF_INET6, &ap->addr, buf, sizeof(buf));
                        if (p)
                                snprintf(ap->saddr,
                                    sizeof(ap->saddr),
@@ -731,8 +730,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
 
        TAILQ_FOREACH(rap, ctx->ra_routers, next) {
                if (ifp == rap->iface &&
-                   memcmp(rap->from.s6_addr, ctx->from.sin6_addr.s6_addr,
-                   sizeof(rap->from.s6_addr)) == 0)
+                   IN6_ARE_ADDR_EQUAL(&rap->from, &ctx->from.sin6_addr))
                        break;
        }
 
@@ -761,8 +759,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                        return;
                }
                rap->iface = ifp;
-               memcpy(rap->from.s6_addr, ctx->from.sin6_addr.s6_addr,
-                   sizeof(rap->from.s6_addr));
+               rap->from = ctx->from.sin6_addr;
                strlcpy(rap->sfrom, ctx->sfrom, sizeof(rap->sfrom));
                TAILQ_INIT(&rap->addrs);
                TAILQ_INIT(&rap->options);
@@ -849,9 +846,8 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                        }
                        TAILQ_FOREACH(ap, &rap->addrs, next)
                                if (ap->prefix_len ==pi->nd_opt_pi_prefix_len &&
-                                   memcmp(ap->prefix.s6_addr,
-                                   pi->nd_opt_pi_prefix.s6_addr,
-                                   sizeof(ap->prefix.s6_addr)) == 0)
+                                   IN6_ARE_ADDR_EQUAL(&ap->prefix,
+                                   &pi->nd_opt_pi_prefix))
                                        break;
                        if (ap == NULL) {
                                if (!(pi->nd_opt_pi_flags_reserved &
@@ -865,9 +861,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                                ap->iface = rap->iface;
                                ap->flags = IPV6_AF_NEW;
                                ap->prefix_len = pi->nd_opt_pi_prefix_len;
-                               memcpy(ap->prefix.s6_addr,
-                                  pi->nd_opt_pi_prefix.s6_addr,
-                                  sizeof(ap->prefix.s6_addr));
+                               ap->prefix = pi->nd_opt_pi_prefix;
                                if (pi->nd_opt_pi_flags_reserved &
                                    ND_OPT_PI_FLAG_AUTO)
                                {
@@ -881,7 +875,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                                                break;
                                        }
                                        cbp = inet_ntop(AF_INET6,
-                                           ap->addr.s6_addr,
+                                           &ap->addr,
                                            buf, sizeof(buf));
                                        if (cbp)
                                                snprintf(ap->saddr,
@@ -944,7 +938,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                        op += sizeof(rdnss->nd_opt_rdnss_lifetime);
                        l = 0;
                        for (n = ndo->nd_opt_len - 1; n > 1; n -= 2,
-                           op += sizeof(addr.s6_addr))
+                           op += sizeof(addr))
                        {
                                r = ipv6_printaddr(NULL, 0, op, ifp->name);
                                if (r != -1)
@@ -958,7 +952,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                        if (opt == NULL)
                                continue;
                        for (n = ndo->nd_opt_len - 1; n > 1; n -= 2,
-                           op += sizeof(addr.s6_addr))
+                           op += sizeof(addr))
                        {
                                r = ipv6_printaddr(tmp, l, op,
                                    ifp->name);
@@ -1398,8 +1392,7 @@ ipv6nd_handlena(struct ipv6_ctx *ctx, struct interface *ifp,
 
        TAILQ_FOREACH(rap, ctx->ra_routers, next) {
                if (rap->iface == ifp &&
-                   memcmp(rap->from.s6_addr, nd_na->nd_na_target.s6_addr,
-                   sizeof(rap->from.s6_addr)) == 0)
+                   IN6_ARE_ADDR_EQUAL(&rap->from, &nd_na->nd_na_target))
                        break;
        }
        if (rap == NULL) {