LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 855|回复: 3

怎么会这样呢 ?

[复制链接]
发表于 2006-3-2 22:02:26 | 显示全部楼层 |阅读模式
想编个程序来直接添加一个iptables规则,但是怎么会这样呢?
[root@anuode anuode]# cat login.c
#include <unistd.h>

int main(int argc,char *argv[])
{
        char *arg[8]={"iptables","-A","FORWARD","-s",argv[1],"-j","ACCEPT",(char *)0};
        execve("/sbin/iptables",arg,(char **)0);
        arg[3]="-d";
        execve("/sbin/iptables",arg,(char **)0);
        return(0);
}
[root@anuode anuode]# ./login 10.10.10.1
[root@anuode anuode]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  10.10.10.1           anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
 楼主| 发表于 2006-3-2 22:16:54 | 显示全部楼层
难道是一个进程中只可以执行一次exec函数?
回复 支持 反对

使用道具 举报

发表于 2006-3-2 22:21:19 | 显示全部楼层
man execve:
  1. execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the  program  loaded.
复制代码
你可以先 fork 一个进程出来,然后在子进程里面用 execve
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-2 22:27:07 | 显示全部楼层
改好了,似乎真的是一个进程只能执行一次exec函数
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表