2 * Copyright (c) 2018-2019 The strace developers.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
10 #include "error_prints.h"
13 #define XLAT_MACROS_ONLY
14 # include "xlat/arp_hardware_types.h"
15 #undef XLAT_MACROS_ONLY
17 DIAG_PUSH_IGNORE_OVERRIDE_INIT
19 static uint8_t hwaddr_sizes[] = {
20 [0 ... ARPHRD_IEEE802_TR] = 255,
22 [ARPHRD_NETROM] = 7 /* AX25_ADDR_LEN */,
23 [ARPHRD_ETHER] = 6 /* ETH_ALEN */,
24 /* ARPHRD_EETHER - no actual devices in Linux */
25 [ARPHRD_AX25] = 7 /* AX25_ADDR_LEN */,
26 /* ARPHRD_PRONET - no actual devices in Linux */
27 /* ARPHRD_CHAOS - no actual devices in Linux */
28 [ARPHRD_IEEE802] = 6 /* FC_ALEN */,
29 [ARPHRD_ARCNET] = 1 /* ARCNET_ALEN */,
30 /* ARPHRD_APPLETLK - no actual devices in Linux */
31 [ARPHRD_DLCI] = sizeof(short),
32 /* ARPHRD_ATM - no explicit setting */
33 /* ARPHRD_METRICOM - no actual devices in Linux */
34 [ARPHRD_IEEE1394] = 16 /* FWNET_ALEN */,
35 [ARPHRD_EUI64] = 8 /* EUI64_ADDR_LEN */,
36 [ARPHRD_INFINIBAND] = 20 /* INFINIBAND_ALEN */,
38 /* ARPHRD_CSLIP - no actual devices in Linux */
39 /* ARPHRD_SLIP6 - no actual devices in Linux */
40 /* ARPHRD_CSLIP6 - no actual devices in Linux */
41 /* ARPHRD_RSRVD - no actual devices in Linux */
42 /* ARPHRD_ADAPT - no actual devices in Linux */
43 [ARPHRD_ROSE] = 5 /* ROSE_ADDR_LEN */,
45 /* ARPHRD_HWX25 - no actual devices in Linux */
48 /* ARPHRD_CISCO - no actual devices in Linux */
49 /* ARPHRD_LAPB - no actual devices in Linux */
50 /* ARPHRD_DDCMP - no actual devices in Linux */
53 [ARPHRD_TUNNEL] = 4 /* IPIP */,
54 [ARPHRD_TUNNEL6] = 16 /* sizeof(struct in6_addr) */,
55 /* ARPHRD_FRAD - no actual devices in Linux */
56 /* ARPHRD_SKIP - no actual devices in Linux */
57 [ARPHRD_LOOPBACK] = 6 /* ETH_ALEN */,
58 [ARPHRD_LOCALTLK] = 1 /* LTALK_ALEN */,
59 [ARPHRD_FDDI] = 6 /* FDDI_K_ALEN */,
60 /* ARPHRD_BIF - no actual devices in Linux */
65 [ARPHRD_HIPPI] = 6 /* HIPPI_ALEN */,
66 /* ARPHRD_ASH - no actual devices in Linux */
67 /* ARPHRD_ECONET - no actual devices in Linux */
68 [ARPHRD_IRDA] = 4 /* LAP_ALEN */,
69 /* ARPHRD_FCPP - no actual devices in Linux */
70 /* ARPHRD_FCAL - no actual devices in Linux */
71 /* ARPHRD_FCPL - no actual devices in Linux */
72 /* ARPHRD_FCFABRIC - no actual devices in Linux */
73 /* ARPHRD_IEEE802_TR - no actual devices in Linux */
74 [ARPHRD_IEEE80211] = 6 /* ETH_ALEN */,
75 [ARPHRD_IEEE80211_PRISM] = 6 /* ETH_ALEN */,
76 [ARPHRD_IEEE80211_RADIOTAP] = 6 /* ETH_ALEN */,
78 = 8 /* IEEE802154_EXTENDED_ADDR_LEN */,
79 [ARPHRD_IEEE802154_MONITOR]
80 = 8 /* IEEE802154_EXTENDED_ADDR_LEN */,
82 [ARPHRD_PHONET_PIPE] = 1,
84 [ARPHRD_IP6GRE] = 16 /* sizeof(struct in6_addr) */,
86 [ARPHRD_6LOWPAN] = 8 /* EUI64_ADDR_LEN */
87 /* ^ or ETH_ALEN, depending on lltype */,
88 [ARPHRD_VSOCKMON] = 0,
91 DIAG_POP_IGNORE_OVERRIDE_INIT
94 sprint_mac_addr(const uint8_t addr[], size_t size)
96 static char res[MAX_ADDR_LEN * 3];
98 if (size > MAX_ADDR_LEN) {
99 error_func_msg("Address size (%zu) is more than maximum "
100 "supported (%u)", size, MAX_ADDR_LEN);
107 for (size_t i = 0; i < size; i++)
108 ptr = xappendstr(res, ptr, "%s%02x", i ? ":" : "", addr[i]);
114 print_mac_addr(const char *prefix, const uint8_t addr[], size_t size)
117 if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
118 print_quoted_string((const char *) addr, size,
120 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
122 (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
123 ? tprints_comment : tprints)(sprint_mac_addr(addr, size));
127 sprint_hwaddr(const uint8_t hwaddr[], size_t size, uint32_t devtype)
129 uint8_t sz = (devtype < ARRAY_SIZE(hwaddr_sizes))
130 ? hwaddr_sizes[devtype] : 255;
132 return sprint_mac_addr(hwaddr, MIN(size, sz));
136 print_hwaddr(const char *prefix, const uint8_t addr[], size_t size,
140 if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
141 print_quoted_string((const char *) addr, size,
143 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
145 (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
146 ? tprints_comment : tprints)(sprint_hwaddr(addr, size,