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

  1. /* $Id: etherlocal.c,v 2.1 89/10/23 15:42:38 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>            /* (u_char) */
  4. #include <sys/socket.h>            /* sockaddr_in (sockaddr) */
  5. #include <net/if.h>            /* ifconf */
  6. #include <netinet/in.h>            /* sockaddr_in */
  7. #include <errno.h>
  8.  
  9. extern int errno;
  10.  
  11. #include "libether.h"
  12.  
  13. extern short _ether_ifindex[MAXNUMIF];    /* from ether_interfaces() */
  14. extern struct ifconf _ether_ifconf;    /* from ether_interfaces() */
  15.  
  16.  
  17. int
  18. _ether_localif (addr, ipaddr)
  19. ether_addr *addr;
  20. struct in_addr *ipaddr;
  21. {
  22.     char **intfs;
  23.     int i;
  24.  
  25.     if ((intfs = ether_interfaces ()) == 0)
  26.     return (0);
  27.  
  28.     for (i = 0; *intfs; intfs++, i++)
  29.     {
  30.     ether_addr eaddr;
  31.  
  32.     if (_ether_ifindex[i] < 0)
  33.         continue;            /* not an AF_INET interface */
  34.  
  35.     if (ether_intfaddr (*intfs, &eaddr) == 0)
  36.         return (0);
  37.  
  38.     if (ether_cmp (addr, &eaddr) == 0)
  39.     {
  40.         struct sockaddr_in *inaddr;
  41.  
  42.         inaddr = (struct sockaddr_in *)
  43.         &_ether_ifconf.ifc_req[_ether_ifindex[i]].ifr_addr;
  44.  
  45.         (void) bcopy ((char *) &inaddr->sin_addr, (char *) ipaddr,
  46.               sizeof (*ipaddr));
  47.         return (1);
  48.     }
  49.     }
  50.  
  51.     return (0);                /* doesn't match any local interface */
  52. }
  53.