荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: jjk (UNIX+C+XML+?? 傻了?), 信区: Linux
标  题: Delete ipchains input rules(转寄)[转载]
发信站: 荔园晨风BBS站 (Wed Apr 24 18:09:50 2002), 转信

【 以下文字转载自 jjk 的信箱 】
【 原文由 jjk.bbs@apue.dhs.org 所发表 】
发信人: lgx (lgx), 信区: CompSci
标  题: Delete ipchains input rules
发信站: UNIX编程 (2002年04月12日14:04:22 星期五), 站内信件

//int del_ipchains_input(int num) 删除 num 个ipchains input规则
//成功返回 0。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/types.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#include <linux/if.h>
#include <linux/netfilter_ipv4/ipchains_core.h>
/* num 必需为 1 */
int  del_ipchains_input(int num)
{
    int s,r;
    struct ip_fwdelnum fwd;

    if ((s = socket(PF_INET,SOCK_RAW,IPPROTO_RAW)) < 0) {
        return -1;
    }

    fwd.fwd_rulenum = num;
    strcpy(fwd.fwd_label,IP_FW_LABEL_INPUT);
    r = setsockopt(s,SOL_IP,IP_FW_DELETE_NUM,&fwd,16);

    close(s);
    return r;
}
0x8049ef4:      push   %ebp
0x8049ef5:      mov    %esp,%ebp
0x8049ef7:      sub    $0x24,%esp
0x8049efa:      push   %ebx
0x8049efb:      push   $0xff
0x8049f00:      push   $0x3
0x8049f02:      push   $0x2
0x8049f04:      call   0x80499e0    ; socket(AF_INET,SOCK_RAW,IPPROTO_RAW)
0x8049f09:      mov    %eax,0xffffffdc(%ebp)    ; socket fd
0x8049f0c:      add    $0xc,%esp
0x8049f0f:      test   %eax,%eax
0x8049f11:      jl     0x8049f68
0x8049f13:      movl   $0x0,0xffffffe0(%ebp)    ; level= SOL_IP
0x8049f1a:      movl   $0x42,0xffffffe4(%ebp)   ; optname: IP_FW_DELETE_NUM
0x8049f21:      lea    0xfffffff0(%ebp),%edx
0x8049f24:      mov    %edx,0xffffffe8(%ebp)
0x8049f27:      movl   $0x10,0xffffffec(%ebp)   ; optlen = 0x10
0x8049f2e:      mov    0x8(%ebp),%eax
0x8049f31:      mov    %eax,0xfffffff0(%ebp)    ; fwd_rulenum = p1
0x8049f34:      movl   $0x75706e69,0xfffffff4(%ebp)
0x8049f3b:      movl   $0x310074,0xfffffff8(%ebp)   ; fwd_label="input"
0x8049f42:      lea    0xfffffff4(%ebp),%edx
0x8049f45:      mov    %edx,0xfffffffc(%ebp)
0x8049f48:      lea    0xffffffdc(%ebp),%eax
0x8049f4b:      push   %eax
0x8049f4c:      push   $0xe
0x8049f4e:      push   $0x66
0x8049f50:      call   0x8049624                ; setsockopt
0x8049f55:      mov    %eax,%ebx
0x8049f57:      pushl  0xffffffdc(%ebp)
0x8049f5a:      push   $0x6
0x8049f5c:      call   0x8049610                ; close (s)
0x8049f61:      mov    %ebx,%eax
0x8049f63:      jmp    0x8049f6d
0x8049f65:      lea    0x0(%esi),%esi
0x8049f68:      mov    $0xffffffff,%eax
0x8049f6d:      mov    0xffffffd8(%ebp),%ebx
0x8049f70:      leave
0x8049f71:      ret
--
※ 来源:·UNIX编程 apue.dhs.org·[FROM: 202.108.200.52] --
※ 转寄:·UNIX编程 apue.dhs.org·[FROM: 210.39.3.50]
--
※ 转载:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.146]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店