|
@@ -736,7 +736,7 @@ static bool IsLocalAdapter(const std::string& name)
|
|
|
#endif //_MSC_VER
|
|
|
}
|
|
|
|
|
|
-static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem> &netLists)
|
|
|
+static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem>& netLists)
|
|
|
{
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
|
|
@@ -761,9 +761,11 @@ static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem> &netList
|
|
|
}
|
|
|
PIP_ADAPTER_ADDRESSES pFirst = pAddresses;
|
|
|
while (pAddresses) {
|
|
|
- if (pAddresses->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET &&
|
|
|
+ if (pAddresses->FirstUnicastAddress &&
|
|
|
+ pAddresses->IfType != IF_TYPE_SOFTWARE_LOOPBACK &&
|
|
|
pAddresses->OperStatus == IfOperStatusUp &&
|
|
|
- pAddresses->IfType != IF_TYPE_SOFTWARE_LOOPBACK) {
|
|
|
+ pAddresses->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET
|
|
|
+ ) {
|
|
|
NetworkAdapterItem netItem;
|
|
|
BYTE* pa = pAddresses->PhysicalAddress;
|
|
|
if (!pa) {
|
|
@@ -827,101 +829,102 @@ static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem> &netList
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s, %s: OperStatus: %d, IfType = %d, ip=%s, mac=%s"
|
|
|
, strFriendlyName.GetData(), strDescription.GetData()
|
|
|
, pAddresses->OperStatus, pAddresses->IfType, tmpip.GetData(), tmpmac.GetData());
|
|
|
-}
|
|
|
+ }
|
|
|
pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
|
|
|
-}
|
|
|
+ }
|
|
|
HeapFree(GetProcessHeap(), 0, pFirst);
|
|
|
return Error_Succeed;
|
|
|
|
|
|
#else
|
|
|
- std::map<std::string, std::string> inteIPs;
|
|
|
- std::map<std::string, std::string> inteMacs;
|
|
|
+ std::map<std::string, std::string> inteIPs;
|
|
|
+ std::map<std::string, std::string> inteMacs;
|
|
|
std::map<std::string, int> inteStatus;
|
|
|
|
|
|
- char buf[512];
|
|
|
- toolkit_interface_address_t* info;
|
|
|
- int count, i;
|
|
|
- toolkit_interface_addresses(&info, &count);
|
|
|
- i = count;
|
|
|
- Dbg("Number of interfaces: %d", count);
|
|
|
- while (i--) {
|
|
|
- toolkit_interface_address_t interface = info[i];
|
|
|
-
|
|
|
- Dbg("Name: %s", interface.name);
|
|
|
- Dbg("Internal? %s", interface.is_internal ? "Yes" : "No");
|
|
|
- if (interface.address.address4.sin_family == AF_INET) {
|
|
|
- toolkit_ip4_name(&interface.address.address4, buf, sizeof(buf));
|
|
|
- Dbg("IPv4 address: %s", buf);
|
|
|
- inteIPs[interface.name] = buf;
|
|
|
- } else if (interface.address.address4.sin_family == AF_INET6) {
|
|
|
- toolkit_ip6_name(&interface.address.address6, buf, sizeof(buf));
|
|
|
- Dbg("IPv6 address: %s", buf);
|
|
|
- //inteIPs[interface.name] = buf;
|
|
|
- }
|
|
|
- }
|
|
|
+ char buf[512];
|
|
|
+ toolkit_interface_address_t* info;
|
|
|
+ int count, i;
|
|
|
+ toolkit_interface_addresses(&info, &count);
|
|
|
+ i = count;
|
|
|
+ Dbg("Number of interfaces: %d", count);
|
|
|
+ while (i--) {
|
|
|
+ toolkit_interface_address_t interface = info[i];
|
|
|
+
|
|
|
+ Dbg("Name: %s", interface.name);
|
|
|
+ Dbg("Internal? %s", interface.is_internal ? "Yes" : "No");
|
|
|
+ if (interface.address.address4.sin_family == AF_INET) {
|
|
|
+ toolkit_ip4_name(&interface.address.address4, buf, sizeof(buf));
|
|
|
+ Dbg("IPv4 address: %s", buf);
|
|
|
+ inteIPs[interface.name] = buf;
|
|
|
+ }
|
|
|
+ else if (interface.address.address4.sin_family == AF_INET6) {
|
|
|
+ toolkit_ip6_name(&interface.address.address6, buf, sizeof(buf));
|
|
|
+ Dbg("IPv6 address: %s", buf);
|
|
|
+ //inteIPs[interface.name] = buf;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- toolkit_free_interface_addresses(info, count);
|
|
|
- {
|
|
|
- int fd, interface;
|
|
|
- struct ifreq buf[16];
|
|
|
- struct ifconf ifc;
|
|
|
- char mac[32] = { 0 };
|
|
|
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
|
|
- int i = 0;
|
|
|
- ifc.ifc_len = sizeof(buf);
|
|
|
- ifc.ifc_buf = (caddr_t)buf;
|
|
|
- if (!ioctl(fd, SIOCGIFCONF, (char*)&ifc)) {
|
|
|
- interface = ifc.ifc_len / sizeof(struct ifreq);
|
|
|
- Dbg("interface num is %d", interface);
|
|
|
- while (i < interface) {
|
|
|
- Dbg("Name: %s", buf[i].ifr_name);
|
|
|
- if (!(ioctl(fd, SIOCGIFHWADDR, (char*)&buf[i]))) {
|
|
|
- sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[0],
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[1],
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[2],
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[3],
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[4],
|
|
|
- (unsigned char)buf[i].ifr_hwaddr.sa_data[5]);
|
|
|
- Dbg("HWaddr %s", mac);
|
|
|
- inteMacs[buf[i].ifr_name] = mac;
|
|
|
- }
|
|
|
- struct ethtool_value edata;
|
|
|
-
|
|
|
- edata.cmd = ETHTOOL_GLINK;
|
|
|
- edata.data = 0;
|
|
|
- buf[i].ifr_data = (char*)& edata;
|
|
|
- //oiltmp@20231026 只检测了以太网卡
|
|
|
- if (ioctl(fd, SIOCETHTOOL, (char*)& buf[i]) == -1) {
|
|
|
- //up down
|
|
|
- Dbg("Name: %s is down", buf[i].ifr_name);
|
|
|
- inteStatus[buf[i].ifr_name] = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Dbg("Name: %s is up", buf[i].ifr_name);
|
|
|
- inteStatus[buf[i].ifr_name] = 1;
|
|
|
- }
|
|
|
- i++;
|
|
|
- }
|
|
|
- }
|
|
|
- close(fd);
|
|
|
- }
|
|
|
- }
|
|
|
+ toolkit_free_interface_addresses(info, count);
|
|
|
+
|
|
|
+ int fd, interface;
|
|
|
+ struct ifreq buf[16];
|
|
|
+ struct ifconf ifc;
|
|
|
+ char mac[32] = { 0 };
|
|
|
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
|
|
+ int i = 0;
|
|
|
+ ifc.ifc_len = sizeof(buf);
|
|
|
+ ifc.ifc_buf = (caddr_t)buf;
|
|
|
+ if (!ioctl(fd, SIOCGIFCONF, (char*)& ifc)) {
|
|
|
+ interface = ifc.ifc_len / sizeof(struct ifreq);
|
|
|
+ Dbg("interface num is %d", interface);
|
|
|
+ while (i < interface) {
|
|
|
+ Dbg("Name: %s", buf[i].ifr_name);
|
|
|
+ if (!(ioctl(fd, SIOCGIFHWADDR, (char*)& buf[i]))) {
|
|
|
+ sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[0],
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[1],
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[2],
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[3],
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[4],
|
|
|
+ (unsigned char)buf[i].ifr_hwaddr.sa_data[5]);
|
|
|
+ Dbg("HWaddr %s", mac);
|
|
|
+ inteMacs[buf[i].ifr_name] = mac;
|
|
|
+ }
|
|
|
+ struct ethtool_value edata;
|
|
|
+
|
|
|
+ edata.cmd = ETHTOOL_GLINK;
|
|
|
+ edata.data = 0;
|
|
|
+ buf[i].ifr_data = (char*)& edata;
|
|
|
+ //oiltmp@20231026 只检测了以太网卡
|
|
|
+ if (ioctl(fd, SIOCETHTOOL, (char*)& buf[i]) == -1) {
|
|
|
+ //up down
|
|
|
+ Dbg("Name: %s is down", buf[i].ifr_name);
|
|
|
+ inteStatus[buf[i].ifr_name] = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("Name: %s is up", buf[i].ifr_name);
|
|
|
+ inteStatus[buf[i].ifr_name] = 1;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ close(fd);
|
|
|
+ }
|
|
|
|
|
|
- std::map<std::string, std::string>::const_iterator map_it = inteIPs.begin();
|
|
|
- while (map_it != inteIPs.end()) {
|
|
|
+ std::map<std::string, std::string>::const_iterator map_it = inteIPs.begin();
|
|
|
+ while (map_it != inteIPs.end()) {
|
|
|
NetworkAdapterItem netItem;
|
|
|
- CSimpleStringA tmpip(map_it->second.c_str());
|
|
|
- CSimpleStringA tmpmac(true);
|
|
|
+ CSimpleStringA tmpip(map_it->second.c_str());
|
|
|
+ CSimpleStringA tmpmac(true);
|
|
|
CSimpleStringA tmpname(true);
|
|
|
- auto it = inteMacs.find(std::string(map_it->first));
|
|
|
- if (it != inteMacs.end()) {
|
|
|
- tmpmac = it->second.c_str();
|
|
|
- }
|
|
|
- if (tmpip.Compare("127.0.0.1") == 0 && tmpmac.Compare("00:00:00:00:00:00") == 0) {
|
|
|
- //skip
|
|
|
- } else {
|
|
|
+ auto it = inteMacs.find(std::string(map_it->first));
|
|
|
+ if (it != inteMacs.end()) {
|
|
|
+ tmpmac = it->second.c_str();
|
|
|
+ }
|
|
|
+ if (tmpip.Compare("127.0.0.1") == 0 && tmpmac.Compare("00:00:00:00:00:00") == 0) {
|
|
|
+ //skip
|
|
|
+ }
|
|
|
+ else {
|
|
|
tmpname = map_it->first.c_str();
|
|
|
netItem.friend_name = "";//oiltmp
|
|
|
netItem.description = tmpname;
|
|
@@ -930,10 +933,10 @@ static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem> &netList
|
|
|
netItem.operStatus = inteStatus[map_it->first];
|
|
|
netItem.type = 6;//oiltest haven't find the in linux
|
|
|
netLists.Append(&netItem, 0, 1);
|
|
|
- }
|
|
|
- ++map_it;
|
|
|
- }
|
|
|
- return Error_Succeed;
|
|
|
+ }
|
|
|
+ ++map_it;
|
|
|
+ }
|
|
|
+ return Error_Succeed;
|
|
|
|
|
|
#endif //RVC_OS_WIN
|
|
|
|