udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / basic / arphrd-util.c
blob3ea2c9d09a90870b203a4bff2c26187e3c171b01
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include <errno.h>
4 #include <netinet/in.h>
5 #include <linux/if_arp.h>
6 #include <linux/if_infiniband.h>
7 #include <string.h>
9 #include "arphrd-util.h"
10 #include "macro.h"
12 static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
14 #include "arphrd-from-name.h"
15 #include "arphrd-to-name.h"
17 int arphrd_from_name(const char *name) {
18 const struct arphrd_name *sc;
20 assert(name);
22 sc = lookup_arphrd(name, strlen(name));
23 if (!sc)
24 return -EINVAL;
26 return sc->id;
29 size_t arphrd_to_hw_addr_len(uint16_t arphrd) {
30 switch (arphrd) {
31 case ARPHRD_ETHER:
32 return ETH_ALEN;
33 case ARPHRD_INFINIBAND:
34 return INFINIBAND_ALEN;
35 case ARPHRD_TUNNEL:
36 case ARPHRD_SIT:
37 case ARPHRD_IPGRE:
38 return sizeof(struct in_addr);
39 case ARPHRD_TUNNEL6:
40 case ARPHRD_IP6GRE:
41 return sizeof(struct in6_addr);
42 default:
43 return 0;