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

  1. /* $Id: enetintaddr.c,v 2.0 89/10/20 19:02:02 dupuy Exp $ */
  2.  
  3. #include <strings.h>            /* strcpy */
  4. #include <sys/types.h>            /* (sockaddr) (u_short) */
  5. #include <sys/socket.h>            /* IFNAMSIZ (sockaddr) */
  6. #include <sys/file.h>            /* O_RDWR */
  7. #include <net/if.h>            /* IFNAMSIZ */
  8.  
  9. extern int errno;
  10.  
  11. #include "libether.h"
  12.  
  13. #ifndef ENET_DEVDIR
  14. #define ENET_DEVDIR "/dev/enet/"
  15. #endif
  16.  
  17. /*
  18.  * Returns the local ethernet address for an ethernet interface.  The result
  19.  * is stored in the structure given by address; if none is given, malloc is
  20.  * used to allocate space.
  21.  */
  22.  
  23. ether_addr *
  24. ether_intfaddr (intf, address)
  25. char *intf;
  26. ether_addr *address;
  27. {
  28.     char pathname[sizeof (ENET_DEVDIR) + IFNAMSIZ];
  29.     int fd;
  30.     int saved_errno;
  31.  
  32.     (void) strcpy (pathname, ENET_DEVDIR);
  33.     (void) strncat (pathname, intf, IFNAMSIZ);
  34.  
  35.     if ((fd = open (pathname, O_RDWR)) < 0)
  36.     {
  37. #ifdef DEBUG
  38.     perror (pathname);
  39. #endif
  40.     return (0);
  41.     }
  42.  
  43.     address = ether_address (fd, address);
  44.  
  45.     saved_errno = errno;
  46.     (void) close (fd);
  47.     errno = saved_errno;
  48.  
  49.     return (address);
  50. }
  51.