Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!swidir.switch.ch!scsing.switch.ch!news.belwue.de!news.uni-stuttgart.de!uni-regensburg.de!lrz-muenchen.de!informatik.tu-muenchen.de!gruner 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 Lines: 41 Distribution: world Message-ID: <451ito$h4i@sunsystem5.informatik.tu-muenchen.de> References: <45136o$6qf@wn1.sci.kun.nl> NNTP-Posting-Host: hprbg5.informatik.tu-muenchen.de X-Newsreader: NN version 6.5.0 #5 (NOV) 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); > }