]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/arphrd-list.c
Add SPDX license identifiers to source files under the LGPL
[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 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <net/if_arp.h>
22 #include <string.h>
23
24 #include "arphrd-list.h"
25 #include "macro.h"
26
27 static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
28
29 #include "arphrd-from-name.h"
30 #include "arphrd-to-name.h"
31
32 const char *arphrd_to_name(int id) {
33
34 if (id <= 0)
35 return NULL;
36
37 if (id >= (int) ELEMENTSOF(arphrd_names))
38 return NULL;
39
40 return arphrd_names[id];
41 }
42
43 int arphrd_from_name(const char *name) {
44 const struct arphrd_name *sc;
45
46 assert(name);
47
48 sc = lookup_arphrd(name, strlen(name));
49 if (!sc)
50 return 0;
51
52 return sc->id;
53 }
54
55 int arphrd_max(void) {
56 return ELEMENTSOF(arphrd_names);
57 }