summaryrefslogtreecommitdiffstats
path: root/iptables/ip6tables.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2020-11-17 00:57:10 +0100
committerPhil Sutter <phil@nwl.cc>2021-05-17 15:07:22 +0200
commit556f704458cdb509d395ddb7d2629987d60e762e (patch)
tree115282e7391fb411e8d0f92b5324b32142efed22 /iptables/ip6tables.c
parenteea68ca828b6a757490d91fc87dcac2f15647f40 (diff)
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 <phil@nwl.cc>
Diffstat (limited to 'iptables/ip6tables.c')
-rw-r--r--iptables/ip6tables.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c
index 044d9a33..e967c040 100644
--- a/iptables/ip6tables.c
+++ b/iptables/ip6tables.c
@@ -759,28 +759,16 @@ print_iface(char letter, const char *iface, const unsigned char *mask,
}
}
-/* The ip6tables looks up the /etc/protocols. */
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);
}
}