Subject: dumb bind() question..?
To: None <netbsd-help@NetBSD.ORG>
From: None <tooleym@douglas.bc.ca>
List: netbsd-help
Date: 03/25/1998 17:02:17
I have two IP addresses (127.0.0.1, and 140.161.99.105).

I compile the following code:

#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

main()
{
int s;
struct sockaddr_in bindme;
int len = sizeof(bindme);

if (s = socket(AF_INET, SOCK_STREAM, 0)) {
        bindme.sin_family = AF_INET;
        bindme.sin_port = htons(9000);
        bindme.sin_addr.s_addr = inet_addr("140.161.99.105");
        if (bind(s, (struct sockaddr *)&bindme, sizeof(bindme)) ) {
                printf("success!\n");
        }
        close(s);
}
}

Success doesn't happen, on 140.161.99.105, and 127.0.0.1.

ifconfig -a:

lo0: flags=8009<UP,LOOPBACK,MULTICAST> mtu 32976
        inet 127.0.0.1 netmask 0xff000000 
sl0: flags=c010<POINTOPOINT,LINK2,MULTICAST> mtu 296
ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500
        inet 140.161.99.105 --> 140.161.254.127 netmask 0xffff0000

So! I do have the two addresses, and INADDR_ANY works fine for servers..
but what if I want something only available when someone connects via the
loopback? Or, if when I get an ethernet card, I only want to wait for a
connection on that card?

I've looked through the comp.unix sockets examples and so forth, and I've
checked around in some newsgroup archives.. I've looked through the man
pages, I've seen the code working on the linux boxes at the univ...

I've also tried to sysctl() the hostid into my machine, but there's only
one slot for a hostid. blech. and it still produces no "success" keyword.

well anyway, thanks for any help you may be able to provide, I appreciate
even pointers to some sort of online information source.

sincerely,

marc tooley
tooleym@douglas.bc.ca