From 556f704458cdb509d395ddb7d2629987d60e762e Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 17 Nov 2020 00:57:10 +0100 Subject: Use proto_to_name() from xshared in more places Share the common proto name lookup code. While being at it, make proto number variable 16bit, values may exceed 256. This aligns iptables-nft '-p' argument printing with legacy iptables. In practice, this should make a difference only in corner cases. Signed-off-by: Phil Sutter --- iptables/iptables.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'iptables/iptables.c') diff --git a/iptables/iptables.c b/iptables/iptables.c index da67dd2e..b925f089 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -727,23 +727,13 @@ list_entries(const xt_chainlabel chain, int rulenum, int verbose, int numeric, static void print_proto(uint16_t proto, int invert) { if (proto) { - unsigned int i; + const char *pname = proto_to_name(proto, 0); const char *invertstr = invert ? " !" : ""; - const struct protoent *pent = getprotobynumber(proto); - if (pent) { - printf("%s -p %s", invertstr, pent->p_name); - return; - } - - for (i = 0; xtables_chain_protos[i].name != NULL; ++i) - if (xtables_chain_protos[i].num == proto) { - printf("%s -p %s", - invertstr, xtables_chain_protos[i].name); - return; - } - - printf("%s -p %u", invertstr, proto); + if (pname) + printf("%s -p %s", invertstr, pname); + else + printf("%s -p %u", invertstr, proto); } } -- cgit v1.2.3