home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: alt.sources
- From: thomas@mipsbx.nac.dec.com (Matt Thomas)
- Subject: [ultrix] Re: Reading the HARDWARE ethernet address from a program?
- Message-ID: <1990Sep12.001506.22805@math.lsa.umich.edu>
- Date: Wed, 12 Sep 90 00:15:06 GMT
-
- Archive-name: ultrix-geteaddr/04-Sep-90
- Original-posting-by: thomas@mipsbx.nac.dec.com (Matt Thomas)
- Original-subject: Re: Reading the HARDWARE ethernet address from a program?
- Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
-
- [Reposted from comp.unix.ultrix.
- Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
-
- In article <19290@dime.cs.umass.edu> williams@cs.umass.edu writes:
- >We have a need to obtain the hardware ethernet address within a program.
- >We can obtain this address on a Sun using an ioctl call on /dev/nit
- >([sun-spots program] getaddr.c ) Does anyone know how one could obtain the
- >physical ethernet address in ultrix, in particular for the dec5000, MIPS
- >based workstation?
- >
- >If this is not of general interest, you can email to ralf@aai.com. I will
- >also check for followups.
- >
- >Thanks for any help!
- >
- >Leo leo@aai.com leo%aai@uunet.uu.net ...uunet!aai!leo
-
- #include <stdio.h> /* standard I/O */
- #include <errno.h> /* error numbers */
- #include <time.h> /* time definitions */
- #include <sys/types.h> /* system types */
- #include <sys/socket.h> /* socket stuff */
- #include <sys/ioctl.h> /* ioctls */
- #include <net/if.h> /* generic interface structs */
-
- extern char *optarg;
- extern int optind;
- extern char *sys_errlist[];
-
- main( argc, argv )
- int argc;
- char *argv[];
- {
- struct ifdevea devea;
- struct ifreq *ifr, ifreqs[32];
- struct ifconf ifc;
- int s, i;
-
- bzero(&devea, sizeof(devea));
-
- /* we need a socket -- any old socket will do. */
- s = socket(AF_UNIX, SOCK_DGRAM, 0);
- if (s < 0) {
- perror("socket");
- exit(1);
- }
-
- ifc.ifc_req = ifreqs;
- ifc.ifc_len = sizeof(ifreqs);
- if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
- perror("siocgifconf");
- exit(1);
- }
-
- for (ifr = ifreqs; ifc.ifc_len > 0; ifr++, ifc.ifc_len -= sizeof(*ifr)) {
- if (strcmp(devea.ifr_name, ifr->ifr_name)) {
- (void) strcpy(devea.ifr_name, ifr->ifr_name);
- /* read the address of the interface */
- if (ioctl(s, SIOCRPHYSADDR, &devea) < 0) {
- /* error? */
- if (errno != EOPNOTSUPP && errno |= EINVAL) {
- /* unexpected error */
- perror(devea.ifr_name);
- }
- continue;
- }
- printf("%s: ", devea.ifr_name);
- printf("current = %02x-%02x-%02x-%02x-%02x-%02x, ",
- devea.current_pa[0], devea.current_pa[1], devea.current_pa[2],
- devea.current_pa[3], devea.current_pa[4], devea.current_pa[5]
- );
- printf("default = %02x-%02x-%02x-%02x-%02x-%02x\n",
- devea.default_pa[0], devea.default_pa[1], devea.default_pa[2],
- devea.default_pa[3], devea.default_pa[4], devea.default_pa[5]
- );
- }
- }
- }
- Matt Thomas Internet: thomas@wrl.dec.com
- DECnet-ULTRIX Development UUCP: ...!decwrl!thomas
- Digital Equipment Corporation Disclaimer: This message reflects my own
- Littleton, MA warped views, etc.
-