Qt 4.8
Functions
qgenericengine.cpp File Reference
#include "qgenericengine.h"
#include "../qnetworksession_impl.h"
#include <QtNetwork/private/qnetworkconfiguration_p.h>
#include <QtCore/qthread.h>
#include <QtCore/qmutex.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
#include <QtCore/private/qcoreapplication_p.h>
#include "../platformdefs_win.h"
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <unistd.h>

Go to the source code of this file.

Functions

static QNetworkConfiguration::BearerType qGetInterfaceType (const QString &interface)
 

Function Documentation

◆ qGetInterfaceType()

static QNetworkConfiguration::BearerType qGetInterfaceType ( const QString interface)
static

Definition at line 72 of file qgenericengine.cpp.

Referenced by QGenericEngine::doRequestUpdate().

73 {
74 #ifdef Q_OS_WIN32
75  unsigned long oid;
76  DWORD bytesWritten;
77 
78  NDIS_MEDIUM medium;
79  NDIS_PHYSICAL_MEDIUM physicalMedium;
80 
81  HANDLE handle = CreateFile((TCHAR *)QString::fromLatin1("\\\\.\\%1").arg(interface).utf16(), 0,
82  FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
83  if (handle == INVALID_HANDLE_VALUE)
85 
87  bytesWritten = 0;
88  bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
89  &medium, sizeof(medium), &bytesWritten, 0);
90  if (!result) {
91  CloseHandle(handle);
93  }
94 
96  bytesWritten = 0;
97  result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
98  &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0);
99  if (!result) {
100  CloseHandle(handle);
101 
102  if (medium == NdisMedium802_3)
104  else
106  }
107 
108  CloseHandle(handle);
109 
110  if (medium == NdisMedium802_3) {
111  switch (physicalMedium) {
118  default:
119 #ifdef BEARER_MANAGEMENT_DEBUG
120  qDebug() << "Physical Medium" << physicalMedium;
121 #endif
123  }
124  }
125 
126 #ifdef BEARER_MANAGEMENT_DEBUG
127  qDebug() << medium << physicalMedium;
128 #endif
129 #elif defined(Q_OS_LINUX)
130  int sock = socket(AF_INET, SOCK_DGRAM, 0);
131 
132  ifreq request;
133  strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name));
134  int result = ioctl(sock, SIOCGIFHWADDR, &request);
135  close(sock);
136 
137  if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER)
139 #else
140  Q_UNUSED(interface);
141 #endif
142 
144 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
#define IOCTL_NDIS_QUERY_GLOBAL_STATS
NDIS_PHYSICAL_MEDIUM
#define OID_GEN_PHYSICAL_MEDIUM
Q_CORE_EXPORT void qDebug(const char *,...)
void * HANDLE
Definition: qnamespace.h:1671
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
NDIS_MEDIUM
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define OID_GEN_MEDIA_SUPPORTED
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729