本文整理汇总了C++中IpAddress::isV6方法的典型用法代码示例。如果您正苦于以下问题:C++ IpAddress::isV6方法的具体用法?C++ IpAddress::isV6怎么用?C++ IpAddress::isV6使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IpAddress
的用法示例。
在下文中一共展示了IpAddress::isV6方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool SocketAddress::parse ( Type t, const std::string& str )
{
memset ( &sa_, 0, sizeof ( sa_ ) );
switch ( t )
{
case Internet:
{
const size_t idx = str.find_last_of ( ":" );
if ( idx == std::string::npos )
return false;
IpAddress addr;
if ( ! addr.parse ( str.substr ( 0, idx ) ) || ! addr.isV4() )
return false;
assert ( addr.isV4() );
const uint16_t port = std::stoi ( str.substr ( idx + 1 ) );
struct sockaddr_in* sin = ( struct sockaddr_in* ) &sa_;
sin->sin_family = AF_INET;
sin->sin_port = htons ( port );
sin->sin_addr.s_addr = addr.v4()->s_addr;
return true;
}
case Internet6:
{
const size_t idx = str.find_last_of ( ":" );
if ( idx == std::string::npos )
return false;
IpAddress addr;
if ( ! addr.parse ( str.substr ( 0, idx ) ) || ! addr.isV6() )
return false;
assert ( addr.isV6() );
const uint16_t port = std::stoi ( str.substr ( idx + 1 ) );
struct sockaddr_in6* sin6 = ( struct sockaddr_in6* ) &sa_;
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons ( port );
memcpy ( & ( sin6->sin6_addr ), addr.v6(), sizeof ( in6_addr ) );
sin6->sin6_scope_id = 0;
sin6->sin6_flowinfo = 0;
return true;
}
case Local:
{
struct sockaddr_un* sun = ( struct sockaddr_un* ) &sa_;
sun->sun_family = AF_LOCAL;
strlcpy ( sun->sun_path, str.c_str(), sizeof ( sun->sun_path ) );
return true;
}
case Datalink:
{
struct sockaddr_dl* sdl = ( struct sockaddr_dl* ) &sa_;
sdl->sdl_family = AF_LINK;
/// @todo Implement this further
}
case Unspecified:
default:
assert ( false );
return false;
}
}