lock.Lock();
derr(0) << "got control-c, exiting" << endl;
::close(accepter.listen_sd);
- exit(-1);
+ _exit(-1);
lock.Unlock();
}
socklen_t llen = sizeof(rank.listen_addr);
getsockname(listen_sd, (sockaddr*)&rank.listen_addr, &llen);
- int myport = ntohs(rank.listen_addr.sin_port);
- dout(10) << "accepter.start bound to port " << myport << endl;
+ dout(10) << "accepter.start bound to " << rank.listen_addr << endl;
// listen!
rc = ::listen(listen_sd, 1000);
assert(rc >= 0);
- //dout(10) << "accepter.start listening on " << myport << endl;
// my address is... HELP HELP HELP!
char host[100];
// figure out my_addr
if (g_my_addr.port > 0) {
- // user specified it, easy.
+ // user specified it, easy peasy.
rank.my_addr = g_my_addr;
} else {
- // try to figure out what ip i can be reached out
- memset(&rank.listen_addr, 0, sizeof(rank.listen_addr));
-
// look up my hostname. blech! this sucks.
rank.listen_addr.sin_family = myhostname->h_addrtype;
memcpy((char *) &rank.listen_addr.sin_addr.s_addr,
myhostname->h_addr_list[0],
myhostname->h_length);
- rank.listen_addr.sin_port = htons(myport);
+
+ // set up my_addr with a nonce
rank.my_addr.set_addr(rank.listen_addr);
+ rank.my_addr.nonce = getpid(); // FIXME: pid might not be best choice here.
}
-
- // set a nonce
- rank.my_addr.nonce = getpid(); // FIXME: pid might not be best choice here.
-
+
dout(10) << "accepter.start my addr is " << rank.my_addr << endl;
// set up signal handler
void set_addr(tcpaddr_t a) {
memcpy((char*)ipq, (char*)&a.sin_addr.s_addr, 4);
- port = a.sin_port;
+ port = ntohs(a.sin_port);
}
void make_addr(tcpaddr_t& a) const {
+ memset(&a, 0, sizeof(a));
a.sin_family = AF_INET;
memcpy((char*)&a.sin_addr.s_addr, (char*)ipq, 4);
- a.sin_port = port;
+ a.sin_port = htons(port);
}
};