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

  1. /* $Id: dliintaddr.c,v 2.1 89/10/23 15:41:58 dupuy Exp $ */
  2.  
  3. #include <errno.h>
  4.  
  5. extern int errno;
  6.  
  7. #include "libether.h"
  8.  
  9. /*
  10.  * Returns the local ethernet address for the ethernet interface.  The result
  11.  * is stored in the structure given by address; if none is given, malloc is
  12.  * used to allocate space.
  13.  */
  14.  
  15. ether_addr *
  16. ether_intfaddr (intf, address)
  17. char *intf;
  18. ether_addr *address;
  19. {
  20.     int fd;
  21.     unsigned short proto = 0xffff;
  22.     int saved_errno;
  23.  
  24.     do
  25.     if ((fd = ether_open (intf, proto--, (ether_addr *) 0)) < 0)
  26.     {
  27.         if (errno == EADDRINUSE)
  28.         continue;
  29.         return (0);
  30.     }                /* constant argument to NOT ??? */
  31.     while (fd < 0 && proto >= ETHER_MINTYPE);
  32.  
  33.     address = ether_address (fd, address);
  34.  
  35.     saved_errno = errno;
  36.     (void) close (fd);
  37.     errno = saved_errno;
  38.  
  39.     return (address);
  40. }
  41.