Changeset 2010
- Timestamp:
- 02/14/11 10:58:10 (2 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 5 modified
-
dnsproxy.cc (modified) (1 diff)
-
iputils.hh (modified) (2 diffs)
-
misc.cc (modified) (5 diffs)
-
misc.hh (modified) (2 diffs)
-
pdns_recursor.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dnsproxy.cc
r1549 r2010 140 140 if(i->second.created) 141 141 L<<Logger::Warning<<"Recursive query for remote "<< 142 sockAddrToString((struct sockaddr_in *)&i->second.remote)<<" with internal id "<<n<<142 i->second.remote.toStringWithPort()<<" with internal id "<<n<< 143 143 " was not answered by backend within timeout, reusing id"<<endl; 144 144 -
trunk/pdns/pdns/iputils.hh
r2009 r2010 109 109 } 110 110 111 // 'port' sets a default value in case 'str' does not set a port 111 112 explicit ComboAddress(const string& str, uint16_t port=0) 112 113 { 113 114 memset(&sin6, 0, sizeof(sin6)); 114 115 sin4.sin_family = AF_INET; 115 116 if( !IpToU32(str, (uint32_t*)&sin4.sin_addr.s_addr)) {116 sin4.sin_port = 0; 117 if(makeIPv4sockaddr(str, &sin4)) { 117 118 sin6.sin6_family = AF_INET6; 118 119 if(makeIPv6sockaddr(str, &sin6) < 0) … … 120 121 121 122 } 122 sin4.sin_port=htons(port); 123 if(!sin4.sin_port) // 'str' overrides port! 124 sin4.sin_port=htons(port); 123 125 } 124 126 -
trunk/pdns/pdns/misc.cc
r1978 r2010 482 482 483 483 484 const string sockAddrToString(struct sockaddr_in *remote)485 {486 if(remote->sin_family == AF_INET) {487 struct sockaddr_in sip;488 memcpy(&sip,(struct sockaddr_in*)remote,sizeof(sip));489 return inet_ntoa(sip.sin_addr);490 }491 else {492 char tmp[128];493 494 if(!Utility::inet_ntop(AF_INET6, ( const char * ) &((struct sockaddr_in6 *)remote)->sin6_addr, tmp, sizeof(tmp)))495 return "IPv6 untranslateable";496 497 return tmp;498 }499 }500 501 484 string makeHexDump(const string& str) 502 485 { … … 511 494 return ret; 512 495 } 513 514 515 496 516 497 // shuffle, maintaining some semblance of order … … 666 647 int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) 667 648 { 649 if(addr.empty()) 650 return -1; 651 string ourAddr(addr); 652 int port = -1; 653 if(addr[0]=='[') { // [::]:53 style address 654 string::size_type pos = addr.find(']'); 655 if(pos == string::npos || pos + 2 > addr.size() || addr[pos+1]!=':') 656 return -1; 657 ourAddr.assign(addr.c_str() + 1, pos-1); 658 port = atoi(addr.c_str()+pos+2); 659 } 660 668 661 struct addrinfo* res; 669 662 struct addrinfo hints; … … 674 667 675 668 int error; 676 if((error=getaddrinfo( addr.c_str(), 0, &hints, &res))) {669 if((error=getaddrinfo(ourAddr.c_str(), 0, &hints, &res))) { // this is correct 677 670 /* 678 671 cerr<<"Error translating IPv6 address '"<<addr<<"': "; … … 686 679 687 680 memcpy(ret, res->ai_addr, res->ai_addrlen); 688 681 if(port >= 0) 682 ret->sin6_port = htons(port); 689 683 freeaddrinfo(res); 690 684 return 0; 691 685 } 686 687 int makeIPv4sockaddr(const string &str, struct sockaddr_in* ret) 688 { 689 if(str.empty()) { 690 return -1; 691 } 692 struct in_addr inp; 693 694 string::size_type pos = str.find(':'); 695 if(pos == string::npos) { // no port specified, not touching the port 696 if(Utility::inet_aton(str.c_str(), &inp)) { 697 ret->sin_addr.s_addr=inp.s_addr; 698 return 0; 699 } 700 return -1; 701 } 702 if(!*(str.c_str() + pos + 1)) // trailing : 703 return -1; 704 705 char *eptr = (char*)str.c_str() + str.size(); 706 int port = strtol(str.c_str() + pos + 1, &eptr, 10); 707 if(*eptr) 708 return -1; 709 710 ret->sin_port = htons(port); 711 if(Utility::inet_aton(str.substr(0, pos).c_str(), &inp)) { 712 ret->sin_addr.s_addr=inp.s_addr; 713 return 0; 714 } 715 return -1; 716 } 717 692 718 693 719 //! read a line of text from a FILE* to a std::string, returns false on 'no data' -
trunk/pdns/pdns/misc.hh
r1976 r2010 216 216 struct timeval d_set; 217 217 }; 218 const string sockAddrToString(struct sockaddr_in *remote); 218 219 219 int sendData(const char *buffer, int replen, int outsock); 220 220 … … 458 458 std::string dotConcat(const std::string& a, const std::string &b); 459 459 int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret); 460 int makeIPv4sockaddr(const string &str, struct sockaddr_in* ret); 460 461 bool stringfgets(FILE* fp, std::string& line); 461 462 -
trunk/pdns/pdns/pdns_recursor.cc
r1997 r2010 1385 1385 g_stats.serverParseError++; 1386 1386 if(g_logCommonErrors) 1387 L<<Logger::Error<<"Unable to parse packet from remote UDP server "<< sockAddrToString((struct sockaddr_in*) &fromaddr) <<1387 L<<Logger::Error<<"Unable to parse packet from remote UDP server "<< fromaddr.toString() << 1388 1388 ": packet smalller than DNS header"<<endl; 1389 1389 } … … 1418 1418 catch(std::exception& e) { 1419 1419 g_stats.serverParseError++; // won't be fed to lwres.cc, so we have to increment 1420 L<<Logger::Warning<<"Error in packet from "<< sockAddrToString((struct sockaddr_in*) &fromaddr) << ": "<<e.what() << endl;1420 L<<Logger::Warning<<"Error in packet from "<< fromaddr.toStringWithPort() << ": "<<e.what() << endl; 1421 1421 return; 1422 1422 } … … 1458 1458 } 1459 1459 else 1460 L<<Logger::Warning<<"Ignoring question on outgoing socket from "<< sockAddrToString((struct sockaddr_in*) &fromaddr) <<endl;1460 L<<Logger::Warning<<"Ignoring question on outgoing socket from "<< fromaddr.toStringWithPort() <<endl; 1461 1461 } 1462 1462