对ip6tables rule操作

#include "libip6tc.h"


int getRulePackets()

{
    struct ip6tc_handle *handle;
    char *tables = "filter";
    const char *error = NULL;

       const char * chain = NULL;

       struct ip6t_counters counters;

       const char *pol = NULL;

       const struct ip6t_entry* rule;
       handle= ip6tc_init( tables );

/*
        int ret = 0;
       ret= xtables_init_all(&iptables_globals, NFPROTO_IPV6);

       if(ret < 0 )
       {
              printf("initerror\n");
              return-1;
       }
*/
       if(handle == NULL )
       {
              error= ip6tc_strerror(errno);
              printf("iptc_initerror:%s\n",error);
              return-1;
       }

 
    for(chain = ip6tc_first_chain(handle); chain; chain = ip6tc_next_chain(handle) )
    {
              printf("%s\t",chain);
              pol= ip6tc_get_policy(chain,&counters,handle);
              printf("%s\t",pol);
              printf("%llu\t",counters.pcnt);//\u7ecf\u8fc7\u8be5\u94fe\u7684\u5305\u7684\u6570\u91cf
              printf("%llu\n",counters.bcnt);//\u7ecf\u8fc7\u8be5\u94fe\u7684\u5b57\u8282\u6570

              for(rule = ip6tc_first_rule(chain,handle); rule; rule = ip6tc_next_rule(rule,handle))
              {
                     const char *target = NULL;
                     target= ip6tc_get_target(rule,handle);
                     printf("%s\t",target);
                     printf("%llu\t",rule->counters.pcnt);//\u547d\u4e2d\u8be5\u89c4\u5219\u7684\u5305\u6570
                     printf("%llu\t",rule->counters.bcnt);//\u547d\u4e2d\u8be5\u89c4\u5219\u7684\u5b57\u8282\u6570
                     struct protoent *pro = NULL;

                     pro= getprotobynumber(rule->ipv6.proto);

                     if(pro != NULL )
                     {
                            printf("%s\t",pro->p_name);
                     }
                     if(rule->ipv6.iniface[0] == '\0' )//\u8f93\u5165\u7f51\u7edc\u63a5\u53e3\u9ed8\u8ba4\u4e0d\u6307\u5b9a\u53ef\u4ee5\u901a\u8fc7-i\u6307\u5b9a\u5982 \u2013I ehh0
                            printf("any\t");
                     else
                            printf("%s\t",rule->ipv6.iniface);

 

                     if(rule->ipv6.outiface[0] == '\0' )//\u8f93\u51fa\u7f51\u7edc\u63a5\u53e3\u9ed8\u8ba4\u4e0d\u6307\u5b9a\u53ef\u4ee5\u901a\u8fc7-o \u6307\u5b9a
                            printf("any\t");
                     else
                            printf("%s\t",rule->ipv6.outiface);

                     char addr[128] = {0};

                     printf("%s\t",inet_ntop(AF_INET6,&(rule->ipv6.src),addr,sizeof(addr)));

                     printf("%s\t",inet_ntop(AF_INET6,&(rule->ipv6.dst),addr,sizeof(addr)));

        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值