[comp.unix.ultrix] How do I get the Serial # of my CPU ?

snoopy@ixos.de (10/12/90)

Dear Net,

would like to get at the serial number (not the CPU Type) of my
DEC machine (DECStation or uVax) from a C-Program.

Is there a way to do this ? Surely DEC has some register or some number
in EPROM to get this. Note it does not have be a number: an ASCII
string etc. would do.

Sorry if this been asked before or if its a stupid questions or I'm too
f. lazy to read the f. manual, but I am asking for a friend without a net
access.

Please reply by e-mail only.

Thanks,
Love,
Snoopy

krs0@GTE.COM (Rod Stephens) (10/15/90)

In article <1263@ixos.de> snoopy@ixos.de writes:
>Dear Net,
>
>would like to get at the serial number (not the CPU Type) of my
>DEC machine (DECStation or uVax) from a C-Program.

I don't think this can be done (I would love to hear that it can) but
you can get your CPU ethernet address. I am told that this address can
be changed but it probably won't be. The following code was posted
some time ago -- sorry I don't remember who posted it so I cannot give
them proper credit.

+---------------------------------------------------------------+
| Rod Stephens           | "Haven't I told you not to play      |
| GTE Laboratories, Inc  |  with my super-weapons? You might    |
| (617)466-4182          |  devastate yourself!"                |
| krs0@gte.com           |                                      |
+---------------------------------------------------------------+

-- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE --
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <net/if.h>

extern int errno;

main(ac, av)
    int ac;
    char *av [];
{
    int s;
    char *line = "------------------------------------";
    char device [IFNAMSIZ+1];

    /* structure used to query de and qe for physical addresses

        struct ifdevea {
            char    ifr_name[IFNAMSIZ];
            char    default_pa[6];
            char    current_pa[6];
        };
    */
    struct ifdevea hw_addr;

    s = socket (AF_INET, SOCK_DGRAM, 0);

    if (s < 0)  {
        perror ("socket:");
        exit (3);
    }

    if (ac > 1 && strlen (av [1]) <= IFNAMSIZ)
        strcpy (&hw_addr.ifr_name [0], av [1]);
    else    strcpy (&hw_addr.ifr_name [0], "se0");

    if (ioctl(s, SIOCRPHYSADDR, (caddr_t) &hw_addr) < 0) {
        perror ("ioctl: SIOCRPHYSADDR");
        close(s);
        exit (1);
    }

    printf ("\n%s\n", line);
    printf ("addresses for %s :\n", &hw_addr.ifr_name [0]);
    printf ("%s\n", line);
    print_addr ("hardware-address", &hw_addr.default_pa [0]);
    print_addr ("current-address ", &hw_addr.current_pa [0]);
    printf ("%s\n", line);
    close(s);
}

print_addr (what, ether_addr)
    char *what, *ether_addr;
    {
    printf ("%s = %02x-%02x-%02x-%02x-%02x-%02x\n", what,
                ether_addr [0] & 0xff,
                ether_addr [1] & 0xff,
                ether_addr [2] & 0xff,
                ether_addr [3] & 0xff,
                ether_addr [4] & 0xff,
                ether_addr [5] & 0xff);
    }