Qt5 中如何判断 QHostAddress 是 IPv4 还是 IPv6?
How to tell if QHostAddress is IPv4 or IPv6 in Qt5?
我可以像这样创建一个 QHostAddress
对象:
QHostAddress addr_ip4("127.0.0.1");
QHostAddress addr_ip6("::1/128");
并像这样测试它们的属性:
qDebug() << "addr_ip4.isNull() = " << addr_ip4.isNull();
qDebug() << "addr_ip4.isLoopback() = " << addr_ip4.isLoopback();
qDebug() << "addr_ip4.isMulticast() = " << addr_ip4.isMulticast();
qDebug() << "addr_ip6.isNull() = " << addr_ip6.isNull();
qDebug() << "addr_ip6.isLoopback() = " << addr_ip6.isLoopback();
qDebug() << "addr_ip6.isMulticast() = " << addr_ip6.isMulticast();
但是...我怎么知道哪些地址实际上是 IPv4,哪些是 IPv6?
调用 QHostAddress::protocol() will return a QAbstractSocket::NetworkLayerProtocol enum 指定地址是 IPv4、IPv6、两者还是其他。
我可以像这样创建一个 QHostAddress
对象:
QHostAddress addr_ip4("127.0.0.1");
QHostAddress addr_ip6("::1/128");
并像这样测试它们的属性:
qDebug() << "addr_ip4.isNull() = " << addr_ip4.isNull();
qDebug() << "addr_ip4.isLoopback() = " << addr_ip4.isLoopback();
qDebug() << "addr_ip4.isMulticast() = " << addr_ip4.isMulticast();
qDebug() << "addr_ip6.isNull() = " << addr_ip6.isNull();
qDebug() << "addr_ip6.isLoopback() = " << addr_ip6.isLoopback();
qDebug() << "addr_ip6.isMulticast() = " << addr_ip6.isMulticast();
但是...我怎么知道哪些地址实际上是 IPv4,哪些是 IPv6?
调用 QHostAddress::protocol() will return a QAbstractSocket::NetworkLayerProtocol enum 指定地址是 IPv4、IPv6、两者还是其他。