зеркало из https://github.com/mozilla/gecko-dev.git
Bug 978709 - 4.h/6: NetworkInterfaceListService changes. r=vicamo
This commit is contained in:
Родитель
1d9cbf76fd
Коммит
0b0b45972a
|
@ -341,9 +341,17 @@ function isNetworkReady() {
|
|||
SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_DUN_INTERFACES);
|
||||
var num = itfList.getNumberOfInterface();
|
||||
for (var i = 0; i < num; i++) {
|
||||
if (itfList.getInterface(i).ip) {
|
||||
info("Network interface is ready with address: " + itfList.getInterface(i).ip);
|
||||
return true;
|
||||
var ips = {};
|
||||
var prefixLengths = {};
|
||||
var length = itfList.getInterface(i).getAddresses(ips, prefixLengths);
|
||||
|
||||
for (var j = 0; j < length; j++) {
|
||||
var ip = ips.value[j];
|
||||
// skip IPv6 address
|
||||
if (ip.indexOf(":") < 0) {
|
||||
info("Network interface is ready with address: " + ip);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ip address is not available
|
||||
|
|
|
@ -47,12 +47,52 @@ NetworkInterfaceListService.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function NetworkInterfaceList (aInterfaces) {
|
||||
this._interfaces = aInterfaces;
|
||||
function FakeNetworkInterface(aAttributes) {
|
||||
this.state = aAttributes.state;
|
||||
this.type = aAttributes.type;
|
||||
this.name = aAttributes.name;
|
||||
this.ips = aAttributes.ips;
|
||||
this.prefixLengths = aAttributes.prefixLengths;
|
||||
this.gateways = aAttributes.gateways;
|
||||
this.dnses = aAttributes.dnses;
|
||||
this.httpProxyHost = aAttributes.httpProxyHost;
|
||||
this.httpProxyPort = aAttributes.httpProxyPort;
|
||||
}
|
||||
FakeNetworkInterface.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
|
||||
|
||||
getAddresses: function (ips, prefixLengths) {
|
||||
ips.value = this.ips.slice();
|
||||
prefixLengths.value = this.prefixLengths.slice();
|
||||
|
||||
return this.ips.length;
|
||||
},
|
||||
|
||||
getGateways: function (count) {
|
||||
if (count) {
|
||||
count.value = this.gateways.length;
|
||||
}
|
||||
return this.gateways.slice();
|
||||
},
|
||||
|
||||
getDnses: function (count) {
|
||||
if (count) {
|
||||
count.value = this.dnses.length;
|
||||
}
|
||||
return this.dnses.slice();
|
||||
}
|
||||
};
|
||||
|
||||
function NetworkInterfaceList (aInterfaceLiterals) {
|
||||
this._interfaces = [];
|
||||
for (let entry of aInterfaceLiterals) {
|
||||
this._interfaces.push(new FakeNetworkInterface(entry));
|
||||
}
|
||||
}
|
||||
|
||||
NetworkInterfaceList.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]),
|
||||
|
||||
getNumberOfInterface: function() {
|
||||
return this._interfaces.length;
|
||||
},
|
||||
|
|
|
@ -357,15 +357,18 @@ NetworkManager.prototype = {
|
|||
continue;
|
||||
}
|
||||
#endif
|
||||
let ips = {};
|
||||
let prefixLengths = {};
|
||||
i.getAddresses(ips, prefixLengths);
|
||||
|
||||
interfaces.push({
|
||||
state: i.state,
|
||||
type: i.type,
|
||||
name: i.name,
|
||||
ip: i.ip,
|
||||
prefixLength: i.prefixLength,
|
||||
gateway: i.gateway,
|
||||
dns1: i.dns1,
|
||||
dns2: i.dns2,
|
||||
ips: ips.value,
|
||||
prefixLengths: prefixLengths.value,
|
||||
gateways: i.getGateways(),
|
||||
dnses: i.getDnses(),
|
||||
httpProxyHost: i.httpProxyHost,
|
||||
httpProxyPort: i.httpProxyPort
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ extern "C" {
|
|||
#include "nsINetworkInterfaceListService.h"
|
||||
#include "runnable_utils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "mozilla/SyncRunnable.h"
|
||||
|
@ -55,25 +56,43 @@ GetInterfaces(std::vector<NetworkInterface>* aInterfaces)
|
|||
NS_ERROR_FAILURE);
|
||||
aInterfaces->clear();
|
||||
|
||||
nsAutoString ip;
|
||||
nsAutoString ifaceName;
|
||||
for (int32_t i = 0; i < listLength; i++) {
|
||||
nsCOMPtr<nsINetworkInterface> iface;
|
||||
if (NS_FAILED(networkList->GetInterface(i, getter_AddRefs(iface)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char16_t **ips = nullptr;
|
||||
uint32_t *prefixs = nullptr;
|
||||
uint32_t count = 0;
|
||||
bool isAddressGot = false;
|
||||
NetworkInterface interface;
|
||||
memset(&(interface.addr), 0, sizeof(interface.addr));
|
||||
interface.addr.sin_family = AF_INET;
|
||||
if (NS_FAILED(iface->GetIp(ip))) {
|
||||
continue;
|
||||
}
|
||||
if (inet_pton(AF_INET, NS_ConvertUTF16toUTF8(ip).get(),
|
||||
&(interface.addr.sin_addr.s_addr)) != 1) {
|
||||
|
||||
if (NS_FAILED(iface->GetAddresses(&ips, &prefixs, &count))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (uint32_t j = 0; j < count; j++) {
|
||||
nsAutoString ip;
|
||||
|
||||
ip.Assign(ips[j]);
|
||||
if (inet_pton(AF_INET, NS_ConvertUTF16toUTF8(ip).get(),
|
||||
&(interface.addr.sin_addr.s_addr)) == 1) {
|
||||
isAddressGot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsMemory::Free(prefixs);
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, ips);
|
||||
|
||||
if (!isAddressGot) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoString ifaceName;
|
||||
if (NS_FAILED(iface->GetName(ifaceName))) {
|
||||
continue;
|
||||
}
|
||||
|
@ -84,12 +103,12 @@ GetInterfaces(std::vector<NetworkInterface>* aInterfaces)
|
|||
continue;
|
||||
}
|
||||
switch (type) {
|
||||
case nsINetworkInterface::NETWORK_TYPE_WIFI:
|
||||
interface.type = NR_INTERFACE_TYPE_WIFI;
|
||||
break;
|
||||
case nsINetworkInterface::NETWORK_TYPE_MOBILE:
|
||||
interface.type = NR_INTERFACE_TYPE_MOBILE;
|
||||
break;
|
||||
case nsINetworkInterface::NETWORK_TYPE_WIFI:
|
||||
interface.type = NR_INTERFACE_TYPE_WIFI;
|
||||
break;
|
||||
case nsINetworkInterface::NETWORK_TYPE_MOBILE:
|
||||
interface.type = NR_INTERFACE_TYPE_MOBILE;
|
||||
break;
|
||||
}
|
||||
|
||||
aInterfaces->push_back(interface);
|
||||
|
|
Загрузка…
Ссылка в новой задаче