*BSD News Article 52456


Return to BSD News archive

Newsgroups: comp.unix.bsd.netbsd.misc
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!chi-news.cic.net!news.midplains.net!gw2.att.com!nntpa!news
From: "J.T. Holmes x7683" <jtholmes>
Subject: Re: bind()ing a socket to a specific address?
Content-Type: text/plain
Message-ID: <DG740K.EK7@nntpa.cb.att.com>
To: jtholmes@alphlz.att.com
Sender: news@nntpa.cb.att.com (Netnews Administration)
Nntp-Posting-Host: nmg3-gw.alph.att.com
Content-Transfer-Encoding: 7bit
Organization: AT&T
References: <45136o$6qf@wn1.sci.kun.nl> <451ito$h4i@sunsystem5.informatik.tu-muenchen.de>
Mime-Version: 1.0
Date: Mon, 9 Oct 1995 19:12:20 GMT
X-Mailer: Mozilla 1.1 (X11; U; SunOS 4.1.3_DB sun4c)
X-Url: news:451ito$h4i@sunsystem5.informatik.tu-muenchen.de
Lines: 50

From: gruner@Informatik.TU-Muenchen.DE (Armin Gruner)
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: Re: bind()ing a socket to a specific address?
Date: 5 Oct 1995 21:32:40 GMT
Organization: Technische Universitaet Muenchen, Germany
Message-ID: <451ito$h4i@sunsystem5.informatik.tu-muenchen.de>
References: <45136o$6qf@wn1.sci.kun.nl>

rhialto@polder.ubc.kun.nl (Olaf Seibert) writes:

>I am trying to bind() a socket to a specific IP address, but I always
>get the error EADDRNOTAVAIL: "Can't assign requested address".
>Nevertheless, as far as I can see, this should be possible.
>The only address that will work is INADDR_ANY (i.e., 0.0.0.0).

>I took a quick look in the kernel sources, and what I saw should also
>allow it.

>Any hints? I have appended source of my program (not very long).
>Try it with command line such as a.out localhost 1234 (does not work)
>or a.out 0 1234 (does work but is not what I want).

>int
>main(int argc, char **argv)
>{
>    if (argc >= 2) {
>	struct sockaddr_in hostaddr;
>	char *proto = "tcp";
>	int ac;

	bzero(&hostaddr, sizeof(hostaddr));

		or

	memset(&hostaddr, 0, sizeof(hostaddr));
		
>	get_ip(argv[1], &hostaddr);

>	for (ac = 2; ac < argc; ac++) {
>	    if (prototosocktype(argv[ac]) != -1) {
>		proto = argv[ac];
>		continue;
>	    }
>	    make_socket(hostaddr, proto, argv[ac]);
>	}

>	/* and do nothing else anymore */
>	select(0, NULL, NULL, NULL, NULL);
>    }