diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-13 16:07:43 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-13 16:07:43 +0000 |
commit | d94805d59bbd3a4ceb725f5fc4c6e6778dc25709 (patch) | |
tree | b91192ddd4c74660e1a7839d8ff820636a1a32fc /src/conntrack | |
parent | 58716a8224deb44c67dde60fe60672de9820e3df (diff) |
add NFCT_OF_TIME output flag to nfct_snprintf
Diffstat (limited to 'src/conntrack')
-rw-r--r-- | src/conntrack/api.c | 5 | ||||
-rw-r--r-- | src/conntrack/snprintf_xml.c | 40 |
2 files changed, 43 insertions, 2 deletions
diff --git a/src/conntrack/api.c b/src/conntrack/api.c index d020869..f2f3cb5 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -607,8 +607,9 @@ int nfct_catch(struct nfct_handle *h) * - NFCT_O_XML: XML output * * The output flags are: - * - NFCT_O_LAYER: include layer 3 information in the output, this is - * *only* required by NFCT_O_DEFAULT. + * - NFCT_OF_SHOW_LAYER3: include layer 3 information in the output, + * this is *only* required by NFCT_O_DEFAULT. + * - NFCT_OF_TIME: display time. * * This function returns the size of the information that _would_ have been * written to the buffer, even if there was no room for it. Thus, the diff --git a/src/conntrack/snprintf_xml.c b/src/conntrack/snprintf_xml.c index 1415e0d..9f7f388 100644 --- a/src/conntrack/snprintf_xml.c +++ b/src/conntrack/snprintf_xml.c @@ -341,6 +341,46 @@ int __snprintf_conntrack_xml(char *buf, BUFFER_SIZE(ret, size, len, offset); } + if (flags & NFCT_OF_TIME) { + time_t t; + struct tm tm; + + t = time(NULL); + if (localtime_r(&t, &tm) == NULL) + goto err_out; + + ret = snprintf(buf+offset, len, "<when>"); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<hour>%d</hour>", tm.tm_hour); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<min>%02d</min>", tm.tm_min); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<sec>%02d</sec>", tm.tm_sec); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<wday>%d</wday>", + tm.tm_wday + 1); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<day>%d</day>", tm.tm_mday); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<month>%d</month>", + tm.tm_mon + 1); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "<year>%d</year>", + 1900 + tm.tm_year); + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "</when>"); + BUFFER_SIZE(ret, size, len, offset); + } + +err_out: ret = snprintf(buf+offset, len, "</flow>"); BUFFER_SIZE(ret, size, len, offset); |