void read_interface_file()
{
QFile readFile("/etc/network/interfaces");
QString strAll;
if(readFile.open((QIODevice::ReadOnly|QIODevice::Text)))
{
QTextStream stream(&readFile);
strAll=stream.readAll();
}
readFile.close();
QStringList strList;
strList=strAll.split("\n");
int eth_index = -1;
for(int i=0;i
if(strList.at(i) == "iface eth0 inet static")
{
eth_index = 0;
}
else if(strList.at(i) == "iface eth1 inet static")
{
eth_index = 1;
}
else if(strList.at(i).contains("iface eth"))
{
eth_index = -1;
}
else if(strList.at(i).contains("address"))
{
if(eth_index==0)
{
ip0 = strList.at(i);
}
else if(eth_index==1)
{
ip1 = strList.at(i);
}
}
else if(strList.at(i).contains("netmask"))
{
if(eth_index==0)
{
mask0 = strList.at(i);
}
else if(eth_index==1)
{
mask1 = strList.at(i);
}
}
else if(strList.at(i).contains("gateway"))
{
if(eth_index==0)
{
gate0 = strList.at(i);
}
else if(eth_index==1)
{
gate1 = strList.at(i);
}
}
}
ip0 = ip0.mid(ip0.indexOf(" ")).replace(" ","");
mask0 = mask0.mid(mask0.indexOf(" ")).replace(" ","");
gate0 = gate0.mid(gate0.indexOf(" ")).replace(" ","");
ip1 = ip1.mid(ip1.indexOf(" ")).replace(" ","");
mask1 = mask1.mid(mask1.indexOf(" ")).replace(" ","");
gate1 = gate1.mid(gate1.indexOf(" ")).replace(" ","");
qDebug()<<"ip0:"<
void write_interface()
{
QString strAll;
QStringList strList;
QFile readFile("/etc/network/interfaces");
if(readFile.open((QIODevice::ReadOnly|QIODevice::Text)))
{
QTextStream stream(&readFile);
strAll=stream.readAll();
}
readFile.close();
QFile writeFile("/etc/network/interfaces");
QString ip;
QString mask;
QString gateway;
if(writeFile.open(QIODevice::WriteOnly))
{
QTextStream stream(&writeFile);
strList=strAll.split("\n");
qDebug()<<"strList size = "<
if(i==strList.count()-1)
{
stream<
else
{
stream<
if(strList.at(i).contains("iface eth0 inet static"))
{
ip.sprintf("address %d.%d.%d.%d",(eth0_ownIpAddr >> 24) & 0xff, (eth0_ownIpAddr >> 16) & 0xff,
(eth0_ownIpAddr >> 8) & 0xff, eth0_ownIpAddr & 0xff);
mask.sprintf("netmask %d.%d.%d.%d",(eth0_SubNetMask >> 24) & 0xff, (eth0_SubNetMask >> 16) & 0xff,
(eth0_SubNetMask >> 8) & 0xff, eth0_SubNetMask & 0xff);
gateway.sprintf("gateway %d.%d.%d.%d",(eth0_GateWay >> 24) & 0xff, (eth0_GateWay >> 16) & 0xff,
(eth0_GateWay >> 8) & 0xff, eth0_GateWay & 0xff);
qDebug()<<"eth0 ip = "<
tempStr.replace(0,tempStr.length(),ip);
qDebug()<<"eth0 ip = "<
stream<
tempStr.replace(0,tempStr.length(),mask);
qDebug()<<"eth0 mask = "<
tempStr.replace(0,tempStr.length(),"network 192.168.0.12");
stream<
tempStr.replace(0,tempStr.length(),gateway);
qDebug()<<"eth0 gateway = "<
}
ip.clear();
mask.clear();
gateway.clear();
if(strList.at(i).contains("iface eth1 inet static"))
{
ip.sprintf("address %d.%d.%d.%d",(eth1_ownIpAddr >> 24) & 0xff, (eth1_ownIpAddr >> 16) & 0xff,
(eth1_ownIpAddr >> 8) & 0xff, eth1_ownIpAddr & 0xff);
mask.sprintf("netmask %d.%d.%d.%d",(eth1_SubNetMask >> 24) & 0xff, (eth1_SubNetMask >> 16) & 0xff,
(eth1_SubNetMask >> 8) & 0xff, eth1_SubNetMask & 0xff);
gateway.sprintf("gateway %d.%d.%d.%d",(eth1_GateWay >> 24) & 0xff, (eth1_GateWay >> 16) & 0xff,
(eth1_GateWay >> 8) & 0xff, eth1_GateWay & 0xff);
qDebug()<<"eth1 ip = "<
QString tempStr=strList.at(i+1);
tempStr.replace(0,tempStr.length(),ip);
qDebug()<<"eth1 ip = "<
stream<
tempStr.replace(0,tempStr.length(),mask);
qDebug()<<"eth1 mask = "<
tempStr.replace(0,tempStr.length(),"network 192.168.0.12");
stream<
tempStr.replace(0,tempStr.length(),gateway);
qDebug()<<"eth1 gateway = "<
}
ip.clear();
mask.clear();
gateway.clear();
if(strList.at(i).contains("iface eth2 inet static"))
{
UINT32 eth2_ip = vos_dottedIP(ip_eth2);
eth2_ip = htonl(eth2_ip);
UINT32 eth2_mask = vos_dottedIP(sub_net_mask_eth2);
eth2_mask = htonl(eth2_mask);
UINT32 eth2_gate = vos_dottedIP(gate_way_eth2);
eth2_gate = htonl(eth2_gate);
ip.sprintf("address %d.%d.%d.%d",(eth2_ip >> 24) & 0xff, (eth2_ip >> 16) & 0xff,
(eth2_ip >> 8) & 0xff, eth2_ip & 0xff);
mask.sprintf("netmask %d.%d.%d.%d",(eth2_mask >> 24) & 0xff, (eth2_mask >> 16) & 0xff,
(eth2_mask >> 8) & 0xff, eth2_mask & 0xff);
gateway.sprintf("gateway %d.%d.%d.%d",(eth2_gate >> 24) & 0xff, (eth2_gate >> 16) & 0xff,
(eth2_gate >> 8) & 0xff, eth2_gate & 0xff);
QString tempStr=strList.at(i+1);
tempStr.replace(0,tempStr.length(),ip);
stream<
tempStr.replace(0,tempStr.length(),mask);
stream<
tempStr.replace(0,tempStr.length(),"network 192.168.0.11");
stream<
tempStr.replace(0,tempStr.length(),gateway);
stream<
}
}
}
}