src/backend/networking/tcp_address.cpp
// Returns true if the address is parsed successfully.
Returns true if the address is parsed successfully.
Returns true if the address is parsed successfully .
bool NetworkAddress::Parse(const std::string& address) {
  std::vector<std::string> parts = splitExcluding(address, ' ');
  if (parts.size() == 1) {
    parts = splitExcluding(address, ':');
  }
  if (parts.size() != 2) return false;
  if (parts[0].empty() || parts[1].empty()) return false;
  addrinfo* node = NULL;
  int error = getaddrinfo(parts[0].c_str(), NULL, NULL, &node);
  if (error != 0) {
    return false;
  }
  bool found = false;
  addrinfo* ptr = node;
  while (ptr != NULL) {
    if (ptr->ai_family == AF_INET) {
      const void* v = ptr->ai_addr;
      const sockaddr_in* addr = reinterpret_cast<const sockaddr_in*>(v);
      ip_address_ = addr->sin_addr.s_addr;
      found = true;
      break;
    }
    ptr = ptr->ai_next;
  }
  freeaddrinfo(node);
  if (!found) return false;
  long int parsed_port = strtol(parts[1].c_str(), NULL, 10);
  if (!(0 < parsed_port && parsed_port < (1 << 16))) return false;
  port_ = htons(assert_range_cast<uint16_t>(parsed_port));
  return true;
}
bool NetworkAddress :: Parse ( const std :: string & address ) { std :: vector < std :: string > parts = splitExcluding ( address , ' ' ) ; if ( parts . size ( ) == 1 ) { parts = splitExcluding ( address , ' ' ) ; } if ( parts . size ( ) != 2 ) return false ; if ( parts [ 0 ] . empty ( ) || parts [ 1 ] . empty ( ) ) return false ; addrinfo * node = NULL ; int error = getaddrinfo ( parts [ 0 ] . c_str ( ) , NULL , NULL , & node ) ; if ( error != 0 ) { return false ; } bool found = false ; addrinfo * ptr = node ; while ( ptr != NULL ) { if ( ptr -> ai_family == AF_INET ) { const void * v = ptr -> ai_addr ; const sockaddr_in * addr = reinterpret_cast < const sockaddr_in * > ( v ) ; ip_address_ = addr -> sin_addr . s_addr ; found = true ; break ; } ptr = ptr -> ai_next ; } freeaddrinfo ( node ) ; if ( ! found ) return false ; long int parsed_port = strtol ( parts [ 1 ] . c_str ( ) , NULL , 10 ) ; if ( ! ( 0 < parsed_port && parsed_port < ( 1 << 16 ) ) ) return false ; port_ = htons ( assert_range_cast < uint16_t > ( parsed_port ) ) ; return true ; }
Returns true if the address is parsed successfully.
Returns true if the address is parsed successfully .
// Try splitting with a colon // Convert the first part from text to an IP address // Avoid alignment warning on Sparc // Convert the second part from an integer to a port number