]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4298d0b5 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
4298d0b5 | 21 | #include <string.h> |
cf0fbc49 | 22 | #include <sys/socket.h> |
4298d0b5 | 23 | |
4298d0b5 | 24 | #include "af-list.h" |
11c3a366 | 25 | #include "macro.h" |
4298d0b5 | 26 | |
c9f7b4d3 | 27 | static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len); |
4298d0b5 | 28 | |
4298d0b5 | 29 | #include "af-from-name.h" |
cf0fbc49 | 30 | #include "af-to-name.h" |
4298d0b5 LP |
31 | |
32 | const char *af_to_name(int id) { | |
33 | ||
34 | if (id <= 0) | |
35 | return NULL; | |
36 | ||
37 | if (id >= (int) ELEMENTSOF(af_names)) | |
38 | return NULL; | |
39 | ||
40 | return af_names[id]; | |
41 | } | |
42 | ||
43 | int af_from_name(const char *name) { | |
44 | const struct af_name *sc; | |
45 | ||
46 | assert(name); | |
47 | ||
48 | sc = lookup_af(name, strlen(name)); | |
49 | if (!sc) | |
50 | return AF_UNSPEC; | |
51 | ||
52 | return sc->id; | |
53 | } | |
54 | ||
55 | int af_max(void) { | |
56 | return ELEMENTSOF(af_names); | |
57 | } |