From: thomas@decatl.enet.dec.com (Elgin Thomas)
Subject: Re: ioctl call to ln0
Reply-To: thomas@decatl.alf.dec.com <Elgin Thomas>
Organization: Digital Equipment Corporation - Customer Support Center, Alpharetta,  GA
Date: Wed, 30 Dec 1992 15:49:27 GMT


--
Try this:


/*
 ************************************************************************
 * UNSUPPORTED - UNSUPPORTED - UNSUPPORTED
 *
 * Program:	netif.c
 * Purpose:	This program is designed to find each lan interface
 *		in the system and print out its address(s).
 *		The current address is what the device driver is 
 *		currently set to. This is useful when running decnet,
 *		as it changes the address.
 *		The default address is what is encoded into the ROMS
 *		of the interface.
 * Usage:	netif <cr>
 * Compile:	cc -g netif -o netif
 ************************************************************************
 */ 
#define IFREQCNT	64

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <net/if.h>
#include <strings.h>

main()
{
 struct ifreq *ifr;
 struct ifreq ifreqs[IFREQCNT];
 struct ifreq tmp_ifr;
 struct ifconf ifc;
 int sock;

/*
 ************************************************************************
 * Open a IP socket
 ************************************************************************
 */

if ((sock = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
	perror("Socket open fialed");
	exit(1);
 }

ifc.ifc_req = ifreqs;
ifc.ifc_len = sizeof(ifreqs);

/*
 ************************************************************************
 * Get interface list.
 ************************************************************************
 */

if (ioctl(sock,SIOCGIFCONF,&ifc) < 0) {
	perror("Ioctl: SIOCGIFCONF");
	exit(1);
 }

/*
 ************************************************************************
 * Loop through possible interface list.
 ************************************************************************
 */

for (ifr = ifreqs; ifr < &ifreqs[IFREQCNT - 1]; ifr++) {
 if (strlen(ifr->ifr_name) == 0) {
 	printf("\nEnd of network interface configuration list\n");
	exit(0);
  }

 if (strcmp(tmp_ifr.ifr_name,ifr->ifr_name) == 0) continue; 
 strcpy(tmp_ifr.ifr_name,ifr->ifr_name);

/*
 ************************************************************************
 * Get what flags are available from interface
 ************************************************************************
 */

if (ioctl(sock,SIOCGIFFLAGS,&tmp_ifr) < 0) {
	perror("Ioctl: SIOGIFFLAGS");
	exit(1);
 }

/*
 ************************************************************************
 * Find out which interfaces are up and running
 ************************************************************************
 */

 if (((tmp_ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) !=
	(IFF_UP | IFF_RUNNING)) ||
	((tmp_ifr.ifr_flags & (IFF_POINTOPOINT)) ==
	(IFF_POINTOPOINT)) ||
	((tmp_ifr.ifr_flags & (IFF_DYNPROTO|IFF_BROADCAST)) !=
	(IFF_DYNPROTO | IFF_BROADCAST))) continue;

  printf("Found: %s: ",ifr->ifr_name);
  print_phys(sock,tmp_ifr.ifr_name);	/* print physical address(s) */
  printf("\n");
 }
 close(sock);
}

print_phys(s,name)
int s;
char *name;
{
	struct ifdevea hw_addr;

        strcpy(hw_addr.ifr_name,name);
	if (ioctl(s, SIOCRPHYSADDR, (caddr_t) &hw_addr) < 0) {
		perror ("ioctl: SIOCRPHYSADDR");
		close(s);
		exit (1);
	}

	print_addr (" hardware_addr", &hw_addr.default_pa [0]);
	print_addr (" current_addr", &hw_addr.current_pa [0]);
}

print_addr (what, ether_addr)
	char *what, *ether_addr;
	{
	printf ("%s: %02x-%02x-%02x-%02x-%02x-%02x", 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);
	}
____________________________________________________________________________

Elgin Thomas

Open Systems Application Support Group

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Internet: thomas@decatl.alf.dec.com        |#include <std_disclaimer.h>   %
%US mail:  Digital Equipment Corporation    |                              %
%          Atlanta Customer Support Center  |"Increase the Peace"          %
%          5555 Windward Parkway West       |                              %
%          Alpharetta, GA  30201            |                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%