Subject: Re: Bind to local iface: bug or feautre.
To: None <grefen@hprc.tandem.com>
From: Quaizar Vohra <qv@sparky.iol.unh.edu>
List: tech-net
Date: 11/25/1996 12:06:36
Hi,

 > > 	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.

Below is a perfectly  legal code and works on my Alpha. 
The problem may be with address configuration on your system, i.e
it might not have 163.117.137.172 this address assigned to any of its
interface(s).

 > > 
 > > 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);

	No inet_addr does return address in network byte order and
thats what you are supposed to pass in the 'bind' call.
 > 
 > and you should add:
 > name.sin_len=sizeof(name);
 > 
	This is not a requirement and the in_pcbbind code never 
checks this. All it checks is that the mbuf len is 
sizeof(struct in6_addr), which is automatically set when you
pass sizeof(name) as the 3rd parameter of bind.

 > inet_addr returns in HOST-ORDER !!
 > 
 > Stefan
 > 
 > > 

Quaizar