Changeset 295 for trunk/src/sh_unix.c


Ignore:
Timestamp:
Oct 31, 2010, 10:36:04 AM (15 years ago)
Author:
katerina
Message:

Support for IPv6 (ticket #222).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_unix.c

    r294 r295  
    9898#include "sh_hash.h"
    9999#include "sh_tools.h"
     100#include "sh_ipvx.h"
    100101#include "sh_tiger.h"
    101102#include "sh_prelink.h"
     
    16051606{
    16061607  struct utsname   buf;
    1607   struct hostent * he1;
    16081608  int              i;
    16091609  int              ddot;
     
    16111611  char           * p;
    16121612  char             hostname[256];
     1613  char             numeric[SH_IP_BUF];
     1614  char           * canonical;
    16131615
    16141616
     
    16561658    }
    16571659
    1658   SH_MUTEX_LOCK(mutex_resolv);
    1659   he1 = sh_gethostbyname(hostname);
    1660 
    1661   if (he1 != NULL)
    1662     {
    1663       sl_strlcpy (sh.host.name, sh_unix_h_name(he1), SH_PATHBUF);
    1664       sh_tolower (sh.host.name);
    1665     }
    1666   SH_MUTEX_UNLOCK(mutex_resolv);
    1667 
    1668   if (he1 == NULL)
    1669     {
    1670       dlog(1, FIL__, __LINE__,
    1671            _("According to uname, your nodename is %s, but your resolver\nlibrary cannot resolve this nodename to a FQDN. For more information, see the entry about self-resolving under 'Most frequently' in the FAQ that you will find in the docs/ subdirectory.\n"),
    1672            hostname);
     1660  canonical = sh_ipvx_canonical(hostname, numeric, sizeof(numeric));
     1661
     1662  if (canonical == NULL)
     1663    {
    16731664      sl_strlcpy (sh.host.name, hostname,    SH_PATHBUF);
    16741665      sh_tolower (sh.host.name);
    16751666    }
    1676  
     1667  else
     1668    {
     1669      sl_strlcpy (sh.host.name, canonical,   SH_PATHBUF);
     1670      SH_FREE(canonical);
     1671    }
    16771672
    16781673  /* check whether it looks like a FQDN
     
    16831678    if (sh.host.name[i] == '.') ++ddot;
    16841679
    1685   if (ddot == 0 && he1 != NULL)
     1680  if (ddot == 0)
    16861681    {
    16871682      dlog(1, FIL__, __LINE__,
    16881683           _("According to uname, your nodename is %s, but your resolver\nlibrary cannot resolve this nodename to a FQDN.\nRather, it resolves this to %s.\nFor more information, see the entry about self-resolving under\n'Most frequently' in the FAQ that you will find in the docs/ subdirectory.\n"),
    16891684           hostname, sh.host.name);
    1690       sl_strlcpy (sh.host.name,
    1691                   inet_ntoa (*(struct in_addr *) he1->h_addr),
    1692                   SH_PATHBUF);
     1685      sl_strlcpy (sh.host.name, numeric, SH_PATHBUF);
    16931686      SL_RET0(_("sh_unix_localhost"));
    16941687    }
    16951688
    1696   if (is_numeric(sh.host.name))
     1689  if (sh_ipvx_is_numeric(sh.host.name))
    16971690    {
    16981691      dlog(1, FIL__, __LINE__,
     
    17171710  struct utsname   buf;
    17181711#endif
    1719   struct hostent * he1;
    17201712  int              i;
    17211713  int              ddot;
    17221714  int              len;
    17231715  char             hostname[1024];
    1724 
     1716  char             numeric[SH_IP_BUF];
     1717  char           * canonical;
    17251718
    17261719  SL_ENTER(_("sh_unix_localhost"));
     
    17371730  hostname[1023] = '\0';
    17381731
    1739   SH_MUTEX_LOCK(mutex_resolv);
    1740   he1 = sh_gethostbyname(hostname);
    1741 
    1742   if (he1 != NULL)
    1743     {
    1744       sl_strlcpy (sh.host.name, sh_unix_h_name(he1), SH_PATHBUF);
     1732  canonical = sh_ipvx_canonical(hostname, numeric, sizeof(numeric));
     1733
     1734  if (canonical == NULL)
     1735    {
     1736      sl_strlcpy (sh.host.name, hostname, SH_PATHBUF);
    17451737      sh_tolower (sh.host.name);
    17461738    }
    1747   SH_MUTEX_UNLOCK(mutex_resolv);
    1748 
    1749   if (he1 == NULL)
    1750     {
    1751       dlog(1, FIL__, __LINE__,
    1752            _("According to gethostname, your nodename is %s, but your resolver\nlibrary cannot resolve this nodename to a FQDN.\nFor more information, see the entry about self-resolving under\n'Most frequently' in the FAQ that you will find in the docs/ subdirectory.\n"),
    1753            hostname);
    1754       sl_strlcpy (sh.host.name, _("localhost"), SH_PATHBUF);
    1755       SL_RET0(_("sh_unix_localhost"));
     1739  else
     1740    {
     1741      sl_strlcpy (sh.host.name, canonical,   SH_PATHBUF);
     1742      SH_FREE(canonical);
    17561743    }
    17571744
     
    17671754           _("According to uname, your nodename is %s, but your resolver\nlibrary cannot resolve this nodename to a FQDN.\nRather, it resolves this to %s.\nFor more information, see the entry about self-resolving under\n'Most frequently' in the FAQ that you will find in the docs/ subdirectory.\n"),
    17681755           hostname, sh.host.name);
    1769       sl_strlcpy (sh.host.name,
    1770                   inet_ntoa (*(struct in_addr *) he1->h_addr),
    1771                   SH_PATHBUF);
     1756      sl_strlcpy (sh.host.name, numeric, SH_PATHBUF);
    17721757      SL_RET0(_("sh_unix_localhost"));
    17731758    }
    17741759
    1775   if (is_numeric(sh.host.name))
     1760  if (sh_ipvx_is_numeric(sh.host.name))
    17761761    {
    17771762      dlog(1, FIL__, __LINE__,
Note: See TracChangeset for help on using the changeset viewer.