]> granicus.if.org Git - strace/blobdiff - nlattr.c
nlattr: add unsigned int decoders that print in hex form
[strace] / nlattr.c
index b11f682109e55c21e2f59d89538b11df62286262..83a25bd6f402a0126ce58a488c2a8505c21d216c 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -287,6 +287,31 @@ decode_nla_xval(struct tcb *const tcp,
        return true;
 }
 
+static uint64_t
+process_host_order(uint64_t val)
+{
+       return ntohs(val);
+}
+
+bool
+decode_nla_ether_proto(struct tcb *const tcp,
+                      const kernel_ulong_t addr,
+                      const unsigned int len,
+                      const void *const opaque_data)
+{
+       const struct decode_nla_xlat_opts opts = {
+               .xlat = ethernet_protocols,
+               .xlat_size = ethernet_protocols_size,
+               .dflt = "ETHER_P_???",
+               .xt = XT_SORTED,
+               .prefix = "htons(",
+               .suffix = ")",
+               .process_fn = process_host_order,
+       };
+
+       return decode_nla_xval(tcp, addr, len, &opts);
+}
+
 bool
 decode_nla_ip_proto(struct tcb *const tcp,
                    const kernel_ulong_t addr,
@@ -389,6 +414,10 @@ decode_nla_ ## name(struct tcb *const tcp,         \
        return true;                                    \
 }
 
+DECODE_NLA_INTEGER(x8, uint8_t, "%#" PRIx8)
+DECODE_NLA_INTEGER(x16, uint16_t, "%#" PRIx16)
+DECODE_NLA_INTEGER(x32, uint32_t, "%#" PRIx32)
+DECODE_NLA_INTEGER(x64, uint64_t, "%#" PRIx64)
 DECODE_NLA_INTEGER(u8, uint8_t, "%" PRIu8)
 DECODE_NLA_INTEGER(u16, uint16_t, "%" PRIu16)
 DECODE_NLA_INTEGER(u32, uint32_t, "%" PRIu32)