]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5eef597e MP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 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 | ||
21 | #include <net/if_arp.h> | |
5eef597e MP |
22 | #include <string.h> |
23 | ||
5eef597e | 24 | #include "arphrd-list.h" |
4c89c718 | 25 | #include "macro.h" |
5eef597e | 26 | |
2897b343 | 27 | static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len); |
5eef597e | 28 | |
5eef597e | 29 | #include "arphrd-from-name.h" |
db2df898 | 30 | #include "arphrd-to-name.h" |
5eef597e MP |
31 | |
32 | const char *arphrd_to_name(int id) { | |
33 | ||
34 | if (id <= 0) | |
35 | return NULL; | |
36 | ||
37 | if (id >= (int) ELEMENTSOF(arphrd_names)) | |
38 | return NULL; | |
39 | ||
40 | return arphrd_names[id]; | |
41 | } | |
42 | ||
43 | int arphrd_from_name(const char *name) { | |
44 | const struct arphrd_name *sc; | |
45 | ||
46 | assert(name); | |
47 | ||
48 | sc = lookup_arphrd(name, strlen(name)); | |
49 | if (!sc) | |
50 | return 0; | |
51 | ||
52 | return sc->id; | |
53 | } | |
54 | ||
55 | int arphrd_max(void) { | |
56 | return ELEMENTSOF(arphrd_names); | |
57 | } |