kernel/qnetworkinterface_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4static QHostAddress addressFromSockaddr(sockaddr *sa) -
5{ -
6 QHostAddress address; -
7 if (!sa)
evaluated: !sa
TRUEFALSE
yes
Evaluation Count:489
yes
Evaluation Count:3912
489-3912
8 return address;
executed: return address;
Execution Count:489
489
9 -
10 if (sa->sa_family == 2)
evaluated: sa->sa_family == 2
TRUEFALSE
yes
Evaluation Count:1793
yes
Evaluation Count:2119
1793-2119
11 address.setAddress((__extension__ ({ register unsigned int __v, __x = (((sockaddr_in *)sa)->sin_addr.s_addr); if (__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; })));
executed: address.setAddress((__extension__ ({ register unsigned int __v, __x = (((sockaddr_in *)sa)->sin_addr.s_addr); if (__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; })));
Execution Count:1793
never executed: __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24));
executed: __asm__ ("bswap %0" : "=r" (__v) : "0" (__x));
Execution Count:1793
partially evaluated: __builtin_constant_p (__x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1793
0-1793
12 else if (sa->sa_family == 10) {
evaluated: sa->sa_family == 10
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:815
815-1304
13 address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.__in6_u.__u6_addr8); -
14 int scope = ((sockaddr_in6 *)sa)->sin6_scope_id; -
15 if (scope) {
evaluated: scope
TRUEFALSE
yes
Evaluation Count:489
yes
Evaluation Count:815
489-815
16 -
17 char scopeid[16]; -
18 if (::if_indextoname(scope, scopeid)) {
partially evaluated: ::if_indextoname(scope, scopeid)
TRUEFALSE
yes
Evaluation Count:489
no
Evaluation Count:0
0-489
19 address.setScopeId(QLatin1String(scopeid)); -
20 } else
executed: }
Execution Count:489
489
21 -
22 address.setScopeId(QString::number(scope));
never executed: address.setScopeId(QString::number(scope));
0
23 } -
24 }
executed: }
Execution Count:1304
1304
25 return address;
executed: return address;
Execution Count:3912
3912
26 -
27} -
28 -
29static QNetworkInterface::InterfaceFlags convertFlags(uint rawFlags) -
30{ -
31 QNetworkInterface::InterfaceFlags flags = 0; -
32 flags |= (rawFlags & IFF_UP) ? QNetworkInterface::IsUp : QNetworkInterface::InterfaceFlag(0);
evaluated: (rawFlags & IFF_UP)
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:163
163-652
33 flags |= (rawFlags & IFF_RUNNING) ? QNetworkInterface::IsRunning : QNetworkInterface::InterfaceFlag(0);
evaluated: (rawFlags & IFF_RUNNING)
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:163
163-652
34 flags |= (rawFlags & IFF_BROADCAST) ? QNetworkInterface::CanBroadcast : QNetworkInterface::InterfaceFlag(0);
evaluated: (rawFlags & IFF_BROADCAST)
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:163
163-652
35 flags |= (rawFlags & IFF_LOOPBACK) ? QNetworkInterface::IsLoopBack : QNetworkInterface::InterfaceFlag(0);
evaluated: (rawFlags & IFF_LOOPBACK)
TRUEFALSE
yes
Evaluation Count:163
yes
Evaluation Count:652
163-652
36 -
37 flags |= (rawFlags & IFF_POINTOPOINT) ? QNetworkInterface::IsPointToPoint : QNetworkInterface::InterfaceFlag(0);
partially evaluated: (rawFlags & IFF_POINTOPOINT)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:815
0-815
38 -
39 -
40 -
41 flags |= (rawFlags & IFF_MULTICAST) ? QNetworkInterface::CanMulticast : QNetworkInterface::InterfaceFlag(0);
evaluated: (rawFlags & IFF_MULTICAST)
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:163
163-652
42 -
43 return flags;
executed: return flags;
Execution Count:815
815
44} -
45 -
46 -
47 -
48 -
49 -
50 -
51 -
52static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList) -
53{ -
54 QList<QNetworkInterfacePrivate *> interfaces; -
55 -
56 for (ifaddrs *ptr = rawList; ptr; ptr = ptr->ifa_next) {
evaluated: ptr
TRUEFALSE
yes
Evaluation Count:2119
yes
Evaluation Count:163
163-2119
57 if ( !ptr->ifa_addr )
partially evaluated: !ptr->ifa_addr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2119
0-2119
58 continue;
never executed: continue;
0
59 -
60 -
61 int ifindex = if_nametoindex(ptr->ifa_name); -
62 -
63 -
64 QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin(); -
65 for ( ; if_it != interfaces.end(); ++if_it)
evaluated: if_it != interfaces.end()
TRUEFALSE
yes
Evaluation Count:5542
yes
Evaluation Count:815
815-5542
66 if ((*if_it)->index == ifindex) {
evaluated: (*if_it)->index == ifindex
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:4238
1304-4238
67 -
68 if ( ptr->ifa_addr->sa_family == 17
partially evaluated: ptr->ifa_addr->sa_family == 17
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1304
0-1304
69 && (*if_it)->hardwareAddress.isEmpty()) {
never evaluated: (*if_it)->hardwareAddress.isEmpty()
0
70 sockaddr_ll *sll = (sockaddr_ll *)ptr->ifa_addr; -
71 (*if_it)->hardwareAddress = (*if_it)->makeHwAddress(sll->sll_halen, (uchar*)sll->sll_addr); -
72 }
never executed: }
0
73 break;
executed: break;
Execution Count:1304
1304
74 } -
75 if ( if_it != interfaces.end() )
evaluated: if_it != interfaces.end()
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:815
815-1304
76 continue;
executed: continue;
Execution Count:1304
1304
77 -
78 QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate; -
79 interfaces << iface; -
80 iface->index = ifindex; -
81 iface->name = QString::fromLatin1(ptr->ifa_name); -
82 iface->flags = convertFlags(ptr->ifa_flags); -
83 -
84 if ( ptr->ifa_addr->sa_family == 17 ) {
partially evaluated: ptr->ifa_addr->sa_family == 17
TRUEFALSE
yes
Evaluation Count:815
no
Evaluation Count:0
0-815
85 sockaddr_ll *sll = (sockaddr_ll *)ptr->ifa_addr; -
86 iface->hardwareAddress = iface->makeHwAddress(sll->sll_halen, (uchar*)sll->sll_addr); -
87 }
executed: }
Execution Count:815
815
88 }
executed: }
Execution Count:815
815
89 -
90 return interfaces;
executed: return interfaces;
Execution Count:163
163
91} -
92static QList<QNetworkInterfacePrivate *> interfaceListing() -
93{ -
94 QList<QNetworkInterfacePrivate *> interfaces; -
95 -
96 int socket; -
97 if ((socket = qt_safe_socket(2, SOCK_STREAM, IPPROTO_IP)) == -1)
partially evaluated: (socket = qt_safe_socket(2, SOCK_STREAM, IPPROTO_IP)) == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:163
0-163
98 return interfaces;
never executed: return interfaces;
0
99 -
100 ifaddrs *interfaceListing; -
101 if (getifaddrs(&interfaceListing) == -1) {
partially evaluated: getifaddrs(&interfaceListing) == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:163
0-163
102 -
103 ::close(socket); -
104 return interfaces;
never executed: return interfaces;
0
105 } -
106 -
107 interfaces = createInterfaces(interfaceListing); -
108 for (ifaddrs *ptr = interfaceListing; ptr; ptr = ptr->ifa_next) {
evaluated: ptr
TRUEFALSE
yes
Evaluation Count:2119
yes
Evaluation Count:163
163-2119
109 -
110 int ifindex = if_nametoindex(ptr->ifa_name); -
111 QNetworkInterfacePrivate *iface = 0; -
112 QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin(); -
113 for ( ; if_it != interfaces.end(); ++if_it)
partially evaluated: if_it != interfaces.end()
TRUEFALSE
yes
Evaluation Count:6357
no
Evaluation Count:0
0-6357
114 if ((*if_it)->index == ifindex) {
evaluated: (*if_it)->index == ifindex
TRUEFALSE
yes
Evaluation Count:2119
yes
Evaluation Count:4238
2119-4238
115 -
116 iface = *if_it; -
117 break;
executed: break;
Execution Count:2119
2119
118 } -
119 if (!iface) {
partially evaluated: !iface
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2119
0-2119
120 -
121 continue;
never executed: continue;
0
122 } -
123 -
124 QNetworkAddressEntry entry; -
125 entry.setIp(addressFromSockaddr(ptr->ifa_addr)); -
126 if (entry.ip().isNull())
evaluated: entry.ip().isNull()
TRUEFALSE
yes
Evaluation Count:815
yes
Evaluation Count:1304
815-1304
127 -
128 continue;
executed: continue;
Execution Count:815
815
129 -
130 entry.setNetmask(addressFromSockaddr(ptr->ifa_netmask)); -
131 if (iface->flags & QNetworkInterface::CanBroadcast)
evaluated: iface->flags & QNetworkInterface::CanBroadcast
TRUEFALSE
yes
Evaluation Count:978
yes
Evaluation Count:326
326-978
132 entry.setBroadcast(addressFromSockaddr(ptr->ifa_ifu.ifu_broadaddr));
executed: entry.setBroadcast(addressFromSockaddr(ptr->ifa_ifu.ifu_broadaddr));
Execution Count:978
978
133 -
134 iface->addressEntries << entry; -
135 }
executed: }
Execution Count:1304
1304
136 -
137 freeifaddrs(interfaceListing); -
138 ::close(socket); -
139 return interfaces;
executed: return interfaces;
Execution Count:163
163
140} -
141 -
142 -
143QList<QNetworkInterfacePrivate *> QNetworkInterfaceManager::scan() -
144{ -
145 return interfaceListing();
executed: return interfaceListing();
Execution Count:163
163
146} -
147 -
148 -
149 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial