]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/ip-protocol-list.c
util: rename socket_protocol_{from,to}_name() to ip_protocol_{from,to}_name()
[thirdparty/systemd.git] / src / shared / ip-protocol-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <netinet/in.h>
5 #include <string.h>
6
7 #include "ip-protocol-list.h"
8 #include "macro.h"
9
10 static const struct ip_protocol_name* lookup_ip_protocol(register const char *str, register GPERF_LEN_TYPE len);
11
12 #include "ip-protocol-from-name.h"
13 #include "ip-protocol-to-name.h"
14
15 const char *ip_protocol_to_name(int id) {
16
17 if (id < 0)
18 return NULL;
19
20 if (id >= (int) ELEMENTSOF(ip_protocol_names))
21 return NULL;
22
23 return ip_protocol_names[id];
24 }
25
26 int ip_protocol_from_name(const char *name) {
27 const struct ip_protocol_name *sc;
28
29 assert(name);
30
31 sc = lookup_ip_protocol(name, strlen(name));
32 if (!sc)
33 return -EINVAL;
34
35 return sc->id;
36 }