Revert previous
authorkn <kn@openbsd.org>
Mon, 15 Nov 2021 18:23:45 +0000 (18:23 +0000)
committerkn <kn@openbsd.org>
Mon, 15 Nov 2021 18:23:45 +0000 (18:23 +0000)
sockaddr_storage should stay since it is preferred and less error prone.

From deraadt
OK florian

sbin/resolvd/resolvd.c

index e51e7d5..23d12e7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: resolvd.c,v 1.22 2021/11/15 17:33:51 kn Exp $ */
+/*     $OpenBSD: resolvd.c,v 1.23 2021/11/15 18:23:45 kn Exp $ */
 /*
  * Copyright (c) 2021 Florian Obser <florian@openbsd.org>
  * Copyright (c) 2021 Theo de Raadt <deraadt@openbsd.org>
@@ -467,32 +467,27 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info)
 
                /* Add the new proposals */
                for (i = 0; i < rdns_count; i++) {
-                       struct sockaddr_in       sin;
-                       struct sockaddr_in6      sin6;
-                       struct sockaddr         *sa;
-                       int                      new, err;
+                       struct sockaddr_storage ss;
+                       struct sockaddr_in *sin = (struct sockaddr_in *)&ss;
+                       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss;
+                       int new, err;
 
+                       memset(&ss, 0, sizeof(ss));
+                       ss.ss_family = af;
                        new = findslot(learning);
                        switch (af) {
                        case AF_INET:
-                               memset(&sin, 0, sizeof(sin));
-                               memcpy(&sin.sin_addr, src, addrsz);
-                               sa = (struct sockaddr *) &sin;
-                               sa->sa_len = sizeof(sin);
+                               memcpy(&sin->sin_addr, src, addrsz);
                                break;
                        case AF_INET6:
-                               memset(&sin6, 0, sizeof(sin6));
-                               memcpy(&sin6.sin6_addr, src, addrsz);
-                               if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
-                                       sin6.sin6_scope_id = rtm->rtm_index;
-                               sa = (struct sockaddr *) &sin6;
-                               sa->sa_len = sizeof(sin6);
+                               memcpy(&sin6->sin6_addr, src, addrsz);
+                               if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
+                                       sin6->sin6_scope_id = rtm->rtm_index;
                                break;
                        }
-                       sa->sa_family = af;
                        src += addrsz;
 
-                       if ((err = getnameinfo(sa, sa->sa_len,
+                       if ((err = getnameinfo((struct sockaddr *)&ss, ss.ss_len,
                            learning[new].ip, sizeof(learning[new].ip),
                            NULL, 0, NI_NUMERICHOST)) == 0) {
                                learning[new].prio = rtm->rtm_priority;