[ECOS] Inconsistency between the Open BSD IP stack and the tests in version 2.0

Andrew Lunn andrew@lunn.ch
Tue Aug 17 17:20:00 GMT 2004


On Tue, Aug 17, 2004 at 05:59:32PM +0100, Paul Riley wrote:
> That will work as I've already done something similar. I was wonderring
> if anyone knew why it was zeroed as there appears to be no good reason
> that I can see.

The code is:

                } else if (sin->sin_addr.s_addr != INADDR_ANY) {
                        sin->sin_port = 0;              /* yech... */
                        if (ifa_ifwithaddr((struct sockaddr *)sin) == 0)
                                return (EADDRNOTAVAIL);
                }

ie, if you have asked it to bind to a specific interface, not
IMADDR_ANY, it calls ifa_ifwithaddr to see if the interface exists.
Now look at the search function:


ifa_ifwithaddr(addr)
        register struct sockaddr *addr;
{
        register struct ifnet *ifp;
        register struct ifaddr *ifa;
 
#define equal(a1, a2) \
  (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0)
        for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next)
            for (ifa = ifp->if_addrhead.tqh_first; ifa;
                 ifa = ifa->ifa_link.tqe_next) {
                if (ifa->ifa_addr->sa_family != addr->sa_family)
                        continue;
                if (equal(addr, ifa->ifa_addr))
                        return (ifa);
                if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr &&
                    /* IP6 doesn't have broadcast */
                    ifa->ifa_broadaddr->sa_len != 0 &&
                    equal(ifa->ifa_broadaddr, addr))
                        return (ifa);
        }
        return ((struct ifaddr *)0);
}

It does a memcpy of the address with the address associated with the
interface. It compares sa_len bytes, which will include the port
number. If it did not zero the port number, the compare would fail
since its port number is zero.

Simply realy, when you read the code.

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list