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

  1. Newsgroups: comp.unix.ultrix
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!news.iastate.edu!john
  3. From: john@iastate.edu (John Hascall)
  4. Subject: Re: ioctl call to ln0
  5. Message-ID: <C02zKH.5n2@news.iastate.edu>
  6. Sender: news@news.iastate.edu (USENET News System)
  7. Organization: Iowa State University, Ames, IA
  8. References: <1992Dec30.135231.292@athena.mit.edu>
  9. Date: Wed, 30 Dec 1992 16:38:38 GMT
  10. Lines: 51
  11.  
  12. goeke@space.mit.edu (Robert F. Goeke) writes:
  13. }I am running Ultrix 4.3 on a variety of DECStation 5000s and wanted to 
  14. }interogate the Ethernet interface in order to retrieve the physical 
  15. }address.  The ln(4) man page gives the ioctl request, and I tracked
  16. }down via sys/ioctl.h and net/if.h what I think is enough information
  17. }to do the job, but....I'm new to this ioctl game.  How do I open
  18. }a file descriptor for this hardware interface (the first arg needed
  19. }in the ioctl call)?
  20.  
  21. Here are some code excerpts (error checking, etc. omitted for brevity) which
  22. do this sort of thing (note that this looks for the net interface rather than
  23. assuming ln0, [ie. it works for fza0 too]):
  24.  
  25.         sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  26.         interface = find_hardware_interface(sockfd);
  27.         find_hardware_address(sockfd, interface, hardware);
  28.  
  29. char * find_hardware_interface(sfd)
  30.         int     sfd;
  31. {
  32.         struct ifconf   ifconf;
  33.         struct ifreq    ifreq[10];        /* more than 10 net ifaces? */
  34.         int             i;
  35.  
  36.         ifconf.ifc_len = sizeof(ifreq);
  37.         ifconf.ifc_req = ifreq;
  38.         ioctl(sfd, SIOCGIFCONF, &ifconf);
  39.         for (i = 0; i < (ifconf.ifc_len / sizeof(struct ifreq)); ++i) {
  40.         /* find & return a suitable interface using ifreq[i] */
  41.     }
  42. }
  43.  
  44. int find_hardware_address(sfd, interface,  hardware)
  45.         int    sfd;
  46.         char * interface;
  47.         char * hardware;
  48. {
  49.         struct ifdevea  dev_info;
  50.  
  51.         strcpy(dev_info.ifr_name, interface);
  52.         ioctl(sfd, SIOCRPHYSADDR, &dev_info);
  53.         memcpy(hardware, dev_info.current_pa, 6);    /* using 6 is gross... */
  54. }
  55.  
  56. Hope this helps,
  57. John
  58. -- 
  59. John Hascall                   ``An ill-chosen word is the fool's messenger.''
  60. Systems Software Engineer
  61. Project Vincent
  62. Iowa State University Computation Center  +  Ames, IA  50011  +  515/294-9551
  63.