在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;
}
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
Kscope是Linux下的一款类似于SourceInsight工具,下面将其安装过程总结如下:
1.先下载kscope
kscope最新安装版本kscope-1.6.2.tar.gz
http://download.chinaunix.net/download/0006000/5469.shtml
按照说明#./configure
#make
&nb ......
管道:当从一个进程连接数据流到另一个进程时,使用术语管道(pipe)。
#i nclude <unistd.h>
int pipe(int filedes[2]); //创建管道
pipe()说明:
返回值:0成功,-1出错。
如果调用成功,则进程此时由了两个额外的打开文件描述符,filedes[0]中的值是管道的读取端,而filedes[1]是管道的写入端。
#include&l ......
dup和dup2也是两个非常有用的调用,它们的作用都是用来复制一个文件的描述符。它们经常用来重定向进程的stdin、stdout和stderr。这两个函数的 原形如下:
#include <unistd.h>
int dup( int oldfd );
int dup2( int oldfd, int targetfd )
利用函数dup,我们可以复制一个描述符。传给 ......
1.将 arm-linux-gcc 的压缩包解压到tmp目录下
2.将 tmp/usr/local 下的 arm 目录copy 到系统的/usr/local 下
3.执行命令:vi/etc/profile 在path murge的语句断后添加
pathmurge/usr/local/arm/2.95.3/bin;
4.按ESC键,输入:wq 保存并退出.
5.执行 source /etc/profile
6.建立工作目录mkdir -p/opt/Fr ......