public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Paul Riley <PRILEY@altera.com>
Cc: Andrew Lunn <andrew@lunn.ch>, ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] Inconsistency between the Open BSD  IP stack and the tests in version 2.0
Date: Tue, 17 Aug 2004 17:20:00 -0000	[thread overview]
Message-ID: <20040817172102.GG20020@lunn.ch> (raw)
In-Reply-To: <45E39EE2E44FD443AEFAC07728BF3B50CACFB7@uk-ismsg02.altera.priv.altera.com>

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

  reply	other threads:[~2004-08-17 17:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-17 16:59 Paul Riley
2004-08-17 17:20 ` Andrew Lunn [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-08-17 16:51 Paul Riley
2004-08-17 16:55 ` Andrew Lunn
2004-08-17 16:45 Paul Riley
2004-08-17 16:49 ` Andrew Lunn
2004-08-17 16:24 Paul Riley
2004-08-17 16:31 ` Andrew Lunn
2004-08-17 16:43 ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040817172102.GG20020@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=PRILEY@altera.com \
    --cc=ecos-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).