在linux下 获取,修改网关GateWay的两个函数
//获去GateWay
QString GetGateWay()
{
FILE *fp;
char buf[512];
char cmd[128];
char gateway[30];
char *tmp;
strcpy(cmd, "ip route");
fp = popen(cmd, "r");
if(NULL == fp)
{
perror("popen error");
return "";
}
while(fgets(buf, sizeof(buf), fp) != NULL)
{
tmp =buf;
while(*tmp && isspace(*tmp))
++ tmp;
if(strncmp(tmp, "default", strlen("default")) == 0)
break;
}
sscanf(buf, "%*s%*s%s", gateway);
printf("default gateway:%s\n", gateway);
pclose(fp);
return QString(gateway);
}
//设置网关
int SetGateWay(const char *szGateWay)
{
int ret = 0;
char cmd[128];
QString DefGW = GetGateWay();
const char *strGW = DefGW.latin1();
strcpy(cmd, "route del default gw ");
strcat(cmd, strGW);
ret = system(cmd);
if(ret < 0)
{
perror("route error");
return -1;
}
strcpy(cmd, "route add default gw ");
strcat(cmd, szGateWay);
ret = system(cmd);
if(ret < 0)
{
perror("route error");
return -1;
}
return ret;
}
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
今天的一个很重要的收获
一个致命的命令 sudo chmod -R a+rwx * 是在当前文件夹下面的所有文件和文件夹都是可读 可写 可执行
以前安装phpcms在ubuntu下的时候 都是失败而告终的 今天终于成功 了
就是这个命令救了我 ......
管道:当从一个进程连接数据流到另一个进程时,使用术语管道(pipe)。
#i nclude <unistd.h>
int pipe(int filedes[2]); //创建管道
pipe()说明:
返回值:0成功,-1出错。
如果调用成功,则进程此时由了两个额外的打开文件描述符,filedes[0]中的值是管道的读取端,而filedes[1]是管道的写入端。
#include&l ......
ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件。
当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 ......
Vim和所有的流行文本编辑器一样,可以很好的编辑各种字符编码的文件,这当然包括 UCS-2、UTF-8 等流行的 Unicode 编码方式。而且和很多来自 Linux 世界的软件一样,这需要你自己动手设置。
Vim 有四个跟字符编码方式有关的选项,encoding 、fileencoding 、fileencodings 、termencoding (这些选项可能的取值请参考 Vim 在 ......