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