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