gethostid problem
gethostid problem
- Subject: gethostid problem
- From: Stan Sieler <email@hidden>
- Date: Mon, 14 Feb 2011 16:24:46 -0800
Hi,
Not really a file system item, but people writing filesystem oriented products may be aware of this,
particularly people trying to do machine-based licensing...
Is gethostid() supposed to work in X86 64-bit mode?
(Yes, it's deprecated...that doesn't mean it shouldn't work, and yes, I've tried what I
think the man page points me to, but without a better man page I can't tell for sure
if I'm doing the correct sysctl() call.)
I'm on OS X 10.6.6, and if I call gethostid() several times, I get different answers:
hostid = 3906362722391949312 (0x3636303300000000)
hostid = 3473179330304016384 (0x3033363300000000)
hostid = 3905521595996700672 (0x3633333300000000)
In X86 32-bit or PPC mode, I get 0 (which is bad enough).
BTW, in all 3 modes sysctl (CTL_KERN, KERN_HOSTID) gives me 0.
I compile the following demo program via: cc foo.c -o foo
...
Sometimes when I run it, all the gethostid() calls return 0.
Sometimes, the calls return large numbers:
tin:fsysux sieler$ foo
sizeof (int) = 4
sizeof (long) = 8
sizeof (long long) = 8
sizeof (int64_t) = 8
sizeof (gethostid()) = 8
sysctl (CTL_KERN, KERN_HOSTID) --> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
gethostid() -> 0 (0)
tin:fsysux sieler$ foo
sizeof (int) = 4
sizeof (long) = 8
sizeof (long long) = 8
sizeof (int64_t) = 8
sizeof (gethostid()) = 8
sysctl (CTL_KERN, KERN_HOSTID) --> 0 (0)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
gethostid() -> 4625478292286210048 (4031000000000000)
In fact, the behaviour seems to alternate between 0 and a large number (the large
number varies from run to run).
thanks,
Stan
----------cut here for foo.c ----------------
#include <stdio.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/sysctl.h>
//===============================================================
int main (int argc, char **argv)
{
int64_t
hid;
int
ktr,
mib [2],
value;
size_t
size;
printf ("sizeof (int) = %d\n", (int) sizeof (int));
printf ("sizeof (long) = %d\n", (int) sizeof (long));
printf ("sizeof (long long) = %d\n", (int) sizeof (long long));
printf ("sizeof (int64_t) = %d\n", (int) sizeof (int64_t));
printf ("sizeof (gethostid()) = %d\n", (int) sizeof (gethostid()));
printf ("\n");
mib [0] = CTL_KERN;
mib [1] = KERN_HOSTID;
size = sizeof (value);
if (sysctl (mib, 2, &value, &size, NULL, (size_t) 0) == -1)
{
printf ("sysctl (CTL_KERN, KERN_HOSTID) failed!\n");
return 1;
}
printf ("sysctl (CTL_KERN, KERN_HOSTID) --> %d (%x)\n", value, value);
printf ("\n");
for (ktr = 1; ktr <= 9; ktr++)
{
hid = gethostid ();
printf ("gethostid() -> %"PRId64" (%"PRIx64")\n", hid, hid);
}
return 0;
}
-----------------end cut---------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden