summaryrefslogtreecommitdiff
path: root/src/shared/ip-protocol-list.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-29 15:58:43 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-02 05:48:27 +0100
commitda96ad5ae2bf3e9fd94d145c4b75fdf54a214350 (patch)
tree0c8be8c1b1c3bb562cc7fedaabb8d2e4b2b9fee5 /src/shared/ip-protocol-list.c
parent5dd9527883e0aa8705cf81448bc4bdb0456382fb (diff)
downloadsystemd-da96ad5ae2bf3e9fd94d145c4b75fdf54a214350.tar.gz
util: rename socket_protocol_{from,to}_name() to ip_protocol_{from,to}_name()
Diffstat (limited to 'src/shared/ip-protocol-list.c')
-rw-r--r--src/shared/ip-protocol-list.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/shared/ip-protocol-list.c b/src/shared/ip-protocol-list.c
new file mode 100644
index 0000000000..9a1c11b0d8
--- /dev/null
+++ b/src/shared/ip-protocol-list.c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <string.h>
+
+#include "ip-protocol-list.h"
+#include "macro.h"
+
+static const struct ip_protocol_name* lookup_ip_protocol(register const char *str, register GPERF_LEN_TYPE len);
+
+#include "ip-protocol-from-name.h"
+#include "ip-protocol-to-name.h"
+
+const char *ip_protocol_to_name(int id) {
+
+ if (id < 0)
+ return NULL;
+
+ if (id >= (int) ELEMENTSOF(ip_protocol_names))
+ return NULL;
+
+ return ip_protocol_names[id];
+}
+
+int ip_protocol_from_name(const char *name) {
+ const struct ip_protocol_name *sc;
+
+ assert(name);
+
+ sc = lookup_ip_protocol(name, strlen(name));
+ if (!sc)
+ return -EINVAL;
+
+ return sc->id;
+}