本文整理汇总了C++中rString::find_first_of方法的典型用法代码示例。如果您正苦于以下问题:C++ rString::find_first_of方法的具体用法?C++ rString::find_first_of怎么用?C++ rString::find_first_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rString
的用法示例。
在下文中一共展示了rString::find_first_of方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetIPFromDNS
rString NetworkUtility::GetIPFromDNS( const rString& input )
{
rString ip = "";
size_t colonPos = input.find_first_of( ":" );
rString dns = input;
if ( colonPos != std::string::npos )
dns = input.substr( 0, colonPos );
addrinfo* result = nullptr;
addrinfo hints;
memset(&hints, 0, sizeof( addrinfo ) );
hints.ai_family = AF_INET; // TODODB: When IPv6 implemented change this to AF_UNSPEC, for now force IPv4
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
#if PLATFORM == PLATFORM_WINDOWS
DWORD returnValue;
#elif PLATFORM == PLATFORM_LINUX
int returnValue;
#endif
returnValue = getaddrinfo( dns.c_str(), nullptr, &hints, &result );
if ( returnValue != 0 )
{
// TODODB: Handle dns lookup failure somehow
Logger::Log( "Failed DNS lookup with error: " + rString( gai_strerror( returnValue ) ), "Network", LogSeverity::WARNING_MSG );
return ip;
}
// result will be a linked list, use the first entry
void *addr;
if(result->ai_family == AF_INET)
{
sockaddr_in *ipv4 = (struct sockaddr_in *)result->ai_addr;
addr = &(ipv4->sin_addr);
char ipstr[INET_ADDRSTRLEN];
// convert the IP to a string and print it:
inet_ntop(result->ai_family, addr, ipstr, sizeof( ipstr ) );
ip = rString( ipstr );
}
// TODODB: Handle IPv6 when implemented and move inet_ntop to relevant place
//} else { // Is IPv6
//struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
//addr = &(ipv6->sin6_addr);
//}
// Free the linked list
freeaddrinfo( result );
return ip;
}