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