NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-i386/39880: ioctl with SIOCGIFFLAGS fails on -current (in GNUstep gdomap)



On Thu, 20 Nov 2008, Aleksej Saushev wrote:
> > I have a hunch that the program relies on false SIOCGIFCONF semantics.
> 
> What is the correct way of using SIOCGIFCONF?
> Or what are the common mistakes?

Given struct ifreq *ifr, a pointer into the data returned by
SIOCGIFCONF, the length of the current item (or the offset to the start
of the next item) is never less than sizeof(struct ifreq), and will be
more than sizeof(struct ifreq) if ifr->ifr_addr.sa_len is larger than
ifr->ifr_ifru.

For example, the following code should work:

        if (ifr->ifr_addr.sa_len <= sizeof(ifr->ifr_ifru)) {
                len = sizeof(struct ifreq);
        } else {
                len = sizeof(struct ifreq) +
                        ifr->ifr_addr.sa_len - sizeof(ifr->ifr_ifru);
        }

Common errors are to always use sizeof(struct ifreq), even
if ifr_addr.sa_len is too large to fit; to always use some
calculation involving ifr_addr.sa_len, even if it's smaller than
sizeof(ifr->ifr_ifru); to use something involving sizeof(struct
sockaddr) instead of sizeof(ifr->ifr_ifru).  I have also seen code
that assumes that (sizeof(struct ifreq) == sizeof(ifreq.ifr_name) +
sizeof(ifreq.ifr_ifru)), and I'd discourage that, but I don't know taht
it's really an error.

--apb (Alan Barrett)


Home | Main Index | Thread Index | Old Index