diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /kcontrol/nics | |
download | tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kcontrol/nics')
-rw-r--r-- | kcontrol/nics/AUTHORS | 2 | ||||
-rw-r--r-- | kcontrol/nics/Makefile.am | 15 | ||||
-rw-r--r-- | kcontrol/nics/configure.in.in | 4 | ||||
-rw-r--r-- | kcontrol/nics/nic.cpp | 323 | ||||
-rw-r--r-- | kcontrol/nics/nic.desktop | 173 | ||||
-rw-r--r-- | kcontrol/nics/nic.h | 45 |
6 files changed, 562 insertions, 0 deletions
diff --git a/kcontrol/nics/AUTHORS b/kcontrol/nics/AUTHORS new file mode 100644 index 000000000..2bda83486 --- /dev/null +++ b/kcontrol/nics/AUTHORS @@ -0,0 +1,2 @@ + Alexander Neundorf <[email protected]> + diff --git a/kcontrol/nics/Makefile.am b/kcontrol/nics/Makefile.am new file mode 100644 index 000000000..9cd225329 --- /dev/null +++ b/kcontrol/nics/Makefile.am @@ -0,0 +1,15 @@ +kde_module_LTLIBRARIES = kcm_nic.la + +kcm_nic_la_SOURCES = nic.cpp + +kcm_nic_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +kcm_nic_la_LIBADD = -lkdeui $(LIB_KIO) $(LIBSOCKET) + +AM_CPPFLAGS= $(all_includes) + +METASOURCES = AUTO + +messages: + $(XGETTEXT) $(kcm_nic_la_SOURCES) -o $(podir)/kcmnic.pot + +xdg_apps_DATA = nic.desktop diff --git a/kcontrol/nics/configure.in.in b/kcontrol/nics/configure.in.in new file mode 100644 index 000000000..e08832ebc --- /dev/null +++ b/kcontrol/nics/configure.in.in @@ -0,0 +1,4 @@ +AC_CHECK_FUNCS(getifaddrs getnameinfo) +AC_CHECK_MEMBERS([struct sockaddr.sa_len],,,[ +#include <sys/types.h> +#include <sys/socket.h>]) diff --git a/kcontrol/nics/nic.cpp b/kcontrol/nics/nic.cpp new file mode 100644 index 000000000..97bb9f42b --- /dev/null +++ b/kcontrol/nics/nic.cpp @@ -0,0 +1,323 @@ +/* + * nic.cpp + * + * Copyright (C) 2001 Alexander Neundorf <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/socket.h> +#include <config.h> +#ifdef HAVE_SYS_SOCKIO_H +#include <sys/sockio.h> +#endif + +#include <kaboutdata.h> +#include <kdialog.h> +#include <kgenericfactory.h> +#include <kglobal.h> + +#include <qlayout.h> +#include <qlistview.h> +#include <qpushbutton.h> +#include <qtabwidget.h> +#include <qtimer.h> + +#include "nic.h" + +#ifdef USE_SOLARIS +/* net/if.h is incompatible with STL on Solaris 2.6 - 2.8, redefine + map in the header file because we don't need it. -- Simon Josefsson */ +#define map junkmap +#endif +# include <net/if.h> +#ifdef USE_SOLARIS +#undef map +#endif + +#include <sys/ioctl.h> + +#ifndef HAVE_STRUCT_SOCKADDR_SA_LEN + #undef HAVE_GETNAMEINFO + #undef HAVE_GETIFADDRS +#endif + +#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS) + #include <ifaddrs.h> + #include <netdb.h> + + QString flags_tos (unsigned int flags); +#endif + +typedef KGenericFactory<KCMNic, QWidget> KCMNicFactory; +K_EXPORT_COMPONENT_FACTORY (kcm_nic, KCMNicFactory("kcmnic")) + +struct MyNIC +{ + QString name; + QString addr; + QString netmask; + QString state; + QString type; + QString HWaddr; +}; + +typedef QPtrList<MyNIC> NICList; + +NICList* findNICs(); + +KCMNic::KCMNic(QWidget *parent, const char * name, const QStringList &) + :KCModule(KCMNicFactory::instance(), parent,name) +{ + QVBoxLayout *box=new QVBoxLayout(this, 0, KDialog::spacingHint()); + m_list=new QListView(this); + box->addWidget(m_list); + m_list->addColumn(i18n("Name")); + m_list->addColumn(i18n("IP Address")); + m_list->addColumn(i18n("Network Mask")); + m_list->addColumn(i18n("Type")); + m_list->addColumn(i18n("State")); + m_list->addColumn(i18n("HWaddr")); + m_list->setAllColumnsShowFocus(true); + QHBoxLayout *hbox=new QHBoxLayout(box); + m_updateButton=new QPushButton(i18n("&Update"),this); + hbox->addWidget(m_updateButton); + hbox->addStretch(1); + QTimer* timer=new QTimer(this); + timer->start(60000); + connect(m_updateButton,SIGNAL(clicked()),this,SLOT(update())); + connect(timer,SIGNAL(timeout()),this,SLOT(update())); + update(); + KAboutData *about = + new KAboutData(I18N_NOOP("kcminfo"), + I18N_NOOP("KDE Panel System Information Control Module"), + 0, 0, KAboutData::License_GPL, + I18N_NOOP("(c) 2001 - 2002 Alexander Neundorf")); + + about->addAuthor("Alexander Neundorf", 0, "[email protected]"); + setAboutData( about ); + +} + +void KCMNic::update() +{ + m_list->clear(); + NICList *nics=findNICs(); + nics->setAutoDelete(true); + for (MyNIC* tmp=nics->first(); tmp!=0; tmp=nics->next()) + new QListViewItem(m_list,tmp->name, tmp->addr, tmp->netmask, tmp->type, tmp->state, tmp->HWaddr); + delete nics; +} + +static QString HWaddr2String( char *hwaddr ) +{ + QString ret; + int i; + for (i=0; i<6; i++, hwaddr++) { + int v = (*hwaddr & 0xff); + QString num = QString("%1").arg(v,0,16); + if (num.length() < 2) + num.prepend("0"); + if (i>0) + ret.append(":"); + ret.append(num); + } + return ret; +} + +NICList* findNICs() +{ + QString upMessage( i18n("State of network card is connected", "Up") ); + QString downMessage( i18n("State of network card is disconnected", "Down") ); + + NICList* nl=new NICList; + nl->setAutoDelete(true); + +#if !defined(HAVE_GETIFADDRS) || !defined(HAVE_GETNAMEINFO) + + 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; +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN + int len = sizeof(struct sockaddr); + if (ifr->ifr_addr.sa_len > len) + len = ifr->ifr_addr.sa_len; /* length > 16 */ + ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ +#else + ptr += sizeof(*ifr); /* for next one in buffer */ +#endif + + 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; + tmp->state= ((flags & IFF_UP) == IFF_UP) ? upMessage : downMessage; + + if ((flags & IFF_BROADCAST) == IFF_BROADCAST) + tmp->type=i18n("Broadcast"); + else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) + tmp->type=i18n("Point to Point"); +#ifndef _AIX + else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) + tmp->type=i18n("Multicast"); +#endif + 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"); + + ifcopy=*ifr; + result=-1; // if none of the two #ifs below matches, ensure that result!=0 so that "Unknown" is returned as result +#ifdef SIOCGIFHWADDR + result=ioctl(sockfd,SIOCGIFHWADDR,&ifcopy); + if (result==0) + { + char *n = &ifcopy.ifr_ifru.ifru_hwaddr.sa_data[0]; + tmp->HWaddr = HWaddr2String(n); + } +#elif defined SIOCGENADDR + result=ioctl(sockfd,SIOCGENADDR,&ifcopy); + if (result==0) + { + char *n = &ifcopy.ifr_ifru.ifru_enaddr[0]; + tmp->HWaddr = HWaddr2String(n); + } +#endif + if (result!=0) + { + tmp->HWaddr = i18n("Unknown"); + } + + nl->append(tmp); + break; + + default: + break; + } + } +#else + 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) { + bzero(buf, 128); + getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST); + tmp->netmask = buf; + } + + tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage; + tmp->type = flags_tos(ifa->ifa_flags); + + nl->append(tmp); + break; + } + default: + break; + } + } + + freeifaddrs(ifap); +#endif + return nl; +} + + +#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS) +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; +} +#endif + +#include "nic.moc" diff --git a/kcontrol/nics/nic.desktop b/kcontrol/nics/nic.desktop new file mode 100644 index 000000000..cddf242f6 --- /dev/null +++ b/kcontrol/nics/nic.desktop @@ -0,0 +1,173 @@ +[Desktop Entry] +Exec=kcmshell nic +Type=Application +DocPath=kinfocenter/nics/index.html +Icon=network + + +X-KDE-Library=nic +X-KDE-FactoryName=nic +X-KDE-ParentApp=kinfocenter + +Name=Network Interfaces +Name[af]=Netwerk Koppelvlakke +Name[ar]=واجهات الشبكة +Name[az]=Şəbəkə Ara Üzləri +Name[be]=Сеткавыя інтэрфейсы +Name[bg]=Мрежа +Name[bn]=নেটওয়ার্ক ইন্টারফেস +Name[br]=Etrefasoù Rouedad +Name[bs]=Mrežni interfejsi +Name[ca]=Interfícies de xarxa +Name[cs]=Síťová rozhraní +Name[csb]=Sécowé interfejsë +Name[cy]=Rhyngwynebau Rhwydwaith +Name[da]=Netværksgrænseflade +Name[de]=Netzwerkschnittstellen +Name[el]=Δικτυακές διασυνδέσεις +Name[eo]=Retinterfacoj +Name[es]=Interfaces de red +Name[et]=Võrguliidesed +Name[eu]=Sare interfazeak +Name[fa]=واسطهای شبکه +Name[fi]=Verkkoliitynnät +Name[fr]=Interfaces réseau +Name[fy]=Netwurkynterfaces +Name[ga]=Comhéadain Líonra +Name[gl]=Interfaces de Rede +Name[he]=ממשקי רשת +Name[hi]=नेटवर्क इंटरफेसेस +Name[hr]=Mrežna sučelja +Name[hu]=Hálózati kártyák +Name[is]=Netkort +Name[it]=Interfacce di rete +Name[ja]=ネットワークインターフェース +Name[ka]=ქსელური ინტერფეისები +Name[kk]=Желі интерфейстері +Name[km]=ចំណុចប្រទាក់បណ្ដាញ +Name[ko]=네트워크 인터페이스 +Name[lo]=ແຜງວົງຈອນເຄືອຂ່າຍ +Name[lt]=Tinklo sąsajos +Name[lv]=Tīkla iekārtas +Name[mk]=Мрежни интерфејси +Name[mn]=Сүлжээ-харьцах хэсэг +Name[ms]=Antara Muka Rangkaian +Name[mt]=Interfaċċja tan-network +Name[nb]=Nettverksgrensesnitt +Name[nds]=Nettwark-Koppelsteden +Name[ne]=सञ्जाल इन्टरफेस +Name[nl]=Netwerkinterfaces +Name[nn]=Nettverksgrensesnitt +Name[nso]=Difahlego tsa Kgokagano +Name[pa]=ਨੈਟਵਰਕ ਇੰਟਰਫੇਸ +Name[pl]=Interfejsy sieciowe +Name[pt]=Interfaces de Rede +Name[pt_BR]=Interfaces de Rede +Name[ro]=Interfețe de rețea +Name[ru]=Сетевые интерфейсы +Name[rw]=Imigaragarire y'Urusobemiyoboro +Name[se]=Fierbmelavttat +Name[sk]=Sieťové rozhrania +Name[sl]=Omrežni vmesniki +Name[sr]=Мрежни интерфејси +Name[sr@Latn]=Mrežni interfejsi +Name[ss]=Sichumanisi seluchungechunge +Name[sv]=Nätverksgränssnitt +Name[ta]=வலைதள இடைமுகங்கள் +Name[te]=నెట్వర్క్ ఇంటర్ ఫెస్ +Name[tg]=Воситаҳои шабака +Name[th]=แผงวงจรเครือข่าย +Name[tr]=Ağ Arayüzleri +Name[tt]=Çeltär Yözaraları +Name[uk]=Мережеві інтерфейси +Name[uz]=Tarmoq interfeyslari +Name[uz@cyrillic]=Тармоқ интерфейслари +Name[ven]=Vhukwamani ha tshifhatuwo +Name[vi]=Giao diện Mạng +Name[wa]=Eterfaces rantoele +Name[xh]=Ujongano Lomsebenzi womnatha +Name[zh_CN]=网络接口 +Name[zh_TW]=網路界面 +Name[zu]=Abaxhumanisi boxhumano olusakazekile + +Comment=Network interface information +Comment[af]=Netwerk koppelvlak informasie +Comment[ar]=معلومات حول واجهة الشبكة +Comment[az]=Şəbəkə ara üzü mə'lumatı +Comment[be]=Інфармацыя аб сеткавых інтэрфейсах +Comment[bg]=Информация за мрежовите интерфейси +Comment[bn]=নেটওয়ার্ক ইন্টারফেস সংক্রান্ত তথ্য +Comment[br]=Titouroù diwar-benn an etrefasoù rouedad +Comment[bs]=Informacije o mrežnom interfejsu +Comment[ca]=Informació de la interfície de xarxa +Comment[cs]=Informace o síťových rozhraních +Comment[csb]=Wëdowiédzô ò sécowim interfejse +Comment[cy]=Gwybodaeth rhyngwynebau rhwydwaith +Comment[da]=Information om netværksgrænseflade +Comment[de]=Informationen über die Netzwerkanschlüsse +Comment[el]=Πληροφορίες δικτυακής διασύνδεσης +Comment[eo]=Informo pri retinterfaco +Comment[es]=Información sobre la interfaz de red +Comment[et]=Võrguliideste info +Comment[eu]=Sare interfazeari buruzko informazioa +Comment[fa]=اطلاعات واسط شبکه +Comment[fi]=Verkkoliityntöjen tiedot +Comment[fr]=Informations sur l'interface réseau +Comment[fy]=Netwurkynterface-ynformaasje +Comment[ga]=Eolas faoin gcomhéadan gréasáin +Comment[gl]=Información da interface de rede +Comment[he]=מידע על ממשקי רשת +Comment[hi]=नेटवर्क इंटरफेस जानकारी +Comment[hr]=Podaci o mrežnom sučelju +Comment[hu]=A hálózati kártyák jellemzői +Comment[is]=Upplýsingar um Netkort +Comment[it]=Informazioni sulle interfacce di rete +Comment[ja]=ネットワークインターフェースの情報 +Comment[ka]=ცნობები ქსელური ინტერფეისების შესახებ +Comment[kk]=Желі интерфейсінің мәліметі +Comment[km]=ព័ត៌មានចំណុចប្រទាក់បណ្ដាញ +Comment[ko]=네트워크 인터페이스 정보 +Comment[lo]=ຂໍ້ມູນລະບົບເຄືອຂ່າຍ +Comment[lt]=Tinklo sąsajos informacija +Comment[lv]=Tīkla iekārtu informācija +Comment[mk]=Информации за мрежните интерфејси +Comment[mn]=Сүлжээний холболтын мэдээлэл +Comment[ms]=Maklumat antara muka rangkaian +Comment[mt]=Informazzjoni dwar interfaċċji tan-network +Comment[nb]=Informasjon om nettverksgrensesnitt +Comment[nds]=Informatschoon över de Nettwark-Koppelsteden +Comment[ne]=सञ्जाल इन्टरफेस सूचना +Comment[nl]=Netwerkinterface-informatie +Comment[nn]=Informasjon om nettverksgrensesnitt +Comment[nso]=Tshedimoso ya Difahlego tsa Kgokagano +Comment[pa]=ਨੈੱਟਵਰਕ ਇੰਟਰਫੇਸ ਜਾਣਕਾਰੀ +Comment[pl]=Informacje o interfejsie sieciowym +Comment[pt]=Informações sobre as interfaces de rede +Comment[pt_BR]=Informações sobre rede +Comment[ro]=Afișează informații despre interfețele de rețea +Comment[ru]=Сведения о сетевых интерфейсах +Comment[rw]=Ibisobanuro by'imigaragarire y'urusobemiyoboro +Comment[se]=Fierbmalaktadiehtu +Comment[sk]=Informácie o sieťových rozhraniach +Comment[sl]=Podatki o omrežnih vmesnikih +Comment[sr]=Информације о мрежним интерфејсима +Comment[sr@Latn]=Informacije o mrežnim interfejsima +Comment[sv]=Information om nätverksgränssnitt +Comment[ta]=வலைதள இடைமுகத் தகவல் +Comment[te]=నెట్వర్క్ ఇంటర్ ఫెస్ సమాచారం +Comment[tg]=Иттилооти шабака +Comment[th]=ข้อมูลแผงวงจรเครือข่าย +Comment[tr]=Ağ arayüz bilgisi +Comment[tt]=Çeltär yözaraları turında +Comment[uk]=Інформація щодо інтерфейсів мережі +Comment[uz]=Tarmoq interfeyslari haqida maʼlumot +Comment[uz@cyrillic]=Тармоқ интерфейслари ҳақида маълумот +Comment[ven]=Mafhungo a vhukwamani +Comment[vi]=Thông tin giao diện mạng +Comment[wa]=Informåcion so l' eterface rantoele +Comment[xh]=Ulwazi lojongano lomsebenzi womnatha +Comment[zh_CN]=网络接口信息 +Comment[zh_TW]=網路界面資訊 +Comment[zu]=Ulwazi lomxhumanisi woxhumano olusakazekile + +Categories=Qt;KDE;X-KDE-information; diff --git a/kcontrol/nics/nic.h b/kcontrol/nics/nic.h new file mode 100644 index 000000000..c7711701a --- /dev/null +++ b/kcontrol/nics/nic.h @@ -0,0 +1,45 @@ +/* + * nic.h + * + * Copyright (C) 2001 Alexander Neundorf <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KCONTROL_NIC_H +#define KCONTROL_NIC_H + +#include <kcmodule.h> + +class QStringList; +class QPushButton; +class QListView; + +class KCMNic:public KCModule +{ + Q_OBJECT + public: + KCMNic(QWidget *parent=0, const char * name=0, const QStringList &list = QStringList( )); + + protected slots: + void update(); + + protected: + QListView *m_list; + QPushButton *m_updateButton; +}; + +#endif + |