netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [libnftables PATCH 2/2] examples: nft-table-get different families options
Date: Fri, 05 Jul 2013 14:41:35 +0200	[thread overview]
Message-ID: <20130705124135.23285.58726.stgit@Ph0enix> (raw)
In-Reply-To: <20130705123837.23285.5489.stgit@Ph0enix>

From: Álvaro Neira Ayuso <alvaroneay@gmail.com>

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 examples/nft-table-get.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/examples/nft-table-get.c b/examples/nft-table-get.c
index 0d7746c..eab78de 100644
--- a/examples/nft-table-get.c
+++ b/examples/nft-table-get.c
@@ -50,11 +50,27 @@ int main(int argc, char *argv[])
 	struct mnl_socket *nl;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
-	uint32_t portid, seq;
+	uint32_t portid, seq, family;
 	struct nft_table *t = NULL;
 	int ret;
 	uint32_t type = NFT_TABLE_O_DEFAULT;
 
+	if (argc < 2 || argc > 4) {
+		fprintf(stderr, "%s <family> [<table>] [default|xml|json]\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	if (strcmp(argv[1], "ip") == 0)
+		family = AF_INET;
+	else if (strcmp(argv[1], "ip6") == 0)
+		family = AF_INET6;
+	else if (strcmp(argv[1], "bridge") == 0)
+		family = AF_BRIDGE;
+	else {
+		fprintf(stderr, "Unknown family: ip, ip6, bridge\n");
+		exit(EXIT_FAILURE);
+	}
+
 	if (strcmp(argv[argc-1], "xml") == 0) {
 		type = NFT_TABLE_O_XML;
 		argv[argc-1] = NULL;
@@ -67,7 +83,7 @@ int main(int argc, char *argv[])
 		argc--;
 	}
 
-	if (argc == 2) {
+	if (argc == 3) {
 		t = nft_table_alloc();
 		if (t == NULL) {
 			perror("OOM");
@@ -77,12 +93,12 @@ int main(int argc, char *argv[])
 
 	seq = time(NULL);
 	if (t == NULL) {
-		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, AF_INET,
+		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
 						NLM_F_DUMP, seq);
 	} else {
-		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, AF_INET,
+		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
 						NLM_F_ACK, seq);
-		nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[1]);
+		nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[2]);
 		nft_table_nlmsg_build_payload(nlh, t);
 		nft_table_free(t);
 	}

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-07-05 12:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-05 12:41 [libnftables PATCH 0/2] Series Add Json Support Alvaro Neira
2013-07-05 12:41 ` [libnftables PATCH 1/2] set: add Json Export Support Alvaro Neira
2013-07-05 22:22   ` Pablo Neira Ayuso
2013-07-05 12:41 ` Alvaro Neira [this message]
2013-07-05 22:23   ` [libnftables PATCH 2/2] examples: nft-table-get different families options Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130705124135.23285.58726.stgit@Ph0enix \
    --to=alvaroneay@gmail.com \
    --cc=eric@regit.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).