aboutgitcodebugslistschat
path: root/ip.c
diff options
context:
space:
mode:
Diffstat (limited to 'ip.c')
-rw-r--r--ip.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/ip.c b/ip.c
index 9a7f4c5..f1d224b 100644
--- a/ip.c
+++ b/ip.c
@@ -67,3 +67,30 @@ found:
*proto = nh;
return true;
}
+
+/**
+ * ipproto_name() - Get IP protocol name from number
+ * @proto: IP protocol number
+ *
+ * Return: pointer to name of protocol @proto
+ *
+ * Usually this would be done with getprotobynumber(3) but that reads
+ * /etc/protocols and might allocate, which isn't possible for us once
+ * self-isolated.
+ */
+/* cppcheck-suppress unusedFunction */
+const char *ipproto_name(uint8_t proto)
+{
+ switch (proto) {
+ case IPPROTO_ICMP:
+ return "ICMP";
+ case IPPROTO_TCP:
+ return "TCP";
+ case IPPROTO_UDP:
+ return "UDP";
+ case IPPROTO_ICMPV6:
+ return "ICMPv6";
+ default:
+ return "<unknown protocol>";
+ }
+}