diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-10-01 13:23:39 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-10-01 13:23:39 +0200 |
commit | 3c78a4543e12f5e82bdd771971d3534fa452117b (patch) | |
tree | 8cde35f4b0331bd95a6ea08572628ae680a8e4c0 /src/nfct.c | |
parent | 386968d321d02571b593b3bbbf39891f44397469 (diff) |
nfct: src: consolidate netlink socket creation
Open the socket from the main function, then pass it as parameter
to the corresponding interpreter.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/nfct.c')
-rw-r--r-- | src/nfct.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -69,6 +69,7 @@ int main(int argc, char *argv[]) { int subsys = NFCT_SUBSYS_NONE, ret = 0; struct nfct_extension *ext; + struct mnl_socket *nl; if (argc < 2) { usage(argv); @@ -103,7 +104,15 @@ int main(int argc, char *argv[]) VERSION, argv[1]); return EXIT_FAILURE; } - ret = ext->parse_params(argc, argv); + + nl = nfct_mnl_open(); + if (nl == NULL) { + nfct_perror("cannot open netlink"); + return -1; + } + + ret = ext->parse_params(nl, argc, argv); + mnl_socket_close(nl); break; } return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; @@ -168,3 +177,17 @@ int nfct_mnl_talk(struct mnl_socket *nl, struct nlmsghdr *nlh, return 0; } + +struct mnl_socket *nfct_mnl_open(void) +{ + struct mnl_socket *nl; + + nl = mnl_socket_open(NETLINK_NETFILTER); + if (nl == NULL) + return NULL; + + if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) + return NULL; + + return nl; +} |