openbsd-ports/x11/kde/base3/patches/patch-kcontrol_nics_nic_cpp
espie a4d2f30a9a kdebase 3.1:
- use kcontrol/nics/nic.cpp from kde-current to access getifaddrs...
IPv4 masks are not printed properly yet.
- konsole fixes for utmp
- ksysguardd mostly working. Should unify with Net/FreeBSD
- clock and timezone fixes mostly from Flinn Mueller.
- uses kxkb_pic lib, thanks to Matthieu.
2003-01-27 19:22:49 +00:00

173 lines
4.3 KiB
Plaintext

$OpenBSD: patch-kcontrol_nics_nic_cpp,v 1.2 2003/01/27 19:22:50 espie Exp $
--- kcontrol/nics/nic.cpp.orig Thu Dec 5 21:40:07 2002
+++ kcontrol/nics/nic.cpp Sat Jan 11 05:48:40 2003
@@ -37,6 +37,7 @@
#endif
#include <sys/types.h>
+#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
@@ -55,6 +56,11 @@
#include <sys/ioctl.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+
+QString flags_tos (unsigned int flags);
+
typedef KGenericFactory<KCMNic, QWidget > KCMNicFactory;
K_EXPORT_COMPONENT_FACTORY (kcm_nic, KCMNicFactory("kcmnic") );
@@ -127,76 +133,81 @@ NICList* findNICs()
NICList* nl=new NICList;
nl->setAutoDelete(true);
- int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
-
- char buf[8*1024];
- struct ifconf ifc;
- ifc.ifc_len = sizeof(buf);
- ifc.ifc_req = (struct ifreq *) buf;
- int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
-
- for (char* ptr = buf; ptr < buf + ifc.ifc_len; )
- {
- struct ifreq *ifr =(struct ifreq *) ptr;
- int len = sizeof(struct sockaddr);
-#ifdef HAVE_SOCKADDR_SA_LEN
- if (ifr->ifr_addr.sa_len > len)
- len = ifr->ifr_addr.sa_len; /* length > 16 */
-#endif
- ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
+ struct ifaddrs *ifap, *ifa;
+ if (getifaddrs(&ifap) != 0) {
+ return nl;
+ }
+
+ MyNIC *tmp=0;
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ switch (ifa->ifa_addr->sa_family) {
+ case AF_INET6:
+ case AF_INET: {
+ tmp = new MyNIC;
+ tmp->name = ifa->ifa_name;
+
+ char buf[128];
+
+ bzero(buf, 128);
+ getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
+ tmp->addr = buf;
+
+ if (ifa->ifa_netmask != NULL) {
+ if (ifa->ifa_netmask->sa_family == 0)
+ ifa->ifa_netmask->sa_family = AF_INET;
+ bzero(buf, 128);
+ int result = getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
+ tmp->netmask = buf;
+ }
- int flags;
- struct sockaddr_in *sinptr;
- MyNIC *tmp=0;
- switch (ifr->ifr_addr.sa_family)
- {
- case AF_INET:
- sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
- flags=0;
-
- struct ifreq ifcopy;
- ifcopy=*ifr;
- result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
- flags=ifcopy.ifr_flags;
-
- tmp=new MyNIC;
- tmp->name=ifr->ifr_name;
- if ((flags & IFF_UP) == IFF_UP)
- tmp->state=i18n("Up");
- else
- tmp->state=i18n("Down");
-
- if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
- tmp->type=i18n("Broadcast");
- else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
- tmp->type=i18n("Point to Point");
- else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
- tmp->type=i18n("Multicast");
- else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
- tmp->type=i18n("Loopback");
- else
- tmp->type=i18n("Unknown");
-
- tmp->addr=inet_ntoa(sinptr->sin_addr);
-
- ifcopy=*ifr;
- result=ioctl(sockfd,SIOCGIFNETMASK,&ifcopy);
- if (result==0)
- {
- sinptr = (struct sockaddr_in *) &ifcopy.ifr_addr;
- tmp->netmask=inet_ntoa(sinptr->sin_addr);
- }
- else
- tmp->netmask=i18n("Unknown");
- nl->append(tmp);
- break;
+ if (ifa->ifa_flags & IFF_UP)
+ tmp->state=i18n("Up");
+ else
+ tmp->state=i18n("Down");
+
+ tmp->type = flags_tos(ifa->ifa_flags);
+
+ nl->append(tmp);
+ break;
+ }
+ default:
+ break;
+ }
+ }
- default:
- break;
- }
- }
+ freeifaddrs(ifap);
return nl;
};
-#include "nic.moc"
+QString flags_tos (unsigned int flags)
+{
+ QString tmp;
+ if (flags & IFF_POINTOPOINT) {
+ tmp += i18n("Point to Point");
+ }
+
+ if (flags & IFF_BROADCAST) {
+ if (tmp.length()) {
+ tmp += QString::fromLatin1(", ");
+ }
+ tmp += i18n("Broadcast");
+ }
+
+ if (flags & IFF_MULTICAST) {
+ if (tmp.length()) {
+ tmp += QString::fromLatin1(", ");
+ }
+ tmp += i18n("Multicast");
+ }
+
+ if (flags & IFF_LOOPBACK) {
+ if (tmp.length()) {
+ tmp += QString::fromLatin1(", ");
+ }
+ tmp += i18n("Loopback");
+ }
+ return tmp;
+}
+
+#include "nic.moc"