在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;
}
相关文档:
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
最近一直在忙项目,做的过程中遇到一个很纠结的事情。需要用shell脚本轮训数据库,数据执行完毕以后才能调用其他的shell脚本。在这里总结一下,与大家共享。
脚本如下:
shell 脚本如下:
#!/bin/sh
SQL_DIR=/home/tang/tek/sql/tek
SHELL_DIR=/home/tang/tek/sh/tek
LOG_DIR=/home/tang/tek/logs
. /home/tang/.bas ......
/*
* linux/kernel/floppy.c
*
* (C) 1991 Linus Torvalds
*/
/*
* 02.12.91 - Changed to static variables to indicate need for reset
* and recalibrate. This makes some things easier (output_byte reset
* checking etc), and means less i ......
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 ......