]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
ee8c4568 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Lennart Poettering | |
ee8c4568 LP |
6 | ***/ |
7 | ||
8 | #include <net/if_arp.h> | |
ee8c4568 LP |
9 | #include <string.h> |
10 | ||
ee8c4568 | 11 | #include "arphrd-list.h" |
11c3a366 | 12 | #include "macro.h" |
ee8c4568 | 13 | |
c9f7b4d3 | 14 | static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len); |
ee8c4568 | 15 | |
ee8c4568 | 16 | #include "arphrd-from-name.h" |
cf0fbc49 | 17 | #include "arphrd-to-name.h" |
ee8c4568 LP |
18 | |
19 | const char *arphrd_to_name(int id) { | |
20 | ||
21 | if (id <= 0) | |
22 | return NULL; | |
23 | ||
24 | if (id >= (int) ELEMENTSOF(arphrd_names)) | |
25 | return NULL; | |
26 | ||
27 | return arphrd_names[id]; | |
28 | } | |
29 | ||
30 | int arphrd_from_name(const char *name) { | |
31 | const struct arphrd_name *sc; | |
32 | ||
33 | assert(name); | |
34 | ||
35 | sc = lookup_arphrd(name, strlen(name)); | |
36 | if (!sc) | |
37 | return 0; | |
38 | ||
39 | return sc->id; | |
40 | } | |
41 | ||
42 | int arphrd_max(void) { | |
43 | return ELEMENTSOF(arphrd_names); | |
44 | } |