]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/arphrd-list.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / basic / arphrd-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <net/if_arp.h>
4 #include <string.h>
5
6 #include "arphrd-list.h"
7 #include "macro.h"
8
9 static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
10
11 #include "arphrd-from-name.h"
12 #include "arphrd-to-name.h"
13
14 const char *arphrd_to_name(int id) {
15
16 if (id <= 0)
17 return NULL;
18
19 if (id >= (int) ELEMENTSOF(arphrd_names))
20 return NULL;
21
22 return arphrd_names[id];
23 }
24
25 int arphrd_from_name(const char *name) {
26 const struct arphrd_name *sc;
27
28 assert(name);
29
30 sc = lookup_arphrd(name, strlen(name));
31 if (!sc)
32 return 0;
33
34 return sc->id;
35 }
36
37 int arphrd_max(void) {
38 return ELEMENTSOF(arphrd_names);
39 }