惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
Jina AI
Jina AI
雷峰网
雷峰网
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
美团技术团队
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - Franky
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
量子位
IT之家
IT之家
人人都是产品经理
人人都是产品经理
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 三胖他爹

VC CUtilityLZW 效率还行的LZW压缩算法,随机数加密 VC CQHashNTBuffer 牛逼的Hash表 UINT32 VC CHashBuffer 牛逼的hash表算法,字符串查找块了100倍 关闭Fedora防火墙 gnome 屏幕截图 zynq -- arm-xilinx-eabi-路径 Fedora 14安装出现的错误 fedora19安装后,需要安装的一些必备的软件包 zynq -- cannot find -lxil Zynq -- 启动过程 OTG: On-The-Go Zynq --- SDK - Cannot compile ARM application on Windows 7 64-bit or Linux 64-bit OS MarshalHelper iec61850采样协议(9-1、9-2)解析(二) 找不到/dev/input/event的原因 iec61850采样协议(9-1、9-2)解析(一) C语言项目常用的头文件声明及相关宏定义 TTY头文件注释 设置和取得串口参数
程序调用shell设置ip地址
三胖他爹 · 2013-04-19 · via 博客园 - 三胖他爹

通过脚本设置ip地址和网关:

 1 std::string setip = "ifconfig eth0 " +lineEdit_NetIp->text().toStdString() + " netmask " + lineEdit_NetMask->text().toStdString() + " && echo 1";
 2     std::string setroute = "echo 1;route del default;route add default gw " + ui->lineEdit_NetGate->text().toStdString();
 3     FILE *fp = popen(setip.c_str(), "r");
 4     if (NULL == fp)
 5     {
 6         msgBox.setInformativeText(tr("The IP address is unusable!"));
 7         msgBox.exec();
 8         return;
 9     }
10     char getway[16] = {0};
11     if (NULL == fgets(getway, 16, fp))
12     {
13         pclose(fp);
14         msgBox.setInformativeText(tr("The IP address is unusable!"));
15         msgBox.exec();
16         return;
17     }
18     if (getway[0] != '1')
19     {
20         msgBox.setInformativeText(tr("The IP address is unusable!"));
21         msgBox.exec();
22         return;
23     }    
24     pclose(fp);
25     fp = NULL;
 1 fp = popen(setroute.c_str(), "r");
 2     if (NULL == fp)
 3     {
 4         msgBox.setInformativeText(tr("The route address is unusable!"));
 5        msgBox.exec();
 6         exit(0);
 7    }
 8 
 9    char route[16] = {0};
10 
11    if (NULL == fgets(route, 16, fp))
12    {
13         pclose(fp);
14         msgBox.setInformativeText(tr("The route address is unusable!"));
15         msgBox.exec();
16         exit(0);
17    }
18     pclose(fp);
19 
20     if (route[1] != 0)
21    {
22        msgBox.setInformativeText(tr("The route address is unusable!"));
23         msgBox.exec();
24         exit(0);
25     }