Back to index

glibc  2.9
Classes | Defines | Functions
res_hconf.h File Reference
#include <netdb.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hconf

Defines

#define TRIMDOMAINS_MAX   4
#define HCONF_FLAG_INITED   (1 << 0) /* initialized? */
#define HCONF_FLAG_SPOOF   (1 << 1) /* refuse spoofed addresses */
#define HCONF_FLAG_SPOOFALERT   (1 << 2) /* syslog warning of spoofed */
#define HCONF_FLAG_REORDER   (1 << 3) /* list best address first */
#define HCONF_FLAG_MULTI   (1 << 4) /* see comments for gethtbyname() */

Functions

void _res_hconf_init (void)
void _res_hconf_trim_domain (char *domain)
void _res_hconf_trim_domains (struct hostent *hp)
void _res_hconf_reorder_addrs (struct hostent *hp)

Class Documentation

struct hconf

Definition at line 27 of file res_hconf.h.

Class Members
unsigned int flags
int initialized
int num_trimdomains
const char * trimdomain
int unused1
int unused2

Define Documentation

#define HCONF_FLAG_INITED   (1 << 0) /* initialized? */

Definition at line 35 of file res_hconf.h.

#define HCONF_FLAG_MULTI   (1 << 4) /* see comments for gethtbyname() */

Definition at line 39 of file res_hconf.h.

#define HCONF_FLAG_REORDER   (1 << 3) /* list best address first */

Definition at line 38 of file res_hconf.h.

#define HCONF_FLAG_SPOOF   (1 << 1) /* refuse spoofed addresses */

Definition at line 36 of file res_hconf.h.

#define HCONF_FLAG_SPOOFALERT   (1 << 2) /* syslog warning of spoofed */

Definition at line 37 of file res_hconf.h.

#define TRIMDOMAINS_MAX   4

Definition at line 25 of file res_hconf.h.


Function Documentation

void _res_hconf_init ( void  )

Definition at line 46 of file tst-rfc3484-2.c.

{
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _res_hconf_reorder_addrs ( struct hostent hp)

Definition at line 387 of file res_hconf.c.

{
#if defined SIOCGIFCONF && defined SIOCGIFNETMASK
  int i, j;
  /* Number of interfaces.  */
  static int num_ifs = -1;
  /* We need to protect the dynamic buffer handling.  */
  __libc_lock_define_initialized (static, lock);

  /* Only reorder if we're supposed to.  */
  if ((_res_hconf.flags & HCONF_FLAG_REORDER) == 0)
    return;

  /* Can't deal with anything but IPv4 for now...  */
  if (hp->h_addrtype != AF_INET)
    return;

  if (num_ifs <= 0)
    {
      struct ifreq *ifr, *cur_ifr;
      int sd, num, i;
      /* Save errno.  */
      int save = errno;

      /* Initialize interface table.  */

      /* The SIOCGIFNETMASK ioctl will only work on an AF_INET socket.  */
      sd = __socket (AF_INET, SOCK_DGRAM, 0);
      if (sd < 0)
       return;

      /* Get lock.  */
      __libc_lock_lock (lock);

      /* Recheck, somebody else might have done the work by done.  */
      if (num_ifs <= 0)
       {
         int new_num_ifs = 0;

         /* Get a list of interfaces.  */
         __ifreq (&ifr, &num, sd);
         if (!ifr)
           goto cleanup;

         ifaddrs = malloc (num * sizeof (ifaddrs[0]));
         if (!ifaddrs)
           goto cleanup1;

         /* Copy usable interfaces in ifaddrs structure.  */
         for (cur_ifr = ifr, i = 0; i < num;
              cur_ifr = __if_nextreq (cur_ifr), ++i)
           {
             if (cur_ifr->ifr_addr.sa_family != AF_INET)
              continue;

             ifaddrs[new_num_ifs].addrtype = AF_INET;
             ifaddrs[new_num_ifs].u.ipv4.addr =
              ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;

             if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
              continue;

             ifaddrs[new_num_ifs].u.ipv4.mask =
              ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;

             /* Now we're committed to this entry.  */
             ++new_num_ifs;
           }
         /* Just keep enough memory to hold all the interfaces we want.  */
         ifaddrs = realloc (ifaddrs, new_num_ifs * sizeof (ifaddrs[0]));
         assert (ifaddrs != NULL);

       cleanup1:
         __if_freereq (ifr, num);

       cleanup:
         /* Release lock, preserve error value, and close socket.  */
         save = errno;

         num_ifs = new_num_ifs;

         __libc_lock_unlock (lock);
       }

      __close (sd);
    }

  if (num_ifs == 0)
    return;

  /* Find an address for which we have a direct connection.  */
  for (i = 0; hp->h_addr_list[i]; ++i)
    {
      struct in_addr *haddr = (struct in_addr *) hp->h_addr_list[i];

      for (j = 0; j < num_ifs; ++j)
       {
         u_int32_t if_addr    = ifaddrs[j].u.ipv4.addr;
         u_int32_t if_netmask = ifaddrs[j].u.ipv4.mask;

         if (((haddr->s_addr ^ if_addr) & if_netmask) == 0)
           {
             void *tmp;

             tmp = hp->h_addr_list[i];
             hp->h_addr_list[i] = hp->h_addr_list[0];
             hp->h_addr_list[0] = tmp;
             return;
           }
       }
    }
#endif /* defined(SIOCGIFCONF) && ... */
}

Here is the call graph for this function:

void _res_hconf_trim_domain ( char *  domain)

Definition at line 508 of file res_hconf.c.

{
  size_t hostname_len, trim_len;
  int i;

  hostname_len = strlen (hostname);

  for (i = 0; i < _res_hconf.num_trimdomains; ++i)
    {
      const char *trim = _res_hconf.trimdomain[i];

      trim_len = strlen (trim);
      if (hostname_len > trim_len
         && __strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
       {
         hostname[hostname_len - trim_len] = '\0';
         break;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _res_hconf_trim_domains ( struct hostent hp)

Definition at line 533 of file res_hconf.c.

{
  int i;

  if (_res_hconf.num_trimdomains == 0)
    return;

  _res_hconf_trim_domain (hp->h_name);
  for (i = 0; hp->h_aliases[i]; ++i)
    _res_hconf_trim_domain (hp->h_aliases[i]);
}

Here is the call graph for this function: