Changeset 138:54795acda7b9 in rrlib_util


Ignore:
Timestamp:
26.04.2016 21:57:53 (4 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Parents:
136:53211ebe7c86 (diff), 137:a595ea258c54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merged with 14.08

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sFileIOUtils.cpp

    r136 r138  
    389389  std::stringstream command; 
    390390  command << "nslookup \"" << name << "\""; 
    391   RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "command = <", command, ">"); 
     391  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "command = <", command.str(), ">"); 
    392392  FILE * pipe = popen(command.str().c_str(), "r"); 
    393393  if (!pipe) 
  • sFileIOUtils.cpp

    r137 r138  
    383383struct in_addr sFileIOUtils::HostToIpViaNslookup(const std::string & name) 
    384384{ 
    385   RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
     385  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "started with host <", name, ">"); 
    386386  struct in_addr address; 
    387387  address.s_addr = 0; 
     
    389389  std::stringstream command; 
    390390  command << "nslookup \"" << name << "\""; 
    391   RRLIB_LOG_PRINT(USER, "command = <", command.str(), ">"); 
     391  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "command = <", command.str(), ">"); 
    392392  FILE * pipe = popen(command.str().c_str(), "r"); 
    393393  if (!pipe) 
     
    403403  } 
    404404  pclose(pipe); 
    405   RRLIB_LOG_PRINT(USER, "host = <", name, ">, result = <", result.str(), ">"); 
     405  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "host = <", name, ">, result = <", result.str(), ">"); 
    406406 
    407407  std::string result_str(result.str()); 
     
    414414  } 
    415415  result_str.erase(0, pos + search_token.length()); 
    416   RRLIB_LOG_PRINT(USER, "pos = ", pos); 
     416  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "pos = ", pos); 
    417417 
    418418  search_token = "Address:"; 
     
    427427  std::string found_name(result_str.substr(0, pos)); 
    428428  sStringUtils::TrimWhitespace(found_name); 
    429   //boost::trim(found_name); 
    430429  std::string ip(result_str.substr(pos + search_token.length())); 
    431430  sStringUtils::TrimWhitespace(ip); 
    432   //boost::trim(ip); 
    433  
    434   RRLIB_LOG_PRINT(USER, "found_name <", found_name, "> , name <", name, ">"); 
     431 
     432  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "found_name <", found_name, "> , name <", name, ">"); 
    435433 
    436434  if (found_name != name) 
     
    439437    return address; 
    440438  } 
    441   RRLIB_LOG_PRINT(USER, "found_name <", found_name, "> , ip <", ip, ">"); 
     439  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "found_name <", found_name, "> , ip <", ip, ">"); 
    442440 
    443441  inet_aton(ip.c_str(), &address); 
    444442 
    445   //return ip.c_str(); 
    446443  return address; 
    447444} // HostToIpViaNslookup() 
     
    453450struct in_addr sFileIOUtils::HostToIpViaHost(const std::string & name) 
    454451{ 
    455   RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
     452  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "started with host <", name, ">"); 
    456453  struct in_addr address; 
    457454  address.s_addr = 0; 
     
    459456  std::stringstream command; 
    460457  command << "host -t A \"" << name << "\""; 
    461   RRLIB_LOG_PRINT(USER, "command = <", command.str(), ">"); 
     458  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "command = <", command.str(), ">"); 
    462459  FILE * pipe = popen(command.str().c_str(), "r"); 
    463460  if (!pipe) 
     
    473470  } 
    474471  pclose(pipe); 
    475   RRLIB_LOG_PRINT(USER, "host = <", name, "> , result = <", result.str(), ">"); 
    476  
    477   std::string result_str(result.str()); 
    478   std::vector<std::string> tokens; 
    479   sStringUtils::Tokenize(result_str, tokens, " \t"); 
    480  
    481   for_each(tokens.begin(), tokens.end(), sStringUtils::Trim<std::string>()); 
    482   RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "got ", tokens.size(), " tokens:"); 
    483   RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, Join(tokens, "\n")); 
    484   if (tokens.size() != 4) 
    485   { 
    486     RRLIB_LOG_PRINT(WARNING, "Could not determine IP for host name ", name); 
     472  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "host = <", name, "> , result = <", result.str(), ">"); 
     473 
     474  string result_str(result.str()); 
     475  string search("has address"); 
     476  size_t pos = result_str.find(search); 
     477  if (pos == string::npos) 
     478  { 
     479    RRLIB_LOG_PRINT(ERROR, "could not find address token in host call"); 
    487480    return address; 
    488481  } 
    489  
    490   if (tokens.size() == 4) 
    491   { 
    492     RRLIB_LOG_PRINTF(USER, "found_name <%s> , ip <%s> \n", tokens[0].c_str(), tokens[3].c_str()); 
    493     inet_aton(tokens[3].c_str(), &address); 
    494   } 
     482  string address_str(result_str.substr(pos + search.size(), result_str.size())); 
     483  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "token = <", address_str, ">"); 
     484  sStringUtils::TrimWhitespace(address_str); 
     485  if (inet_aton(address_str.c_str(), &address) == 0) 
     486    RRLIB_LOG_PRINT(ERROR, "could not resolve address <", address_str, ">"); 
     487  else 
     488    RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "address = <", inet_ntoa(address), ">"); 
    495489  return address; 
    496490} // HostToIpViaHost() 
     
    501495struct in_addr sFileIOUtils::HostToIpViaHostsFile(const std::string & name) 
    502496{ 
    503   RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
     497  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "started with host <", name, ">"); 
    504498  struct in_addr address; 
    505499  address.s_addr = 0; 
     
    527521          { 
    528522            ip_address = *iter; 
    529             RRLIB_LOG_PRINT(USER, "sFileIOUtils::HostToIpViaHostsFile() >>> got ip <", ip_address, "> of host <", name, "> from hosts file"); 
     523            RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "sFileIOUtils::HostToIpViaHostsFile() >>> got ip <", ip_address, "> of host <", name, "> from hosts file"); 
    530524            found = true; 
    531525            break; 
Note: See TracChangeset for help on using the changeset viewer.