Return-Path: william@bourbon.usc.edu Delivery-Date: Tue Oct 28 21:44:05 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9T4i4VK013096 for ; Tue, 28 Oct 2008 21:44:05 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9T4tHdf008705 for ; Tue, 28 Oct 2008 21:55:17 -0700 Message-Id: <200810290455.m9T4tHdf008705@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS551 final1 - getpeerbyaddr Date: Tue, 28 Oct 2008 21:55:17 -0700 From: Bill Cheng Someone wrote: > yea, I did this. My problem happens when a regular node sending join to > beacon node.how should that beacon node knows who send this packet. I am > trying to find a generic way > to distinguish. Because all other beacon nodes will get this JOIN_REQ too. > I'd like to treat them > all in the same way. Thanks The first message a node receives is either a HELLO or a JOIN request. In either case, the hostname and port number are in the message! So, you need to associate a socket with this hostname and port number and you only need to do it right after you have received the first message. -- Bill Cheng // bill.cheng@usc.edu On Tue, Oct 28, 2008 at 7:58 PM, Bill Cheng wrote: > Someone wrote: > > > For generating log message, if I use getpeername() to get remote host's > ip > > and > > gethostbyaddr() with that ip, it seems gethostbyaddr() can't get an > hostname > > of local ip. > > Is there any other way to get an hostname by the socket file descriptor. > > When you get a HELLO from your neighbor, you need to remember > the hostname and port number inside the HELLO message! Please > see: > > http://merlot.usc.edu/cs551-f08/msgs/bill/309.txt > -- > Bill Cheng // bill.cheng@usc.edu