c - 使用 C netfilter lib 列出自定义链
问题描述
我正在尝试在 netfilter 中列出自定义链,但是当在 Debian 11 上运行时,以下代码只给了我过滤表中的默认链。在 Ubuntu 20.04 上,它也列出了其他链。谁能告诉我我做错了什么?先感谢您。
外壳:Debian 11,内核 5.10.0-8-amd64,iptables 1.8.7-1
iptables -N TEST
./listchains
Chain name is INPUT
Chain name is FORWARD
Chain name is OUTPUT
Ubuntu 20.04,内核 5.4.0-40-generic,iptables 1.8.4-3ubuntu2
iptables -N TEST
./listchains
Chain name is INPUT
Chain name is FORWARD
Chain name is OUTPUT
Chain name is TEST
C代码:
// compile with gcc -Wall -o listchains listchains.c -lip4tc
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <libiptc/libiptc.h>
int main(void) {
struct xtc_handle *h;
const char *chain = NULL;
const char *tablename = "filter";
h = iptc_init(tablename);
if (!h) {
printf("Error initializing: %s\n", iptc_strerror(errno));
exit(errno);
}
chain = iptc_first_chain(h);
while (chain) {
printf("Chain name is %s\n", chain);
chain = iptc_next_chain(h);
}
}
解决方案
推荐阅读
- python-3.x - 将 varBinds 中的 OID 转换为 MIB 的最有效方法
- java - 在 JNI 函数中,当我就地更改从 Java 代码传递的数组时,数组不会修改
- javascript - 如何修改此代码以创建听写应用程序?
- c# - 如何在不点击 Unity 中的输入字段的情况下输入单词
- c - 修改内核参数(不允许 mmap 操作,EPERM)
- c++ - 计算 N 组交集的快速算法
- python - 构建和编译 keras 顺序模型时出现“列表索引超出范围”
- r - R - 如何在同一列中按每小时不同的分钟数计算值
- sql-server - 查询中的 SQL 子查询?可能的?
- sql - SQL Server 加密 mdf 文件