delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/01/23/04:54:10

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Mon, 23 Jan 2012 10:53:22 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Problem with gethostid
Message-ID: <20120123095322.GB2456@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CAJOtW+7yt4ox1KG5jsy3Zrc5LAUbLVjzbrzefwhGMwXxMFpWMw AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAJOtW+7yt4ox1KG5jsy3Zrc5LAUbLVjzbrzefwhGMwXxMFpWMw@mail.gmail.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jan 22 17:52, Yuri Gribov wrote:
> Hi all,
> 
> I have some problems with gethostid functions. When I run it on some
> nodes of my cluster I get the same return value although hostnames and
> IP addresses are different. Here are the logs for 2 nodes (test
> program is in the attach, as well as cygcheck output).
> 
> C:\Users\gribov.y>\\s-cw-head\pgas\a.exe
> hostname = S-CW-NODE52
> hostent:
> h_name = S-CW-NODE52.XXX
> address: 10.2.0.48
> address: 192.168.80.1
> address: 192.168.169.1
> id = 364106303 15b3d23f
> 
> C:\Users\gribov.y>\\s-cw-head\pgas\a.exe
> hostname = S-CW-NODE53
> hostent:
> h_name = S-CW-NODE53.XXX
> address: 10.2.0.56
> address: 192.168.93.1
> address: 192.168.244.1
> id = 364106303 15b3d23f
> 
> Note that ids are equal although IP addresses are clearly different.

The number returned by gethostid is not created from your IP address
on Cygwin.  In fact, it's created from various other sources like the
CPU processor serial number, the MAC of one of your NICs, the product
ID of your Windows version and the size of your drive C:.

So we can see what's going on, could you please make sure that your
testcase calls gethostid only once by changing the last printf to

  printf("id = %08lx\n", id);

and then call:

  $ strace ./a.exe | grep gethostid:

and paste the output into your reply.

While gethostid is not guaranteed to return a globally unique ID, I
think I see the potential flaws in the algorithm.  It shouldn't be too
hard to make it a bit more intelligent.

Or, we just replace it with a simple algorithm as it's described in the
glibc man pages.  First it checks if /etc/hostid exists and uses the
value from there.  If not, it calls gethostname and gethostbyname to
fetch the (or better "a") IPv4 address and tweaks the bits a bit.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019