Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: ltf@ncmicro.lonestar.org (Lance Franklin)
Subject: Re: unique identification of DECStation
Date: 6 Jul 92 19:49:28 GMT	[thread overview]
Message-ID: <1992Jul6.194928.9759@ncmicro.lonestar.org> (raw)
In-Reply-To: 1992Jul3.204840.26318@decuac.dec.com

In article <1992Jul3.204840.26318@decuac.dec.com> mjr@hussar.dco.dec.com (Marcus J. "will do TCP/IP for food" Ranum) writes:
}>The existing method involves the extraction of the ethernet address
}>from an ethernet device, but this has the drawback of requiring
}>knowledge of all supported device types (ln?, xn? etc.).
}
}	You also need to consider that the ethernet address can be
}changed - it is not immutable. Also a your copy protection scheme
}be careful not to use the first configured network interface, since
}it might be a ci connect.
}
}>Can anyone tell me if there is a neat way of extracting some hardware
}>bound identification?
}
}	Not really. You have to do the usual:
} 
}	if (ioctl(s, SIOCRPHYSADDR, (caddr_t) &hw_addr) < 0) {
}
}	It gets ugly in a hurry, since if you just pick the first you
}can get hosed by ci connections or hosts with multiple ether cards. I
}imagine if I wanted to get around a copy protect it'd take about an
}hour to write a network device that didn't actually do anything but
}have a predeterimined ethernet number...
}
}mjr.

Try this code...works for me.  By the way, The comment at the end, referring to
adding a close before returns, has been done in this code.

--------cut here--------

/*
 *      getadr.c -- program to acquire ethernet controller addresses
 *              (c) Digital Equipment Corporation, 1989
 *              Author: Jim Lieb, Digital Equipment Corp. suntan::lieb
 *              This program is distributed free as a demonstration
 *              of network access methods.  No warrantee is expressed or
 *              implied.
 *
 *      Application: Use the getadr function to get the hardware address
 *              for the system in applications where the license key is
 *              verified by checking something unique like a system serial
 *              number (not always present on DEC cpus).
 *
 *      NOTE:   There is a difference between the hardware address and the
 *              physical address of Digital manufactured Ethernet controller.
 *              The hardware address is a unique number, typically of the
 *              form:  08-00-2B-xx-xx-xx, as assigned by IEEE authority.  The
 *              xx-xx-xx number is fixed in ROM and is unique for each
 *              controller.  This address is guaranteed fixed and unique.
 *              The physical address is programmable and is MODIFIED by the
 *              DECnet routing layer to encode the 16 bit Phase IV DECnet
 *              address in the least significant 2 octets (byte swapped)
 *              of the source address of packets. This address, typically
 *              of the form aa-00-04-00-yy-yy where yy-yy is the DECnet
 *              address, becomes the address used by the controller for
 *              packet receive and transmit.
 *
 *              March 3, 1990 - Jim Lieb, changed to use internal tables
 *                              and clean up struct usage.  Please note!
 *              May 21, 1990 - John Dustin OSG, use status bits rather than
 *                              string compares to get right interface.
 *                              also test for interface turned on and use
 *                              best guess of none on...
 */

#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>                      /* error numbers */
#include <stdio.h>

static char getadrSID[] = "@(#)getadr.c 1.5 6/22/90 demo";
extern int errno;

/*      getadr -- get primary ethernet interface address
 *              read list of net devices via ioctl to ifreqs.  Pass over
 *              loopback device and any serial line interfaces.  Use first
 *              ether device found.  This could cause a problem if there are
 *              multiple ether controllers on the system as it will find the
 *              first device configured.  No panic since most have only one
 *              device.  This function does not require setuid(2) priviledges.
 */

#define IFREQCNT 64     /* need enough room for total number of possible
                         * interfaces, including aliases for LAT and DECnet
                         */
int getadr(name, ifrp)
char *name;
struct ifdevea *ifrp;
{
        int s;
        struct ifreq *ifr;
        struct ifreq ifreqs[IFREQCNT];
        struct ifreq tmp_ifr;
        struct ifconf ifc;
        char *maybe = NULL;     /* a device that might be it */

        bzero(ifrp, sizeof(struct ifdevea));
        if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                perror("socket");
                return( -1);
        }
        if(name != NULL)
                strcpy(ifrp->ifr_name, name);
        else {
                ifc.ifc_req = ifreqs;
                ifc.ifc_len = sizeof(ifreqs);
                if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
                        perror("ioctl: SIOCGIFCONF");
			close(s);
                        return(-1);
                }
                for(ifr = ifreqs; ifr < &ifreqs[IFREQCNT]; ifr++) {
                        if(strlen(ifr->ifr_name) == 0) {
                                if (maybe == NULL) {
                                        fprintf(stderr, "No network devices configured\n");
					close(s);
                                	return(-1);
                                } else
                                        break;  /* check out maybe */
                        } else {
                                (void) strcpy(tmp_ifr.ifr_name, ifr->ifr_name);
                                if (ioctl(s, SIOCGIFFLAGS, &tmp_ifr) < 0) {
                                        perror("ioctl: SIOCGIFFLAGS");
					close(s);
                                        return(-1);
                                }
                                if ((tmp_ifr.ifr_flags & (IFF_POINTOPOINT))
                                         == (IFF_POINTOPOINT)) {
                                        continue; /* skip point to point */
                                }
                                if ((tmp_ifr.ifr_flags
                                    & (IFF_DYNPROTO|IFF_BROADCAST))
                                          != (IFF_DYNPROTO|IFF_BROADCAST)) {
                                        continue;       /* skip CI, etc. */
                                }
                                if ((tmp_ifr.ifr_flags & (IFF_UP|IFF_RUNNING))
                                         != (IFF_UP|IFF_RUNNING)) {
                                        /* save this name, it might be the
                                         * right one but just isn't up now
                                         */
                                        if (maybe == NULL)
                                                maybe = ifr->ifr_name;
                                        continue;   /* not up and running */
                                }
                                (void)strcpy(ifrp->ifr_name, tmp_ifr.ifr_name);
                                maybe = NULL; /* found real one, clear maybe */
                                break;
                        }
                }
        }
        if (maybe != NULL) {
                (void) strcpy(ifrp->ifr_name, maybe);
        }
        if (ioctl(s, SIOCRPHYSADDR, ifrp) < 0) {
                perror("ioctl: SIOCRPHYSADDR");
		close(s);
                return(-1);
        }
	close(s);
        return 0;
}
/*
    There is a small bug in this program, the socket is never close
    before returning from the getadr() function, thus if the program
    is called multiple times and often enough you'll run out of file
    descriptors. 
    
    Fix is to insert close(s); prior to any return statement in the
    getadr() function.
    
    John
*/   
--------cut here-------- 
-- 
Lance T. Franklin            +----------------------------------------------+
(ltf@ncmicro.lonestar.org)   | "You want I should bop you with this here    |
NC Microproducts, Inc.       |    Lollipop?!?"                 The Fat Fury |
Richardson, Texas            +----------------------------------------------+


  reply	other threads:[~1992-07-06 19:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-07-02 22:20 unique identification of DECStation Chris Pinkham
1992-07-03 20:48 ` Marcus J. "will do TCP/IP for food" Ranum
1992-07-06 19:49   ` Lance Franklin [this message]
1992-07-06 16:00 ` M Darrin Chaney
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