The branch main has been updated by kp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=8754ba5a5f6ee681de776601110313b69a779067

commit 8754ba5a5f6ee681de776601110313b69a779067
Author:     Kristof Provost <k...@freebsd.org>
AuthorDate: 2025-02-13 17:30:12 +0000
Commit:     Kristof Provost <k...@freebsd.org>
CommitDate: 2025-02-21 08:11:02 +0000

    pfctl: Rewrite to void using union sockaddr_union
    
    ok mikeb
    
    Obtained from:  OpenBSD, deraadt <dera...@openbsd.org>, 8717211fe3
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sbin/pfctl/pfctl_table.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c
index 7137f42b13e8..90e87adadb0f 100644
--- a/sbin/pfctl/pfctl_table.c
+++ b/sbin/pfctl/pfctl_table.c
@@ -36,9 +36,10 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include <net/if.h>
 #include <net/pfvar.h>
-#include <arpa/inet.h>
 
 #include <ctype.h>
 #include <err.h>
@@ -496,20 +497,24 @@ print_addrx(struct pfr_addr *ad, struct pfr_addr *rad, 
int dns)
                printf("\t nomatch");
        if (dns && ad->pfra_net == hostnet) {
                char host[NI_MAXHOST];
-               union sockaddr_union sa;
+               struct sockaddr_storage ss;
 
                strlcpy(host, "?", sizeof(host));
-               bzero(&sa, sizeof(sa));
-               sa.sa.sa_family = ad->pfra_af;
-               if (sa.sa.sa_family == AF_INET) {
-                       sa.sa.sa_len = sizeof(sa.sin);
-                       sa.sin.sin_addr = ad->pfra_ip4addr;
+               bzero(&ss, sizeof(ss));
+               ss.ss_family = ad->pfra_af;
+               if (ss.ss_family == AF_INET) {
+                       struct sockaddr_in *sin = (struct sockaddr_in *)&ss;
+
+                       sin->sin_len = sizeof(*sin);
+                       sin->sin_addr = ad->pfra_ip4addr;
                } else {
-                       sa.sa.sa_len = sizeof(sa.sin6);
-                       sa.sin6.sin6_addr = ad->pfra_ip6addr;
+                       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss;
+
+                       sin6->sin6_len = sizeof(*sin6);
+                       sin6->sin6_addr = ad->pfra_ip6addr;
                }
-               if (getnameinfo(&sa.sa, sa.sa.sa_len, host, sizeof(host),
-                   NULL, 0, NI_NAMEREQD) == 0)
+               if (getnameinfo((struct sockaddr *)&ss, ss.ss_len, host,
+                   sizeof(host), NULL, 0, NI_NAMEREQD) == 0)
                        printf("\t(%s)", host);
        }
        printf("\n");

Reply via email to