]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/arphrd-list.c
Merge pull request #8417 from brauner/2018-03-09/add_bind_mount_fallback_to_private_d...
[thirdparty/systemd.git] / src / basic / arphrd-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2014 Lennart Poettering
6 ***/
7
8 #include <net/if_arp.h>
9 #include <string.h>
10
11 #include "arphrd-list.h"
12 #include "macro.h"
13
14 static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
15
16 #include "arphrd-from-name.h"
17 #include "arphrd-to-name.h"
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 }