]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/socket-protocol-list.c
2ba6df2b8dcd74121038f1d27d4ca1769550cd99
[thirdparty/systemd.git] / src / basic / socket-protocol-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2014 Lennart Poettering
4 ***/
5
6 #include <netinet/in.h>
7 #include <string.h>
8
9 #include "socket-protocol-list.h"
10 #include "macro.h"
11
12 static const struct socket_protocol_name* lookup_socket_protocol(register const char *str, register GPERF_LEN_TYPE len);
13
14 #include "socket-protocol-from-name.h"
15 #include "socket-protocol-to-name.h"
16
17 const char *socket_protocol_to_name(int id) {
18
19 if (id < 0)
20 return NULL;
21
22 if (id >= (int) ELEMENTSOF(socket_protocol_names))
23 return NULL;
24
25 return socket_protocol_names[id];
26 }
27
28 int socket_protocol_from_name(const char *name) {
29 const struct socket_protocol_name *sc;
30
31 assert(name);
32
33 sc = lookup_socket_protocol(name, strlen(name));
34 if (!sc)
35 return 0;
36
37 return sc->id;
38 }
39
40 int socket_protocol_max(void) {
41 return ELEMENTSOF(socket_protocol_names);
42 }