home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / etherlib / part01 / src / nit3intaddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-24  |  1.2 KB  |  58 lines

  1. /* $Id: nit3intaddr.c,v 2.1 89/10/23 15:42:47 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>            /* AF_NIT (u_short) */
  4. #include <sys/socket.h>            /* AF_NIT */
  5.  
  6. extern int errno;
  7.  
  8. #include "libether.h"
  9.  
  10. ether_addr _ether_localaddr;        /* shared with ether_address() */
  11. int _ether_haveaddress;            /* shared with ether_address() */
  12.  
  13. /*
  14.  * Returns the local ethernet address for an ethernet interface.  The result
  15.  * is stored in the structure given by address; if none is given, malloc is
  16.  * used to allocate space.  Sun systems have the "feature" that all ethernet
  17.  * interfaces are set to the same address (taken from the ID PROM).  So we can
  18.  * get the answer once, and use it forever.
  19.  */
  20.  
  21. /* ARGSUSED */
  22.  
  23. ether_addr *
  24. ether_intfaddr (intf, address)
  25. char *intf;
  26. ether_addr *address;
  27. {
  28.     if (!_ether_haveaddress)
  29.     {
  30.     int fd;
  31.     int saved_errno;
  32.  
  33.     if ((fd = socket (AF_NIT, SOCK_RAW, 0)) < 0)
  34.     {
  35. #ifdef DEBUG
  36.         perror ("ether_open: socket");
  37. #endif
  38.         return (0);
  39.     }
  40.  
  41.     address = ether_address (fd, address);
  42.  
  43.     saved_errno = errno;
  44.     (void) close (fd);
  45.     errno = saved_errno;
  46.  
  47.     return (address);
  48.     }
  49.  
  50.     if (address == 0)
  51.     address = (ether_addr *) malloc (sizeof (ether_addr));
  52.  
  53.     if (address != 0)
  54.     *address = _ether_localaddr;
  55.  
  56.     return (address);
  57. }
  58.