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