[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Workaround for hostid on Darwin 8/MacPPC
From: |
C. Speare |
Subject: |
Workaround for hostid on Darwin 8/MacPPC |
Date: |
Thu, 3 May 2007 22:22:45 -0400 (EDT) |
Output of uname -a:
Darwin ppc7447.local 8.9.0 Darwin Kernel Version 8.9.0: Thu Feb 22
20:54:07 PST 2007; root:xnu-792.17.14~1/RELEASE_PPC Power Macintosh
powerpc PowerMac10,1 Darwin
output of hostid --version:
hostid (GNU coreutils) 6.9
Built using gcc 4.0.4 [custom compiled] plus the Apple-provided as/ld.
(Same result with gcc-3.3, the Apple-provided version, and gcc-4.0.1, the
Apple-provided version.)
Expected output: something random-ish, ideally some hash of the IP address
or such. Of course, the result relies on gethostid().
Actual output: 00000000
Repeatable: always
Details: As it turns out, gethostid() is implemented in MacOSX, but is
broken. On at least this version of MacOSX, the call returns 0 no matter
what. This could happen on other platforms that have a broken (or
incorrect) gethostid() function.
A possible (but weak) workaround is to test for the case where id is 0.
Roughly speaking:
-----
ppc7447% diff -c hostid.c.orig hostid.c
*** hostid.c.orig Thu May 3 22:06:29 2007
--- hostid.c Thu May 3 22:09:01 2007
***************
*** 90,95 ****
--- 90,101 ----
is a no-op unless unsigned int is wider than 32 bits. */
id &= 0xffffffff;
+ if (id == 0) {
+ /* id of 0 can't be right, so come up with some 32-bit random
+ value. */
+ id = random();
+ }
+
printf ("%08x\n", id);
exit (EXIT_SUCCESS);
-----
Or something along those lines. This isn't a bug in hostid as much as it
is a brain-dead implementation of gethostid(), but catching a broken
gethostid() certainly helps hostid to be more robust.
Thank you.
- Workaround for hostid on Darwin 8/MacPPC,
C. Speare <=