Article View: comp.sys.dec
Article #740Re: Hardware ID
From: Joe Gabriel
Date: Fri, 29 Sep 1989 15:25
Date: Fri, 29 Sep 1989 15:25
86 lines
2847 bytes
2847 bytes
Here is a program that prints out my ethernet address on my DECstation 3100 running ULTRIX 3.1:
#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);
}
+*********************************************************+
| | |
| Joe Gabriel | Digital Equipment Corp. |
| Laboratory Data Prodcuts | Technical Consulting |
| Four Results Way | Marlboro, MA 01752-9122 |
| gabriel@ldpmax.enet.dec.com | (508) 467-5055 |
| | |
| % ls -l disclaimer |
| Jan 01 00:00 disclaimer -> standard/one/we/always/see |
| |
+*********************************************************+
Technical Details
Message-ID:
<477@ryn.esg.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!decuac!shlump.nac.dec.com!ryn.esg.dec.com!ldpmax.DEC.COM!gabrielReferences:
<434@shodha.dec.com> <1671@nic.MR.NET>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!decuac!shlump.nac.dec.com!ryn.esg.dec.com!ldpmax.DEC.COM!gabriel From: gabriel@ldpmax.DEC.COM (Joe Gabriel) Newsgroups: comp.sys.dec Subject: Re: Hardware ID Message-ID: <477@ryn.esg.dec.com> Date: 29 Sep 89 15:25:45 GMT References: <434@shodha.dec.com> <1671@nic.MR.NET> Sender: usenet@ryn.esg.dec.com Organization: = Lines: 86