]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4298d0b5 | 2 | |
4298d0b5 | 3 | #include <string.h> |
cf0fbc49 | 4 | #include <sys/socket.h> |
4298d0b5 | 5 | |
4298d0b5 | 6 | #include "af-list.h" |
11c3a366 | 7 | #include "macro.h" |
4298d0b5 | 8 | |
c9f7b4d3 | 9 | static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len); |
4298d0b5 | 10 | |
4298d0b5 | 11 | #include "af-from-name.h" |
cf0fbc49 | 12 | #include "af-to-name.h" |
4298d0b5 LP |
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 | } |