home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / ultrix / 9123 < prev    next >
Encoding:
Text File  |  1992-12-30  |  4.6 KB  |  165 lines

  1. Newsgroups: comp.unix.ultrix
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!haven.umd.edu!decuac!alf.dec.com!decatl!thomas
  3. From: thomas@decatl.enet.dec.com (Elgin Thomas)
  4. Subject: Re: ioctl call to ln0
  5. Message-ID: <1992Dec30.154927.20118@netnews.alf.dec.com>
  6. Lines: 152
  7. Sender: thomas@griot.alf.dec.com (Elgin Thomas)
  8. Reply-To: thomas@decatl.alf.dec.com <Elgin Thomas>
  9. Organization: Digital Equipment Corporation - Customer Support Center, Alpharetta,  GA
  10. References:  <1992Dec30.135231.292@athena.mit.edu>
  11. Date: Wed, 30 Dec 1992 15:49:27 GMT
  12.  
  13.  
  14. --
  15. Try this:
  16.  
  17.  
  18. /*
  19.  ************************************************************************
  20.  * UNSUPPORTED - UNSUPPORTED - UNSUPPORTED
  21.  *
  22.  * Program:    netif.c
  23.  * Purpose:    This program is designed to find each lan interface
  24.  *        in the system and print out its address(s).
  25.  *        The current address is what the device driver is 
  26.  *        currently set to. This is useful when running decnet,
  27.  *        as it changes the address.
  28.  *        The default address is what is encoded into the ROMS
  29.  *        of the interface.
  30.  * Usage:    netif <cr>
  31.  * Compile:    cc -g netif -o netif
  32.  ************************************************************************
  33.  */ 
  34. #define IFREQCNT    64
  35.  
  36. #include <stdio.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <sys/ioctl.h>
  40. #include <errno.h>
  41. #include <net/if.h>
  42. #include <strings.h>
  43.  
  44. main()
  45. {
  46.  struct ifreq *ifr;
  47.  struct ifreq ifreqs[IFREQCNT];
  48.  struct ifreq tmp_ifr;
  49.  struct ifconf ifc;
  50.  int sock;
  51.  
  52. /*
  53.  ************************************************************************
  54.  * Open a IP socket
  55.  ************************************************************************
  56.  */
  57.  
  58. if ((sock = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
  59.     perror("Socket open fialed");
  60.     exit(1);
  61.  }
  62.  
  63. ifc.ifc_req = ifreqs;
  64. ifc.ifc_len = sizeof(ifreqs);
  65.  
  66. /*
  67.  ************************************************************************
  68.  * Get interface list.
  69.  ************************************************************************
  70.  */
  71.  
  72. if (ioctl(sock,SIOCGIFCONF,&ifc) < 0) {
  73.     perror("Ioctl: SIOCGIFCONF");
  74.     exit(1);
  75.  }
  76.  
  77. /*
  78.  ************************************************************************
  79.  * Loop through possible interface list.
  80.  ************************************************************************
  81.  */
  82.  
  83. for (ifr = ifreqs; ifr < &ifreqs[IFREQCNT - 1]; ifr++) {
  84.  if (strlen(ifr->ifr_name) == 0) {
  85.      printf("\nEnd of network interface configuration list\n");
  86.     exit(0);
  87.   }
  88.  
  89.  if (strcmp(tmp_ifr.ifr_name,ifr->ifr_name) == 0) continue; 
  90.  strcpy(tmp_ifr.ifr_name,ifr->ifr_name);
  91.  
  92. /*
  93.  ************************************************************************
  94.  * Get what flags are available from interface
  95.  ************************************************************************
  96.  */
  97.  
  98. if (ioctl(sock,SIOCGIFFLAGS,&tmp_ifr) < 0) {
  99.     perror("Ioctl: SIOGIFFLAGS");
  100.     exit(1);
  101.  }
  102.  
  103. /*
  104.  ************************************************************************
  105.  * Find out which interfaces are up and running
  106.  ************************************************************************
  107.  */
  108.  
  109.  if (((tmp_ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) !=
  110.     (IFF_UP | IFF_RUNNING)) ||
  111.     ((tmp_ifr.ifr_flags & (IFF_POINTOPOINT)) ==
  112.     (IFF_POINTOPOINT)) ||
  113.     ((tmp_ifr.ifr_flags & (IFF_DYNPROTO|IFF_BROADCAST)) !=
  114.     (IFF_DYNPROTO | IFF_BROADCAST))) continue;
  115.  
  116.   printf("Found: %s: ",ifr->ifr_name);
  117.   print_phys(sock,tmp_ifr.ifr_name);    /* print physical address(s) */
  118.   printf("\n");
  119.  }
  120.  close(sock);
  121. }
  122.  
  123. print_phys(s,name)
  124. int s;
  125. char *name;
  126. {
  127.     struct ifdevea hw_addr;
  128.  
  129.         strcpy(hw_addr.ifr_name,name);
  130.     if (ioctl(s, SIOCRPHYSADDR, (caddr_t) &hw_addr) < 0) {
  131.         perror ("ioctl: SIOCRPHYSADDR");
  132.         close(s);
  133.         exit (1);
  134.     }
  135.  
  136.     print_addr (" hardware_addr", &hw_addr.default_pa [0]);
  137.     print_addr (" current_addr", &hw_addr.current_pa [0]);
  138. }
  139.  
  140. print_addr (what, ether_addr)
  141.     char *what, *ether_addr;
  142.     {
  143.     printf ("%s: %02x-%02x-%02x-%02x-%02x-%02x", what, 
  144.                     ether_addr [0] & 0xff,
  145.                     ether_addr [1] & 0xff,
  146.                     ether_addr [2] & 0xff,
  147.                     ether_addr [3] & 0xff,
  148.                     ether_addr [4] & 0xff,
  149.                     ether_addr [5] & 0xff);
  150.     }
  151. ____________________________________________________________________________
  152.  
  153. Elgin Thomas
  154.  
  155. Open Systems Application Support Group
  156.  
  157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. %Internet: thomas@decatl.alf.dec.com        |#include <std_disclaimer.h>   %
  159. %US mail:  Digital Equipment Corporation    |                              %
  160. %          Atlanta Customer Support Center  |"Increase the Peace"          %
  161. %          5555 Windward Parkway West       |                              %
  162. %          Alpharetta, GA  30201            |                              %
  163. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  164.  
  165.