5#define WIN32_LEAN_AND_MEAN 1
10#ifndef QT_NO_NETWORKINTERFACE
30#define IF_TYPE_IEEE80216_WMAN 237
31#define IF_TYPE_IEEE802154 259
41 if (sa->sa_family == AF_INET) {
42 address.setAddress(htonl(
reinterpret_cast<const sockaddr_in *
>(sa)->sin_addr.s_addr));
43 }
else if (sa->sa_family ==
AF_INET6) {
44 auto sai6 =
reinterpret_cast<const sockaddr_in6 *
>(sa);
45 address.setAddress(sai6->sin6_addr.s6_addr);
46 if (sai6->sin6_scope_id)
49 qWarning(
"Got unknown socket family %d", sa->sa_family);
59 if (ConvertInterfaceNameToLuidW(
reinterpret_cast<const wchar_t *
>(
name.constData()), &luid) == NO_ERROR
60 && ConvertInterfaceLuidToIndex(&luid, &
id) == NO_ERROR)
68 if (ConvertInterfaceIndexToLuid(
index, &luid) == NO_ERROR) {
69 WCHAR
buf[IF_MAX_STRING_SIZE + 1];
70 if (ConvertInterfaceLuidToNameW(&luid,
buf,
sizeof(
buf)/
sizeof(
buf[0])) == NO_ERROR)
79 IP_ADAPTER_ADDRESSES staticBuf[2];
80 PIP_ADAPTER_ADDRESSES pAdapter = staticBuf;
81 ULONG
bufSize =
sizeof staticBuf;
83 ULONG
flags = GAA_FLAG_INCLUDE_PREFIX |
84 GAA_FLAG_SKIP_DNS_SERVER |
85 GAA_FLAG_SKIP_MULTICAST;
86 ULONG retval = GetAdaptersAddresses(AF_UNSPEC,
flags, NULL, pAdapter, &
bufSize);
87 if (retval == ERROR_BUFFER_OVERFLOW) {
89 pAdapter =
reinterpret_cast<IP_ADAPTER_ADDRESSES *
>(malloc(
bufSize));
93 if (GetAdaptersAddresses(AF_UNSPEC,
flags, NULL, pAdapter, &
bufSize) != ERROR_SUCCESS) {
97 }
else if (retval != ERROR_SUCCESS) {
103 for (PIP_ADAPTER_ADDRESSES
ptr = pAdapter;
ptr;
ptr =
ptr->Next) {
107 Q_ASSERT(
ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, Luid));
108 Q_ASSERT(
ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, Ipv6IfIndex));
114 if (
ptr->Ipv6IfIndex != 0)
115 iface->index =
ptr->Ipv6IfIndex;
116 else if (
ptr->IfIndex != 0)
117 iface->index =
ptr->IfIndex;
119 iface->mtu = qMin<qint64>(
ptr->Mtu, INT_MAX);
121 if (
ptr->OperStatus == IfOperStatusUp)
123 if ((
ptr->Flags & IP_ADAPTER_NO_MULTICAST) == 0)
125 if (
ptr->IfType == IF_TYPE_PPP)
128 switch (
ptr->IfType) {
129 case IF_TYPE_ETHERNET_CSMACD:
145 case IF_TYPE_SOFTWARE_LOOPBACK:
150 case IF_TYPE_IEEE80211:
154 case IF_TYPE_IEEE1394:
169 WCHAR
buf[IF_MAX_STRING_SIZE + 1];
170 if (ConvertInterfaceLuidToNameW(&
ptr->Luid,
buf,
sizeof(
buf)/
sizeof(
buf[0])) == NO_ERROR)
172 if (iface->name.isEmpty())
176 if (
ptr->PhysicalAddressLength)
177 iface->hardwareAddress = iface->makeHwAddress(
ptr->PhysicalAddressLength,
178 ptr->PhysicalAddress);
181 for (PIP_ADAPTER_UNICAST_ADDRESS
addr =
ptr->FirstUnicastAddress;
addr;
addr =
addr->Next) {
182 Q_ASSERT(
addr->Length >= offsetof(IP_ADAPTER_UNICAST_ADDRESS, OnLinkPrefixLength));
185 if (
addr->DadState == IpDadStateInvalid)
190 entry.setPrefixLength(
addr->OnLinkPrefixLength);
193 if (lifetime == 0xffffffffUL)
197 entry.setAddressLifetime(toDeadline(
addr->ValidLifetime), toDeadline(
addr->PreferredLifetime));
198 entry.setDnsEligibility(
addr->Flags & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE ?
202 iface->addressEntries <<
entry;
206 if (pAdapter != staticBuf)
219 FIXED_INFO
info, *pinfo;
222 if (GetNetworkParams(pinfo, &
bufSize) == ERROR_BUFFER_OVERFLOW) {
223 pinfo =
reinterpret_cast<FIXED_INFO *
>(malloc(
bufSize));
227 if (GetNetworkParams(pinfo, &
bufSize) != ERROR_SUCCESS) {
static constexpr ForeverConstant Forever
The QHostAddress class provides an IP address.
static QString localDomainName()
Returns the DNS domain of this machine.
The QNetworkAddressEntry class stores one IP address supported by a network interface,...
static uint interfaceIndexFromName(const QString &name)
static QString interfaceNameFromIndex(uint index)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromAce(const QByteArray &domain, AceProcessingOptions options={})
Combined button and popup list for selecting options.
static ControlElement< T > * ptr(QWidget *widget)
static QList< QNetworkInterfacePrivate * > interfaceListing()
#define IF_TYPE_IEEE802154
static QList< QNetworkInterfacePrivate * > interfaceListing()
static QT_BEGIN_NAMESPACE QHostAddress addressFromSockaddr(sockaddr *sa)
#define IF_TYPE_IEEE80216_WMAN
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLuint64EXT address
QFileInfo info(fileName)
[8]