From owner-freebsd-hackers Mon Feb 12 17:41:59 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id RAA20251 for hackers-outgoing; Mon, 12 Feb 1996 17:41:59 -0800 (PST) Received: from bubba.tribe.com ([205.184.207.7]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id RAA20246 Mon, 12 Feb 1996 17:41:57 -0800 (PST) Received: (from archie@localhost) by bubba.tribe.com (8.6.12/8.6.12) id RAA25018; Mon, 12 Feb 1996 17:40:47 -0800 From: Archie Cobbs Message-Id: <199602130140.RAA25018@bubba.tribe.com> Subject: Re: Q: programming sockets source address? To: ejs@bfd.com (Eric J. Schwertfeger) Date: Mon, 12 Feb 1996 17:40:46 -0800 (PST) Cc: questions@FreeBSD.ORG, hackers@FreeBSD.ORG In-Reply-To: from "Eric J. Schwertfeger" at Feb 12, 96 01:59:08 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.ORG Precedence: bulk > 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