From: Claudio Jeker Subject: Re: ia_sockmask.sin_family is not set correctly To: ido@wireplug.org Cc: tech@openbsd.org Date: Thu, 18 Jun 2026 10:58:50 +0200 On Thu, Jun 18, 2026 at 02:22:16AM +0000, ido@wireplug.org wrote: > Hi @tech, > > While working on a cross platform codebase that calls getifaddrs(3), > I noticed that unlike Darwin and Linux, on OpenBSD, the sin_family > value isn't set on the returned ifa_netmask structure, for ipv4 addresses. In BSD the netmask was normally all 0xff apart from the sa_len. This comes from the time where all netmasks were shared amongst all address families. In general the sa_family value of the address should be used for the netmask sockaddr. Also be aware that on some systems the returned buffer may be shorter than the AF specific sockaddr struct. So if you really want cross platform then you need to handle that in userland. It may still make sense to improve the exported values by getifaddrs(3). Your diff is certainly not complete. There are a fair amount of other places where ia_sockmask is adjusted that would also need such a fix. > While some SIOCAIFADDR callers set this value correctly (e.g., dhcpleased(8)), > others don't (e.g., ifconfig(8)). Either way, it is ignored by in_ioctl_change_ifaddr(). > > Since this is an ipv4 only path, it seems reasonable to just set it to the correct > value in in_ioctl_change_ifaddr(). > > --- > Ido > > diff --git sys/netinet/in.c sys/netinet/in.c > index 4edd8573071..d5c57d9feda 100644 > --- sys/netinet/in.c > +++ sys/netinet/in.c > @@ -503,6 +503,7 @@ in_ioctl_change_ifaddr(u_long cmd, caddr_t data, struct ifnet *ifp) > } > if (masksin != NULL) { > in_ifscrub(ifp, ia); > + ia->ia_sockmask.sin_family = AF_INET; > ia->ia_netmask = ia->ia_sockmask.sin_addr.s_addr = > masksin->sin_addr.s_addr; > needinit = 1; > -- :wq Claudio