123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "netinterfaces.h"
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- NetInterfaces::NetInterfaces(QObject *pParent) : QObject(pParent)
- {
- setObjectName("NetInterfaces");
- }
- NetInterfaces::~NetInterfaces(void)
- {
- reset();
- }
- void NetInterfaces::classBegin()
- {
- }
- void NetInterfaces::componentComplete()
- {
- }
- void NetInterfaces::reset(void)
- {
- for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
- {
- Interface *pi = *it;
- delete pi;
- }
- m_itfList.clear();
- m_eni._reset();
- }
- bool NetInterfaces::initialize(void)
- {
- bool bRet = false;
- reset();
- if((bRet = ::ParseEtcNetworkInterfaces(m_eni)))
- {
- for(auto it = m_eni.ibl.begin(); it != m_eni.ibl.end(); it++)
- {
- ITF_IFACE_BLOCK &ibl = *it;
- m_itfList.push_back(new Interface(ibl));
- }
- }
- return bRet;
- }
- QVariantList NetInterfaces::getInterface(const QString &itfName)
- {
- QVariantList list;
- list.clear();
- if(m_eni.ibl.size() > 0)
- {
- for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
- {
- Interface *pi = *it;
- const ITF_IFACE_BLOCK &ibl = pi->getIface();
- if( itfName == ibl.cfgName.c_str() &&
- ibl.proto == IFP_Inet &&
- (ibl.method == IFM_Static || ibl.method == IFM_Dhcp))
- {
- QVariant var = QVariant::fromValue(pi);
- list.append(var);
- }
- }
- }
- return list;
- }
- /////////////////////////////////////////////////////////////////////////////
- Interface::Interface(ITF_IFACE_BLOCK &ifb, QObject *pParent) : QObject(pParent), m_ifb(ifb)
- {
- setObjectName("Interface");
- }
- Interface::~Interface(void)
- {
- }
- QString Interface::name(void) const
- {
- return QString::fromStdString(m_ifb.cfgName);
- }
- QString Interface::ipAddress(void) const
- {
- if(m_ifb.proto == IFP_Inet && m_ifb.method == IFM_Static)
- return inet_ntoa(m_ifb.inet4s.addr);
- else
- return "";
- }
- QString Interface::family(void) const
- {
- return ::GetIfaceProtoStr(m_ifb.proto);
- }
- QString Interface::method(void) const
- {
- return ::GetIfaceMethodStr(m_ifb.method);
- }
|