git-svn-id: svn://db.shs.com.ru/pip@852 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-08-31 14:30:26 +00:00
parent 7e7a885302
commit 32daaedf32

View File

@@ -1125,21 +1125,22 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
} }
delete ifc.ifc_buf; delete ifc.ifc_buf;
# else # else
struct ifaddrs * ret; struct ifaddrs * ret, * cif = 0;
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP); int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (getifaddrs(&ret) == 0) { if (getifaddrs(&ret) == 0) {
while (ret != 0) { cif = ret;
if (ret->ifa_addr == 0) { while (cif != 0) {
ret = ret->ifa_next; if (cif->ifa_addr == 0) {
cif = cif->ifa_next;
continue; continue;
} }
if (ret->ifa_addr->sa_family != AF_INET) { if (cif->ifa_addr->sa_family != AF_INET) {
ret = ret->ifa_next; cif = cif->ifa_next;
continue; continue;
} }
ci.name = PIString(ret->ifa_name); ci.name = PIString(cif->ifa_name);
ci.address = getSockAddr(ret->ifa_addr); ci.address = getSockAddr(cif->ifa_addr);
ci.netmask = getSockAddr(ret->ifa_netmask); ci.netmask = getSockAddr(cif->ifa_netmask);
ci.mac.clear(); ci.mac.clear();
# ifdef QNX # ifdef QNX
# ifndef BLACKBERRY # ifndef BLACKBERRY
@@ -1166,7 +1167,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
# else # else
if (s != -1) { if (s != -1) {
struct ifreq ir; struct ifreq ir;
strcpy(ir.ifr_name, ret->ifa_name); strcpy(ir.ifr_name, cif->ifa_name);
if (ioctl(s, SIOCGIFHWADDR, &ir) == 0) { if (ioctl(s, SIOCGIFHWADDR, &ir) == 0) {
ci.mac = macFromBytes(PIByteArray(ir.ifr_hwaddr.sa_data, 6)); ci.mac = macFromBytes(PIByteArray(ir.ifr_hwaddr.sa_data, 6));
ci.mtu = ir.ifr_mtu; ci.mtu = ir.ifr_mtu;
@@ -1175,21 +1176,21 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
# endif # endif
# endif # endif
ci.flags = 0; ci.flags = 0;
if (ret->ifa_flags & IFF_UP) ci.flags |= PIEthernet::ifActive; if (cif->ifa_flags & IFF_UP) ci.flags |= PIEthernet::ifActive;
if (ret->ifa_flags & IFF_RUNNING) ci.flags |= PIEthernet::ifRunning; if (cif->ifa_flags & IFF_RUNNING) ci.flags |= PIEthernet::ifRunning;
if (ret->ifa_flags & IFF_BROADCAST) ci.flags |= PIEthernet::ifBroadcast; if (cif->ifa_flags & IFF_BROADCAST) ci.flags |= PIEthernet::ifBroadcast;
if (ret->ifa_flags & IFF_MULTICAST) ci.flags |= PIEthernet::ifMulticast; if (cif->ifa_flags & IFF_MULTICAST) ci.flags |= PIEthernet::ifMulticast;
if (ret->ifa_flags & IFF_LOOPBACK) ci.flags |= PIEthernet::ifLoopback; if (cif->ifa_flags & IFF_LOOPBACK) ci.flags |= PIEthernet::ifLoopback;
if (ret->ifa_flags & IFF_POINTOPOINT) ci.flags |= PIEthernet::ifPTP; if (cif->ifa_flags & IFF_POINTOPOINT) ci.flags |= PIEthernet::ifPTP;
ci.broadcast.clear(); ci.broadcast.clear();
ci.ptp.clear(); ci.ptp.clear();
if (ci.flags[PIEthernet::ifBroadcast]) if (ci.flags[PIEthernet::ifBroadcast])
ci.broadcast = getSockAddr(ret->ifa_broadaddr); ci.broadcast = getSockAddr(cif->ifa_broadaddr);
if (ci.flags[PIEthernet::ifPTP]) if (ci.flags[PIEthernet::ifPTP])
ci.ptp = getSockAddr(ret->ifa_dstaddr); ci.ptp = getSockAddr(cif->ifa_dstaddr);
ci.index = if_nametoindex(ret->ifa_name); ci.index = if_nametoindex(cif->ifa_name);
il << ci; il << ci;
ret = ret->ifa_next; cif = cif->ifa_next;
} }
freeifaddrs(ret); freeifaddrs(ret);
} else } else