uname and machine identity

Mumit Khan khan@xraylith.wisc.edu
Sun Jan 31 23:52:00 GMT 1999


Ian Collins <ianc@kiwiplan.co.nz> writes:
> I need to get a unique system identity from an application running on b20.1.
> On other Unixes, I use,
> 
> typedef struct utsname UTS
> 
> UTS uts;
> 
> uname(uts)

What problem(s) did you have? It should work just fine, at least the POSIX
part. The only gotcha is the domainname parameter, which lots of systems 
either do not implement (SunOS 4.1.x, Newlib in Cygwin) or implement under 
a different name (eg., glibc2 requires __USE_GNU, otherwise __domainname). 
I don't remember offhand if POSIX requires the domainname field; it's
usually not that meaningful, or at best ambiguous as to what it means.

Here's a code snippet out of my platform configuration sources:

  #include <stdio.h>
  #include <sys/utsname.h>

  int 
  main () 
  {
    struct utsname u;

    if (uname (&u)) 
      {
        perror ("uname");
        exit (1);
      }

    printf ("sysname = %s\n", u.sysname);
    printf ("nodename = %s\n", u.nodename);
    printf ("release = %s\n", u.release);
    printf ("version = %s\n", u.version);
    printf ("machine = %s\n", u.machine);

    return 0;
  }

I of course believe there are better ways to configure your software
without using ``uname'' (eg., via a built-time configuration tool
such as GNU configure).

Regards,
Mumit

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list