我正在玩通过 libnetfilter_conntrack 捕获数据包
到目前为止,除了 Ubuntu 18.04 之外,以下代码已在 Ubuntu 上运行。
尽管浏览或访问 ssh,但没有输出。
你知道为什么吗???
static int cb(enum nf_conntrack_msg_type eMsgType,
struct nf_conntrack *psConntrack,
void *pvData)
{
char buf[1024] = {0,};
nfct_snprintf(buf, sizeof(buf), psConntrack, eMsgType, NFCT_O_DEFAULT, NFCT_OF_TIME);
printf("%s\n", buf);
return NFCT_CB_STOP;
}
int main()
{
struct nfct_handle *pSNfctHandle;
pSNfctHandle = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS);
nfct_callback_register(pSNfctHandle, NFCT_T_ALL, cb, NULL);
nfct_catch(pSNfctHandle);
nfct_close(pSNfctHandle);
return 0;
}
我在添加 nf_conntrack、nf_conntrack_ipv4、nf_conntrack_netlink 内核模块后进行了测试。