This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with gethostid


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]