Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* How to get MAC address
@ 1998-03-13  5:00 t.schreiner
  1998-03-13  5:00 ` Jay Olson
  0 siblings, 1 reply; 2+ messages in thread
From: t.schreiner @ 1998-03-13  5:00 UTC (permalink / raw)



Hi,
does anybody know how to get the MAC address of a workstation within a C
program?

Thanks in advance
Thomas

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to get MAC address
  1998-03-13  5:00 How to get MAC address t.schreiner
@ 1998-03-13  5:00 ` Jay Olson
  0 siblings, 0 replies; 2+ messages in thread
From: Jay Olson @ 1998-03-13  5:00 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 265 bytes --]

t.schreiner@cadenas.de wrote:
> 
> Hi,
> does anybody know how to get the MAC address of a workstation within a
> C program?
> 

Here is a short program which uses the SIOCRPHYSADDR ioctl to do that.
--
	- Jay Olson (jjo @ triton . com)
	Triton Software Group Ltd.

[-- Attachment #2: eth_addr.c --]
[-- Type: text/plain, Size: 1410 bytes --]

/*
 * eth_addr - print the ethernet address of a given interface
 *
 * Author: Jay Olson, Triton Software Group Ltd. (15-Aug-1997)
 *
 * usage:	eth_addr interface
 *
 * $Log$
 */
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <dli/dli_var.h>
#include <sys/ioctl.h>

static char rcsid[] = "$Id$";

int main (int argc, char **argv)
{
   int fd; 
   struct sockaddr_dl out_bind;
   struct ifdevea devea;

   if (argc <= 1) {
      fprintf(stderr, "usage: eth_addr interface\n");
      exit(22);
   }

/*
 *  Create a DLI socket.
 */
   if ((fd = socket(AF_DLI, SOCK_DGRAM, DLPROTO_DLI)) < 0) {
      fprintf(stderr, "eth_addr: can't open DLI socket\n");
      perror("eth_addr");
      exit(errno);
   }
    
/*
 *  Print physical address.
 */
   strcpy(devea.ifr_name,argv[1]);
   if (ioctl(fd,SIOCRPHYSADDR,&devea) < 0) {
      fprintf(stderr,"eth_addr: can't determine address for %s\n",
              devea.ifr_name);
      perror("eth_addr");
   }
   else {
      fprintf(stderr,"eth_addr: address for %s is %0.2X-%0.2X-%0.2X-%0.2X-%0.2X-%0.2X\n",
              argv[1],
              devea.current_pa[0], devea.current_pa[1],
              devea.current_pa[2], devea.current_pa[3],
              devea.current_pa[4], devea.current_pa[5]);
   }
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-03-13  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-03-13  5:00 How to get MAC address t.schreiner
1998-03-13  5:00 ` Jay Olson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox