Changeset 472 for trunk/src/sh_tools.c


Ignore:
Timestamp:
May 29, 2015, 7:08:24 PM (9 years ago)
Author:
katerina
Message:

Fix for ticket #370 (Option --bind-address broken in IPv4-only code).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_tools.c

    r425 r472  
    9393#undef  FIL__
    9494#define FIL__  _("sh_tools.c")
     95
     96static int tools_debug = 0;
    9597
    9698#ifdef SH_ENCRYPT
     
    564566  SL_ENTER(_("connect_port"));
    565567
     568  if (tools_debug)
     569    fprintf(stderr, _("-00- <%s> <%d> no IPv6 support\n"), address, port);
     570
    566571  if (errsiz > 0) errmsg[0] = '\0';
    567572
     
    575580      while (check_cache && check_cache->address)
    576581        {
     582          if (tools_debug)
     583            fprintf(stderr, _("-01- <%s> <%s>\n"),
     584                    address, check_cache->address);
     585
    577586          if ( 0 == sl_strncmp(check_cache->address,
    578587                               address, sl_strlen(address)) )
     
    584593              break;
    585594            }
     595          if (tools_debug)
     596            {
     597              char eaddr[SH_IP_BUF];
     598              sl_strlcpy(eaddr,
     599                         inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)),
     600                         sizeof(eaddr));
     601              fprintf(stderr, _("-02- <AF_INET> <%s> <%d> <%d>\n"),
     602                      eaddr,
     603                      port, cached);
     604            }
    586605          if (check_cache->next)
    587606            check_cache = check_cache->next;
     
    595614  if (cached == 0)
    596615    {
     616      if (tools_debug)
     617        fputs(_("-03- not cached\n"), stderr);
    597618#ifdef HAVE_INET_ATON
    598619      if (0 == inet_aton(address, &haddr))
     
    625646              sinr.sin_addr   = *(struct in_addr *) host_entry->h_addr;
    626647
     648              if (tools_debug)
     649                fprintf(stderr,
     650                        _("-04- <%s> <%s> hostent->h_name %s <%s> hostent->h_addr\n"),
     651                        address,
     652                        (host_entry->h_name == NULL) ? _("NULL") : host_entry->h_name,
     653                        (host_entry->h_addrtype == AF_INET) ? _("AF_INET") : _("AF_INET6"),
     654                        inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)));
    627655
    628656              /* reverse DNS lookup
     
    688716          sinr.sin_port   = htons (port);
    689717          sinr.sin_addr   = haddr;
     718
     719          if (tools_debug)
     720            fprintf(stderr,
     721                    _("-04- <%s> is_numeric AF_INET <%s> \n"),
     722                    address,
     723                    inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)));
    690724        }
    691725
     
    743777        *errnum = status;
    744778        sl_strlcpy(errmsg, sh_error_message (status, errbuf, sizeof(errbuf)), errsiz);
     779        sl_strlcat(errmsg,
     780                   (sinr.sin_family == AF_INET) ? _(", AF_INET ") : _(", AF_INET6 "),
     781                   errsiz);
    745782        sl_strlcat(errmsg, _(", address "), errsiz);
    746783        sl_strlcat(errmsg, address, errsiz);
     
    776813    delete_cache();
    777814
     815  if (tools_debug)
     816    fprintf(stderr, _("-00- <%s> <%d>\n"), address, port);
     817
    778818  if (check_cache != NULL)
    779819    {
    780820      while (check_cache && check_cache->address)
    781821        {
     822          if (tools_debug)
     823            fprintf(stderr, _("-01- <%s> <%s>\n"),
     824                    address, check_cache->address);
     825
    782826          if ( 0 == sl_strcmp(check_cache->address, address) )
    783827            {
     
    798842                  break;
    799843                }
     844              if (tools_debug)
     845                {
     846                  char eaddr[SH_IP_BUF];
     847                  sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss);
     848                  fprintf(stderr, _("-02- <%s> <%s> <%d> <%d>\n"),
     849                          (ss.ss_family == AF_INET) ? _("AF_INET") : _("AF_INET6"),
     850                          eaddr,
     851                          port, cached);
     852                }
    800853              break;
    801854            }
     
    809862  if (cached != 0)
    810863    {
     864      if (tools_debug)
     865        fputs(_("-03- cached\n"), stderr);
    811866      fd = socket(ss.ss_family, SOCK_STREAM, 0);
    812867      if (fd < 0)
     
    854909      struct addrinfo hints;
    855910
     911      if (tools_debug)
     912        fputs(_("-03- not cached\n"), stderr);
     913
    856914      memset (&hints, '\0', sizeof (hints));
    857915      hints.ai_flags = AI_ADDRCONFIG;
     
    882940          const char * canonical;
    883941
     942
    884943#if defined(AI_CANONNAME)
    885944          if (ai->ai_canonname && strlen(ai->ai_canonname) > 0)
    886945            {
    887946              canonical = ai->ai_canonname;
     947              if (tools_debug)
     948                fprintf(stderr, _("-04- <%s> <%s> ai->ai_canonname\n"),
     949                        address, canonical);
    888950            }
    889951          else
    890952            {
    891953              canonical = address;
     954              if (tools_debug)
     955                fprintf(stderr, _("-04- <%s> <%s> defined ai_canonname\n"),
     956                        address, canonical);
    892957            }
    893958#else
    894959          canonical = address;
     960          if (tools_debug)
     961            fprintf(stderr, _("-04- <%s> <%s> not defined ai_canonname\n"),
     962                    address, canonical);
    895963#endif
    896964
     
    903971              if (e == 0)
    904972                {
     973                  if (tools_debug)
     974                    {
     975                      fprintf(stderr, _("-05- <%s> <%s> <%s>\n"),
     976                              (p->ai_family == AF_INET) ? _("AF_INET") : _("AF_INET6"),
     977                              sh_ipvx_print_sockaddr (p->ai_addr, p->ai_family),
     978                              hostname);
     979                    }
     980
    905981                  if (sl_strcasecmp(hostname, canonical) == 0)
    906982                    {
     983                      if (tools_debug)
     984                        fprintf(stderr, _("-06- <%s> <%s> match\n"),
     985                                hostname, canonical);
    907986                      success = 1;
    908987                      break;
    909988                    }
     989
    910990                }
    911991           
     
    14181498      SH_IS_ASCII(head[5]) && isalpha(head[5]) &&                         
    14191499      SH_IS_ASCII(head[6]) && isalpha(head[6])) {
    1420     fprintf(stderr, "%c %3o %s %5d  %c  %c  %c  %c\n", sign,
     1500    fprintf(stderr, _("%c %3o %s %5d  %c  %c  %c  %c\n"), sign,
    14211501            head[0], code, msg_size, head[3], head[4], head[5], head[6]);
    14221502  } else {
    1423     fprintf(stderr, "%c %3o %s %5d %2X %2X %2X %2X\n", sign,
     1503    fprintf(stderr, _("%c %3o %s %5d %2X %2X %2X %2X\n"), sign,
    14241504            head[0], code, msg_size, head[3], head[4], head[5], head[6]);
    14251505  }
Note: See TracChangeset for help on using the changeset viewer.