]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
663996b3 | 2 | |
6e866b33 | 3 | #include <errno.h> |
663996b3 | 4 | #include <string.h> |
db2df898 | 5 | #include <sys/socket.h> |
663996b3 | 6 | |
60f067b4 | 7 | #include "af-list.h" |
4c89c718 | 8 | #include "macro.h" |
663996b3 | 9 | |
2897b343 | 10 | static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len); |
663996b3 | 11 | |
60f067b4 | 12 | #include "af-from-name.h" |
db2df898 | 13 | #include "af-to-name.h" |
663996b3 | 14 | |
60f067b4 | 15 | const char *af_to_name(int id) { |
663996b3 | 16 | |
60f067b4 | 17 | if (id <= 0) |
663996b3 MS |
18 | return NULL; |
19 | ||
6e866b33 | 20 | if ((size_t) id >= ELEMENTSOF(af_names)) |
60f067b4 JS |
21 | return NULL; |
22 | ||
23 | return af_names[id]; | |
663996b3 MS |
24 | } |
25 | ||
60f067b4 JS |
26 | int af_from_name(const char *name) { |
27 | const struct af_name *sc; | |
663996b3 MS |
28 | |
29 | assert(name); | |
30 | ||
60f067b4 | 31 | sc = lookup_af(name, strlen(name)); |
663996b3 | 32 | if (!sc) |
6e866b33 | 33 | return -EINVAL; |
663996b3 MS |
34 | |
35 | return sc->id; | |
36 | } | |
37 | ||
60f067b4 JS |
38 | int af_max(void) { |
39 | return ELEMENTSOF(af_names); | |
663996b3 | 40 | } |