Debian Codegraph @

src/basic/arphrd-util.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <linux/if_arp.h>
4 #include <linux/if_infiniband.h>
5 #include <netinet/in.h>
6 #include <string.h>
7
8 #include "arphrd-util.h"
9
10 static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
11
12 #include "arphrd-from-name.inc"
13 #include "arphrd-to-name.inc"
14
15 int arphrd_from_name(const char *name) {
16 const struct arphrd_name *sc;
17
18 assert(name);
19
20 sc = lookup_arphrd(name, strlen(name));
21 if (!sc)
22 return -EINVAL;
23
24 return sc->id;
25 }
26
27 size_t arphrd_to_hw_addr_len(uint16_t arphrd) {
28 switch (arphrd) {
29 case ARPHRD_ETHER:
30 return ETH_ALEN;
31 case ARPHRD_INFINIBAND:
32 return INFINIBAND_ALEN;
33 case ARPHRD_TUNNEL:
34 case ARPHRD_SIT:
35 case ARPHRD_IPGRE:
36 return sizeof(struct in_addr);
37 case ARPHRD_TUNNEL6:
38 case ARPHRD_IP6GRE:
39 return sizeof(struct in6_addr);
40 default:
41 return 0;
42 }
43 }