gpt4 book ai didi

linux - Linux 4.14 中的 NETLINK_NFLOG 支持

转载 作者:行者123 更新时间:2023-12-05 08:07:02 24 4
gpt4 key购买 nike

我的这个程序在 Linux 2.6.34 上运行良好。将此程序移植到 4.14 时,套接字创建出现错误“错误::不支持协议(protocol)”。根据 http://man7.org/linux/man-pages/man7/netlink.7.html

NETLINK_NFLOG(直到并包括 Linux 3.16)Netfilter/iptables ULOG。

我们知道 4.14 中的替代方案是什么吗?

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>

#include <pthread.h>

#include <netinet/ip.h>
#include <linux/types.h>
#include <linux/netlink.h>

int main()
{
struct sockaddr_nl addr;
int mypid;
int status;
int sockfd = -1;

/* mypid = getpid(); */
mypid = pthread_self();

sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_NFLOG);
if (sockfd <= 0) {
printf("netlink socket() failed - rc:%d, errno:%d\n",
sockfd, errno);
perror("Error: ");
return (-1);
}

/* set up socket address */
memset(&addr, 0, sizeof (addr));
addr.nl_pid = mypid;
addr.nl_family = AF_NETLINK;
/*
nl_groups is the multicast
group ID to which the ULOG
messages will be sent.It
is bitmap of hexadecimal
format
*/
addr.nl_groups = 1;

/* bind socket to listen on
* multicast group 1 */
status = bind(sockfd, (struct sockaddr *)&addr, sizeof (addr));
if (status < 0) {
perror("bind:");
close(sockfd);
return (-1);
}

printf("socket bind successful\n");

close(sockfd);
return (0);
}

我尝试浏览内核源代码但无法识别。

我已经低于配置

CONFIG_NETFILTER=y
# CONFIG_NETFILTER_ADVANCED is not set
CONFIG_NETFILTER_INGRESS=y
CONFIG_NETFILTER_NETLINK=y
CONFIG_NETFILTER_NETLINK_LOG=y
# CONFIG_NETFILTER_NETLINK_GLUE_CT is not set
CONFIG_NETFILTER_XTABLES=y
CONFIG_NETFILTER_XT_MARK=y
CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y
CONFIG_NETFILTER_XT_TARGET_LOG=y
CONFIG_NETFILTER_XT_NAT=y
# CONFIG_NETFILTER_XT_TARGET_NETMAP is not set
CONFIG_NETFILTER_XT_TARGET_NFLOG=y
# CONFIG_NETFILTER_XT_TARGET_REDIRECT is not set
CONFIG_NETFILTER_XT_TARGET_SECMARK=y
CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y
CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
CONFIG_NETFILTER_XT_MATCH_POLICY=y
CONFIG_NETFILTER_XT_MATCH_STATE=y

最佳答案

NETLINK_NFLOG(直到并包括 Linux 3.16)查看 libnml 中的工作示例

关于linux - Linux 4.14 中的 NETLINK_NFLOG 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57878667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com