Changeset 472 for trunk/src/sh_calls.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_calls.c

    r412 r472  
    153153    reject = 1;
    154154
    155 #if defined(USE_IPVX)
    156155  if (0 == sh_ipvx_aton(str, &bind_addr))
    157156    return -1;
    158 #else
    159   if (0 == inet_aton(str, &(bind_addr.sin.sin_addr)))
    160     return -1;
    161 #endif
    162157
    163158  use_bind_addr = 1;
     
    170165{
    171166  int error;
     167  int err_bind = 0;
    172168  long int val_retry = 0;
    173169  char errbuf[SH_ERRBUF_SIZE];
     
    177173  errno = 0;
    178174
    179   if (0 != use_bind_addr)
     175  if (use_bind_addr)
    180176    {
    181177      int slen = SH_SS_LEN(bind_addr);
    182 
    183       val_retry = bind(sockfd, sh_ipvx_sockaddr_cast(&bind_addr), slen);
     178      struct sockaddr *b_addr = sh_ipvx_sockaddr_cast(&bind_addr);
     179
     180      if (bind_addr.ss_family == AF_INET)
     181        b_addr->sa_family = AF_INET;
     182#if defined(USE_IPVX)
     183      else
     184        b_addr->sa_family = AF_INET6;
     185#endif
     186      val_retry = bind(sockfd, b_addr, slen);
    184187    }
    185188
     
    190193      } while (val_retry < 0 && (errno == EINTR || errno == EINPROGRESS));
    191194    }
     195  else
     196    {
     197      err_bind = 1;
     198    }
    192199
    193200  error = errno;
     
    195202    long eport;
    196203    char eaddr[SH_IP_BUF];
    197 
     204    char emesg[SH_BUFSIZE];
     205    struct sockaddr *err_addr = serv_addr;
    198206    struct sh_sockaddr ss;
    199     sh_ipvx_save(&ss, serv_addr->sa_family, serv_addr);
     207
     208    if (err_bind)
     209      err_addr = sh_ipvx_sockaddr_cast(&bind_addr);
     210
     211    sh_ipvx_save(&ss, err_addr->sa_family, err_addr);
    200212    sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss);
    201213   
    202     if (serv_addr->sa_family == AF_INET)
     214    if (err_addr->sa_family == AF_INET)
    203215      eport = (long) ntohs(((struct sockaddr_in *)serv_addr)->sin_port);
     216#if defined(USE_IPVX)
    204217    else
    205218      eport = (long) ntohs(((struct sockaddr_in6 *)serv_addr)->sin6_port);
    206 
    207     sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT,
    208                      sh_error_message(error, errbuf, sizeof(errbuf)),
     219#endif
     220
     221    sl_strlcpy(emesg, sh_error_message(error, errbuf, sizeof(errbuf)), sizeof(emesg));
     222    sl_strlcat(emesg,
     223               (err_addr->sa_family == AF_INET) ? _(", AF_INET") : _(", AF_INET6"),
     224               sizeof(emesg));
     225
     226    sl_strlcat(emesg,
     227               (err_bind) ? _(", bind") : _(", connect"),
     228               sizeof(emesg));
     229   
     230    sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT,
     231                     emesg,
    209232                     (long) sockfd, eport, eaddr);
    210233  }
Note: See TracChangeset for help on using the changeset viewer.