Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: tom@finwds01.tu-graz.ac.at (Thomas Leitner)
Subject: SOLVED: hostid under OSF/1
Date: 1995/04/06	[thread overview]
Message-ID: <3m0s1b$hl1@fstgds15.tu-graz.ac.at> (raw)
In-Reply-To: 3m022g$sh7@fstgds15.tu-graz.ac.at

Thomas Leitner (tom@finwds01.tu-graz.ac.at) wrote:
: Thomas Leitner (tom@finwds01.tu-graz.ac.at) wrote:

: : I found that neither in the FAQ nor in the recent postings here so:
: : I need to get the hardware serial number under OSF/1. Apparently the
: : hostid command can not be used for that. The sysinfo system call
: : won't help either.

: : Question: Can someone please post me a short code fragment how to
: : get the hardware serial number under OSF/1?

: Aehmm, well. Am I touching some secret here or is there really no way
: to get the CPU (or system) serial number somehow? I, as well could
: use the ethernet address for my purposes. How can I get out the
: ethernet address of the machine from a C program (if possible
: a non-priviledged)?

Thanks to John Kohl <jtk@atria.com>. He mailed me the following 
routine for getting the ethernet addr. (slightly modified by me). It 
even works under a non-priviledged account:

#include <stdio.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>

main()
{
        int s;
        struct ifreq *ifrq, ifreqs[32];
        struct ifdevea eaddr;
        struct ifconf ifc;
        long l1, l2;

        memset((char *)ifreqs, 0, sizeof(ifreqs));

        s = socket(AF_INET, SOCK_STREAM, 0);
        ifc.ifc_req = ifreqs;
        ifc.ifc_len = sizeof(ifreqs);
        ioctl(s, SIOCGIFCONF, &ifc);
        for (ifrq = ifreqs;
             ifc.ifc_len > 0;
             ifrq++, ifc.ifc_len -= sizeof(*ifrq)) {
            /* for each known interface, try to get a physaddr. */
            strncpy(eaddr.ifr_name, ifrq->ifr_name, IFNAMSIZ);
            if (ioctl(s, SIOCRPHYSADDR, &eaddr) == 0) {
                /* eaddr now has address. */
                break;                  /* from for loop */
            }
        }
        close(s);
        printf("name='%s'\n", eaddr.ifr_name);
        printf("def_pa='%02x:%02x:%02x:%02x:%02x:%02x'\n",
             eaddr.default_pa[0],
             eaddr.default_pa[1],
             eaddr.default_pa[2],
             eaddr.default_pa[3],
             eaddr.default_pa[4],
             eaddr.default_pa[5]);
        printf("cur_pa='%02x:%02x:%02x:%02x:%02x:%02x'\n",
             eaddr.current_pa[0],
             eaddr.current_pa[1],
             eaddr.current_pa[2],
             eaddr.current_pa[3],
             eaddr.current_pa[4],
             eaddr.current_pa[5]);
}

Thanks again -- Tom
--
Tom Leitner, tom@finwds01.tu-graz.ac.at              |\      _,,,---,,_
Dept. of Communications                         zzz. /,`.-'`'    -.  ;-;;,_.
Graz University of Technology                       |,4-  ) )-,_. ,\ (  `'-'
Phone: +43-316-873-7455                            '---''(_/--'  `-'\_)
Fax:   +43-316-463-697                 
WWW home page: http://wiis.tu-graz.ac.at/people/tom.html



      reply	other threads:[~1995-04-06  4:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-04-04  4:00 hostid under OSF/1 Thomas Leitner
1995-04-04  4:00 ` oberman
1995-04-06  4:00 ` Thomas Leitner
1995-04-06  4:00   ` Thomas Leitner [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox