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