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