Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Feb 1996 17:40:46 -0800 (PST)
From:      Archie Cobbs <archie@tribe.com>
To:        ejs@bfd.com (Eric J. Schwertfeger)
Cc:        questions@FreeBSD.ORG, hackers@FreeBSD.ORG
Subject:   Re: Q: programming sockets source address?
Message-ID:  <199602130140.RAA25018@bubba.tribe.com>
In-Reply-To: <Pine.BSF.3.91.960212135045.22730B-100000@harlie.bfd.com> from "Eric J. Schwertfeger" at Feb 12, 96 01:59:08 pm

next in thread | previous in thread | raw e-mail | index | archive | help

> So far, my initial attempts to use bind() before connect() have been a 
> wash, as bind returns an errno of EADDRNOTAVAIL, regardless of which 
> address I'm using.  I was under the impression that bind could be used 
> before a connect to set the source address.  Is this wrong?  Is there a 
> correct way to do this (needs to be portable to Linux)?

I don't know if this is the source of your problem, but the following
caused me a bit of head scratching.

When bind() is given a specific IP address, it looks through the list
of interfaces and tries to match it to each interface address. The way
it does the compare is by a byte-by-byte compare of the sockaddr structure.
But you're passing a (sockaddr_in *), cast to a (sockaddr *)...

Now if you haven't specifically set the length field, this means that
some irrelevant bytes in the structure may screw up the comparison. So
the solution seems to be to zero out your sockaddr_in structure first.
At least that worked for me.

Maybe some IP interface expert could comment on this?

-Archie

_______________________________________________________________________________
Archie L. Cobbs, archie@tribe.com  *  Tribe Computer Works http://www.tribe.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199602130140.RAA25018>