67 #ifndef QT_NO_BEARERMANAGEMENT |
67 #ifndef QT_NO_BEARERMANAGEMENT |
68 |
68 |
69 QT_BEGIN_NAMESPACE |
69 QT_BEGIN_NAMESPACE |
70 |
70 |
71 #ifndef QT_NO_NETWORKINTERFACE |
71 #ifndef QT_NO_NETWORKINTERFACE |
72 static QString qGetInterfaceType(const QString &interface) |
72 static QNetworkConfiguration::BearerType qGetInterfaceType(const QString &interface) |
73 { |
73 { |
74 #ifdef Q_OS_WIN32 |
74 #ifdef Q_OS_WIN32 |
75 unsigned long oid; |
75 unsigned long oid; |
76 DWORD bytesWritten; |
76 DWORD bytesWritten; |
77 |
77 |
78 NDIS_MEDIUM medium; |
78 NDIS_MEDIUM medium; |
79 NDIS_PHYSICAL_MEDIUM physicalMedium; |
79 NDIS_PHYSICAL_MEDIUM physicalMedium; |
80 |
80 |
81 HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, |
81 HANDLE handle = CreateFile((TCHAR *)QString::fromLatin1("\\\\.\\%1").arg(interface).utf16(), 0, |
82 FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); |
82 FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); |
83 if (handle == INVALID_HANDLE_VALUE) |
83 if (handle == INVALID_HANDLE_VALUE) |
84 return QLatin1String("Unknown"); |
84 return QNetworkConfiguration::BearerUnknown; |
85 |
85 |
86 oid = OID_GEN_MEDIA_SUPPORTED; |
86 oid = OID_GEN_MEDIA_SUPPORTED; |
87 bytesWritten = 0; |
87 bytesWritten = 0; |
88 bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
88 bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
89 &medium, sizeof(medium), &bytesWritten, 0); |
89 &medium, sizeof(medium), &bytesWritten, 0); |
90 if (!result) { |
90 if (!result) { |
91 CloseHandle(handle); |
91 CloseHandle(handle); |
92 return QLatin1String("Unknown"); |
92 return QNetworkConfiguration::BearerUnknown; |
93 } |
93 } |
94 |
94 |
95 oid = OID_GEN_PHYSICAL_MEDIUM; |
95 oid = OID_GEN_PHYSICAL_MEDIUM; |
96 bytesWritten = 0; |
96 bytesWritten = 0; |
97 result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
97 result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
98 &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); |
98 &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); |
99 if (!result) { |
99 if (!result) { |
100 CloseHandle(handle); |
100 CloseHandle(handle); |
101 |
101 |
102 if (medium == NdisMedium802_3) |
102 if (medium == NdisMedium802_3) |
103 return QLatin1String("Ethernet"); |
103 return QNetworkConfiguration::BearerEthernet; |
104 else |
104 else |
105 return QLatin1String("Unknown"); |
105 return QNetworkConfiguration::BearerUnknown; |
106 } |
106 } |
107 |
107 |
108 CloseHandle(handle); |
108 CloseHandle(handle); |
109 |
109 |
110 if (medium == NdisMedium802_3) { |
110 if (medium == NdisMedium802_3) { |
111 switch (physicalMedium) { |
111 switch (physicalMedium) { |
112 case NdisPhysicalMediumWirelessLan: |
112 case NdisPhysicalMediumWirelessLan: |
113 return QLatin1String("WLAN"); |
113 return QNetworkConfiguration::BearerWLAN; |
114 case NdisPhysicalMediumBluetooth: |
114 case NdisPhysicalMediumBluetooth: |
115 return QLatin1String("Bluetooth"); |
115 return QNetworkConfiguration::BearerBluetooth; |
116 case NdisPhysicalMediumWiMax: |
116 case NdisPhysicalMediumWiMax: |
117 return QLatin1String("WiMAX"); |
117 return QNetworkConfiguration::BearerWiMAX; |
118 default: |
118 default: |
119 #ifdef BEARER_MANAGEMENT_DEBUG |
119 #ifdef BEARER_MANAGEMENT_DEBUG |
120 qDebug() << "Physical Medium" << physicalMedium; |
120 qDebug() << "Physical Medium" << physicalMedium; |
121 #endif |
121 #endif |
122 return QLatin1String("Ethernet"); |
122 return QNetworkConfiguration::BearerEthernet; |
123 } |
123 } |
124 } |
124 } |
125 |
125 |
126 #ifdef BEARER_MANAGEMENT_DEBUG |
126 #ifdef BEARER_MANAGEMENT_DEBUG |
127 qDebug() << medium << physicalMedium; |
127 qDebug() << medium << physicalMedium; |
133 strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name)); |
133 strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name)); |
134 int result = ioctl(sock, SIOCGIFHWADDR, &request); |
134 int result = ioctl(sock, SIOCGIFHWADDR, &request); |
135 close(sock); |
135 close(sock); |
136 |
136 |
137 if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER) |
137 if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER) |
138 return QLatin1String("Ethernet"); |
138 return QNetworkConfiguration::BearerEthernet; |
139 #else |
139 #else |
140 Q_UNUSED(interface); |
140 Q_UNUSED(interface); |
141 #endif |
141 #endif |
142 |
142 |
143 return QLatin1String("Unknown"); |
143 return QNetworkConfiguration::BearerUnknown; |
144 } |
144 } |
145 #endif |
145 #endif |
146 |
146 |
147 QGenericEngine::QGenericEngine(QObject *parent) |
147 QGenericEngine::QGenericEngine(QObject *parent) |
148 : QBearerEngineImpl(parent) |
148 : QBearerEngineImpl(parent) |