Changeset View
Changeset View
Standalone View
Standalone View
Modules/nics/nic.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <QHBoxLayout> | 42 | #include <QHBoxLayout> | ||
43 | #include <QTreeWidget> | 43 | #include <QTreeWidget> | ||
44 | 44 | | |||
45 | #include <net/if.h> | 45 | #include <net/if.h> | ||
46 | #include <sys/ioctl.h> | 46 | #include <sys/ioctl.h> | ||
47 | #include <KPluginFactory> | 47 | #include <KPluginFactory> | ||
48 | #include <KPluginLoader> | 48 | #include <KPluginLoader> | ||
49 | 49 | | |||
50 | #ifndef HAVE_STRUCT_SOCKADDR_SA_LEN | | |||
51 | #undef HAVE_GETNAMEINFO | | |||
52 | #undef HAVE_GETIFADDRS | | |||
53 | #endif | | |||
54 | 50 | | |||
55 | #if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS) | 51 | #if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS) | ||
56 | #include <ifaddrs.h> | 52 | #include <ifaddrs.h> | ||
57 | #include <netdb.h> | 53 | #include <netdb.h> | ||
58 | 54 | | |||
59 | QString flags_tos (unsigned int flags); | 55 | QString flags_tos (unsigned int flags); | ||
60 | #endif | 56 | #endif | ||
61 | 57 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 124 | if (num.length() < 2) | |||
129 | num.prepend(QStringLiteral("0")); | 125 | num.prepend(QStringLiteral("0")); | ||
130 | if (i>0) | 126 | if (i>0) | ||
131 | ret.append(QStringLiteral(":")); | 127 | ret.append(QStringLiteral(":")); | ||
132 | ret.append(num); | 128 | ret.append(num); | ||
133 | } | 129 | } | ||
134 | return ret; | 130 | return ret; | ||
135 | } | 131 | } | ||
136 | 132 | | |||
133 | // Convenience wrapper around sa_len being available or not. | ||||
134 | static int getNameInfo(struct sockaddr *addr, struct ifaddrs *ifa, char *hostOut) | ||||
135 | { | ||||
136 | #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN | ||||
137 | return getnameinfo(addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST); | ||||
jjazeix: buf is not defined in this conditional and causes a build fail on freebsd: https://build.kde. | |||||
sitter: thanks. should be fixed
| |||||
138 | #else | ||||
139 | return getnameinfo(addr, | ||||
140 | (ifa->ifa_addr->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : | ||||
141 | sizeof(struct sockaddr_in6), | ||||
142 | hostOut, NI_MAXHOST, | ||||
143 | nullptr, 0, | ||||
144 | NI_NUMERICHOST); | ||||
145 | #endif | ||||
146 | } | ||||
147 | | ||||
137 | QList<MyNIC*> findNICs() { | 148 | QList<MyNIC*> findNICs() { | ||
138 | QString upMessage(i18nc("State of network card is connected", "Up") ); | 149 | QString upMessage(i18nc("State of network card is connected", "Up") ); | ||
139 | QString downMessage(i18nc("State of network card is disconnected", "Down") ); | 150 | QString downMessage(i18nc("State of network card is disconnected", "Down") ); | ||
140 | 151 | | |||
141 | QList<MyNIC*> nl; | 152 | QList<MyNIC*> nl; | ||
142 | 153 | | |||
143 | #if !defined(HAVE_GETIFADDRS) || !defined(HAVE_GETNAMEINFO) | 154 | #if !defined(HAVE_GETIFADDRS) || !defined(HAVE_GETNAMEINFO) | ||
144 | 155 | | |||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 249 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { | |||
240 | case AF_INET6: | 251 | case AF_INET6: | ||
241 | case AF_INET: { | 252 | case AF_INET: { | ||
242 | tmp = new MyNIC; | 253 | tmp = new MyNIC; | ||
243 | tmp->name = ifa->ifa_name; | 254 | tmp->name = ifa->ifa_name; | ||
244 | 255 | | |||
245 | char buf[128]; | 256 | char buf[128]; | ||
246 | 257 | | |||
247 | bzero(buf, 128); | 258 | bzero(buf, 128); | ||
248 | getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST); | 259 | getNameInfo(ifa->ifa_addr, ifa, buf); | ||
249 | tmp->addr = buf; | 260 | tmp->addr = buf; | ||
250 | 261 | | |||
251 | if (ifa->ifa_netmask != nullptr) { | 262 | if (ifa->ifa_netmask != nullptr) { | ||
252 | bzero(buf, 128); | 263 | bzero(buf, 128); | ||
253 | getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST); | 264 | getNameInfo(ifa->ifa_netmask, ifa, buf); | ||
254 | tmp->netmask = buf; | 265 | tmp->netmask = buf; | ||
255 | } | 266 | } | ||
256 | 267 | | |||
257 | tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage; | 268 | tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage; | ||
258 | tmp->type = flags_tos(ifa->ifa_flags); | 269 | tmp->type = flags_tos(ifa->ifa_flags); | ||
259 | 270 | | |||
260 | nl.append(tmp); | 271 | nl.append(tmp); | ||
261 | break; | 272 | break; | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |
buf is not defined in this conditional and causes a build fail on freebsd: https://build.kde.org/view/Failing/job/Plasma/job/kinfocenter/job/kf5-qt5%20FreeBSDQt5.13/lastFailedBuild/