@@ -13,20 +13,18 @@ static int __snprintf_l3protocol(char *buf,
unsigned int len,
const struct nf_conntrack *ct)
{
- return (snprintf(buf, len, "%-8s %u ",
- l3proto2str[ct->head.orig.l3protonum] == NULL ?
- "unknown" : l3proto2str[ct->head.orig.l3protonum],
- ct->head.orig.l3protonum));
+ uint8_t num = ct->head.orig.l3protonum;
+
+ return snprintf(buf, len, "%-8s %u ", __l3proto2str(num), num);
}
int __snprintf_protocol(char *buf,
unsigned int len,
const struct nf_conntrack *ct)
{
- return (snprintf(buf, len, "%-8s %u ",
- proto2str[ct->head.orig.protonum] == NULL ?
- "unknown" : proto2str[ct->head.orig.protonum],
- ct->head.orig.protonum));
+ uint8_t num = ct->head.orig.protonum;
+
+ return snprintf(buf, len, "%-8s %u ", __proto2str(num), num);
}
static int __snprintf_timeout(char *buf,
@@ -55,12 +55,28 @@
const char *__proto2str(uint8_t protonum)
{
- return proto2str[protonum] ? proto2str[protonum] : "unknown";
+ const char *str = NULL;
+
+ if (protonum < ARRAY_SIZE(proto2str))
+ str = proto2str[protonum];
+
+ if (str == NULL)
+ str = "unknown";
+
+ return str;
}
const char *__l3proto2str(uint8_t protonum)
{
- return l3proto2str[protonum] ? l3proto2str[protonum] : "unknown";
+ const char *str = NULL;
+
+ if (protonum < ARRAY_SIZE(l3proto2str))
+ str = l3proto2str[protonum];
+
+ if (str == NULL)
+ str = "unknown";
+
+ return str;
}
static int __snprintf_ipv4_xml(char *buf,
Signed-off-by: Daniel Gröber <dxld@darkboxed.org> --- src/conntrack/snprintf_default.c | 14 ++++++-------- src/conntrack/snprintf_xml.c | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-)