/* * 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... * September 28, 1993 - Doug Olson, updated to match change in * /usr/include/net/if.h (IFF_MULTICAST). * 3 November 1994 Chuck Newman. getadr was changed to return the * addresses of all ethernet devices. The * interface was completely changed. */ #include #include #include #include #include #include /* error numbers */ #include static char getadrSID[] = "@(#)getadr.c 1.5 6/22/90 demo"; extern int errno; int getadr(); /* main -- Shell to demonstrate the call to the getadr function. This * also prints the address contents to stdout. */ main(argc, argv, envp) int argc; char **argv, **envp; { char *interface; #define INTERFACE_COUNT 32 unsigned char hardware[INTERFACE_COUNT][6]; int temp_int, count; if(argc < 2) interface = NULL; else interface = argv[1]; if ((count = getadr(hardware, INTERFACE_COUNT)) == 0) { fprintf(stderr, "couldn't get network interface\n"); exit(1); } for (temp_int = 0; temp_int < abs(count); temp_int++) { printf("Ethernet hardware address = (%02.2X-%02.2X-%02.2X-%02.2X-%02.2X-%02.2X)\n", hardware[temp_int][0], hardware[temp_int][1], hardware[temp_int][2], hardware[temp_int][3], hardware[temp_int][4], hardware[temp_int][5]); } if (count < 0) printf("There are more devices than those listed\nCall getadr with a larger buffer\n"); } /* getadr -- get primary ethernet interface address * read list of net devices via ioctl to ifreqs. Pass over * loopback device and any serial line interfaces. Return * all devices. * * This function does not require setuid(2) priviledges. */ #if 0 This routine accepts two parameters, and returns the count of addresses found Input 1: Area to receive ethernet addresses Input 2: Number of addresses that can fit into the area specified by Input 1. Each address takes 6 bytes. Return Value: Positive -- number of addresses returned Negative -- absolute value is number of addresses returned, but there are more addresses Zero -- no addresses, or failure #endif #define IFREQCNT 64 /* need enough room for total number of possible * interfaces, including aliases for LAT and DECnet */ int getadr(unsigned char hardware[], int count) { int s; struct ifreq ifreqs[IFREQCNT]; struct ifconf ifc; struct ifdevea ifrp; int index = 0; int ndx, ifr; /* JOE - added this for loop - insure picked up errors */ for(s=0; s= 0) { if (index==0) { if (index == count) return -index; hardware[0+index*6] = ifrp.default_pa[0]; hardware[1+index*6] = ifrp.default_pa[1]; hardware[2+index*6] = ifrp.default_pa[2]; hardware[3+index*6] = ifrp.default_pa[3]; hardware[4+index*6] = ifrp.default_pa[4]; hardware[5+index*6] = ifrp.default_pa[5]; index+=1; } else { for (ndx=0; ; ndx++) { if (ndx == count) return -index; if (ndx == index) { hardware[0+index*6] = ifrp.default_pa[0]; hardware[1+index*6] = ifrp.default_pa[1]; hardware[2+index*6] = ifrp.default_pa[2]; hardware[3+index*6] = ifrp.default_pa[3]; hardware[4+index*6] = ifrp.default_pa[4]; hardware[5+index*6] = ifrp.default_pa[5]; index+=1; break; } if ((ifrp.default_pa[5]==hardware[ndx*6+5])&& (ifrp.default_pa[4]==hardware[ndx*6+4])&& (ifrp.default_pa[3]==hardware[ndx*6+3])&& (ifrp.default_pa[2]==hardware[ndx*6+2])&& (ifrp.default_pa[1]==hardware[ndx*6+1])&& (ifrp.default_pa[0]==hardware[ndx*6+0])) { break; } } } } } return index; }