Subject: Re: Bind to local iface: bug or feautre.
To: Jesus M. Gonzalez <jgb@gsyc.inf.uc3m.es>
From: Stefan Grefen <grefen@hprc.tandem.com>
List: tech-net
Date: 11/25/1996 16:49:23
In message <199611251305.OAA02711@hola.gsyc.inf.uc3m.es>  "Jesus M. Gonzalez" wrote:
> 
> 	Hi!
> 
> 	NetBSD returns an error when binding an UDP address where
> the host address matchs a local iface (instead of the more used
> INADDR_ANY). I'm not familar with the networking code,
> and I'm not sure if this is a bug or a feature... Could somebody
> tell me, so that I send-pr it if it is a bug?
> 
> 		Jesus.
> 
> PS: Next, the code which causes EADDRNOTAVAIL. I think it should just
> work. Was tested on NetBSD-1.1/i386 and NetBSD-1.2/i386.
> 
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <stdio.h>
> 
> main()
> {
>   int sock, length;
>   struct sockaddr_in name;
>   char buf[1024];
> 
>   /* Create socket from which to read. */
>   sock = socket(AF_INET, SOCK_DGRAM, 0);
>   if (sock < 0) {
>     perror("opening datagram socket");
>     exit(1);
>   }
>   /* Create name with wildcards. */
>   name.sin_family = AF_INET;
>   name.sin_addr.s_addr = inet_addr("163.117.137.172"); /* Here your addr */

Should be:
ntohl(inet_addr("xx") ;
or
inet_aton("xx",&name.sin_addr);

and you should add:
name.sin_len=sizeof(name);

inet_addr returns in HOST-ORDER !!

Stefan

> 
> -- 
> Jesus M. Gonzalez Barahona         | addr.:  c/ Butarque, 15
> Grupo de Sistemas y Comunicaciones |         28911 Leganes, Spain
> Departamento de Informatica        | tel: +34 1 624 94 58
> Universidad Carlos III de Madrid   | fax: +34 1 624 94 30
> e-mail: jgb@gsyc.inf.uc3m.es       | www: http://ordago.gsyc.inf.uc3m.es/~jgb

--
Stefan Grefen                                Tandem Computers Europe Inc.
grefen@hprc.tandem.com                       High Performance Research Center
You should never bet against anything in science at odds of more than
about 10^12 to 1.
                -- Ernest Rutherford