From owner-freebsd-questions Tue Feb 13 02:40:25 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id CAA29631 for questions-outgoing; Tue, 13 Feb 1996 02:40:25 -0800 (PST) Received: from fun.inria.fr (fun.inria.fr [138.96.24.57]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id CAA29626 for ; Tue, 13 Feb 1996 02:40:22 -0800 (PST) Received: by fun.inria.fr (8.6.12/8.6.12) id LAA02981; Tue, 13 Feb 1996 11:38:46 +0100 Message-Id: <199602131038.LAA02981@fun.inria.fr> X-Mailer: exmh version 1.6.5 12/11/95 To: questions@FreeBSD.ORG Subject: Re: Q: programming sockets source address? In-reply-to: your message of Mon, 12 Feb 1996 20:07:18 PST. Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 13 Feb 1996 11:38:43 +0100 From: Andres Vega Garcia Sender: owner-questions@FreeBSD.ORG Precedence: bulk : Terry Braun wrote: > >Your message dated: Mon, 12 Feb 1996 17:40:46 PST >> >>> 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'm not sure what you are trying to do, but if you want to listen on >a particular socket on you local machine, say on port 1520, this code >will work- > > bindname.sin_addr.s_addr = htonl(INADDR_ANY); > bindname.sin_family = AF_INET; > bindname.sin_port = htons(1520); > n = bind(sock, &bindname, sizeof(bindname)); >\t >-------- >Terry Braun tab@talking.com >Talking Networks, Inc. 510-525-6696 And what can I do to select an specific interface (provided I have several interfaces)?. Do I just pass the addres belonging to the interface selected (bindname.sin_addr.s_addr = htonl(my_interface's_ad dr);) ? Thank you. Andres ------------------------------ INRIA Sophia-Antipolis, France avega@fun.inria.fr