From 47ab85f4c36c713f66bd909d76295f81867b9982 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 17 Oct 2011 00:19:41 +0200 Subject: src: improve nfacct-add example Now it takes the name of the accouting zone as argument. --- examples/nfacct-add.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/nfacct-add.c b/examples/nfacct-add.c index df3175e..8132ade 100644 --- a/examples/nfacct-add.c +++ b/examples/nfacct-add.c @@ -1,21 +1,25 @@ #include #include +#include #include #include -int main(void) +int main(int argc, char *argv[]) { struct mnl_socket *nl; char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; uint32_t portid, seq; - struct nfacct nfacct = { - .name = "example", - .pkts = 10, - .bytes = 10, - }; + struct nfacct nfacct; int ret; + if (argc != 2) { + fprintf(stderr, "Usage: %s [name]\n", argv[0]); + exit(EXIT_FAILURE); + } + strncpy(nfacct.name, argv[1], NFACCT_NAME_MAX); + nfacct.name[NFACCT_NAME_MAX-1] = '\0'; + nlh = nfacct_add(buf, &nfacct); seq = nlh->nlmsg_seq = time(NULL); -- cgit v1.2.3