Changeset 1620

Show
Ignore:
Timestamp:
05/25/10 22:26:23 (3 years ago)
Author:
ahu
Message:

make sure that we can bind to IPv6 link-local addresses. Feature suggested by Darren Gamble, implemented with help of Niels Bakker.

Location:
trunk/pdns/pdns
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/iputils.hh

    r1472 r1620  
    116116    if(!IpToU32(str, (uint32_t*)&sin4.sin_addr.s_addr)) { 
    117117      sin6.sin6_family = AF_INET6; 
    118       if(Utility::inet_pton(AF_INET6, str.c_str(), &sin6.sin6_addr) <= 0) 
     118      if(makeIPv6sockaddr(str, &sin6) < 0) 
    119119        throw AhuException("Unable to convert presentation address '"+ str +"'");  
    120120    } 
     
    187187  if(Utility::inet_pton(AF_INET, str.c_str(), &address.sin4.sin_addr) <= 0) { 
    188188    address.sin4.sin_family=AF_INET6; 
    189     if(Utility::inet_pton(AF_INET6, str.c_str(), &address.sin6.sin6_addr) <= 0) 
     189    if(makeIPv6sockaddr(str, &address.sin6) < 0) 
    190190      throw NetmaskException("Unable to convert '"+str+"' to a netmask");         
    191191  } 
  • trunk/pdns/pdns/misc.cc

    r1605 r1620  
    666666    return a+"."+b; 
    667667} 
     668 
     669int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) 
     670{ 
     671  struct addrinfo* res; 
     672  struct addrinfo hints; 
     673  memset(&hints, 0, sizeof(hints)); 
     674   
     675  hints.ai_family = AF_INET6; 
     676  hints.ai_flags = AI_NUMERICHOST; 
     677   
     678  if(getaddrinfo(addr.c_str(), 0, &hints, &res) < 0) { 
     679    perror("getaddrinfo"); 
     680    return -1; 
     681  } 
     682   
     683  memcpy(ret, res->ai_addr, sizeof(*ret)); 
     684   
     685  freeaddrinfo(res); 
     686  return 0; 
     687} 
  • trunk/pdns/pdns/misc.hh

    r1605 r1620  
    384384string labelReverse(const std::string& qname); 
    385385std::string dotConcat(const std::string& a, const std::string &b); 
    386  
     386int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret); 
    387387#endif 
  • trunk/pdns/pdns/pdns_recursor.cc

    r1559 r1620  
    904904    if(!IpToU32(st.host, (uint32_t*)&sin.sin4.sin_addr.s_addr)) { 
    905905      sin.sin6.sin6_family = AF_INET6; 
    906       if(Utility::inet_pton(AF_INET6, st.host.c_str(), &sin.sin6.sin6_addr) <= 0) 
     906      if(makeIPv6sockaddr(st.host, &sin.sin6) < 0) 
    907907        throw AhuException("Unable to resolve local address for TCP server on '"+ st.host +"'");  
    908908    } 
     
    968968    if(!IpToU32(st.host.c_str() , (uint32_t*)&sin.sin4.sin_addr.s_addr)) { 
    969969      sin.sin6.sin6_family = AF_INET6; 
    970       if(Utility::inet_pton(AF_INET6, st.host.c_str(), &sin.sin6.sin6_addr) <= 0) 
     970      if(makeIPv6sockaddr(st.host, &sin.sin6) < 0) 
    971971        throw AhuException("Unable to resolve local address for UDP server on '"+ st.host +"'");  
    972972    }