From: gabriel@ldpmax.DEC.COM (Joe Gabriel)
Subject: Re: Hardware ID
Date: 29 Sep 89 15:25:45 GMT [thread overview]
Message-ID: <477@ryn.esg.dec.com> (raw)
In-Reply-To: 1671@nic.MR.NET
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 |
| |
+*********************************************************+
next prev parent reply other threads:[~1989-09-29 15:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1989-09-27 15:52 Hardware ID Bruce Cameron
1989-09-28 3:38 ` Alan's Home for Wayward Notes File.
1989-09-29 15:25 ` Joe Gabriel [this message]
1989-10-03 17:00 ` Bruce Cameron
1989-10-03 17:41 ` Steve Dempsey
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