Network order or Host order for raw xlat style
Dmitry V. Levin
ldv at altlinux.org
Mon Jan 7 00:59:24 UTC 2019
On Sun, Jan 06, 2019 at 04:43:42PM -0800, shankarapailoor wrote:
> Thanks Dmitry! Here is an updated patch.
[...]
> Subject: [PATCH v1] handle xlat styles when decoding sockaddr_in and
> sockaddr_in6
I bet it is not v1. :)
[...]
> @@ -374,15 +413,43 @@ print_sockaddr_data_nl(const void *const buf, const int addrlen)
> PRINT_FIELD_0X(", ", *sa_nl, nl_groups);
> }
>
> +static void
> +print_sll_protocol(const struct sockaddr_ll *const sa_ll)
> +{
> + int x_style = xlat_verbose(xlat_verbosity);
> +
> + tprints("sll_protocol=");
> + if (x_style != XLAT_STYLE_ABBREV)
> + print_quoted_string((const char *) &sa_ll->sll_protocol,
> + sizeof(sa_ll->sll_protocol),
> + QUOTE_FORCE_HEX);
> +
> + if (x_style == XLAT_STYLE_RAW)
> + return;
> +
> + if (x_style == XLAT_STYLE_VERBOSE)
> + tprints(" /* ");
> +
> + tprints("htons(");
> + printxvals_ex(ntohs(sa_ll->sll_protocol),
> + "ETH_P_???",
> + XLAT_STYLE_ABBREV,
> + ethernet_protocols,
> + NULL);
As the original function used before this change was
printxval_search(ethernet_protocols, ntohs(sa_ll->sll_protocol),
"ETH_P_???");
printxval_searchn_ex seems to be more appropriate replacement than
printxvals_ex.
[...]
> + int rc = connect(-1, ll, len);
> +#if XLAT_RAW
> + printf("connect(-1, {sa_family=%#x"
> + ", sll_protocol=", AF_PACKET);
> + print_quoted_hex(&c_ll.sll_protocol, sizeof(c_ll.sll_protocol));
> + printf(", sll_ifindex=%u, sll_hatype=%#x"
> + ", sll_pkttype=%u, sll_halen=%u, sll_addr="
> + "[%#02x, %#02x, %#02x, %#02x, %#02x, %#02x, %#02x, %#02x]"
> + "}, %u) = %s\n",
> + c_ll.sll_ifindex, ARPHRD_ETHER,
> + PACKET_HOST, c_ll.sll_halen,
> + c_ll.sll_addr[0], c_ll.sll_addr[1],
> + c_ll.sll_addr[2], c_ll.sll_addr[3],
> + c_ll.sll_addr[4], c_ll.sll_addr[5],
> + c_ll.sll_addr[6], c_ll.sll_addr[7],
> + len, sprintrc(rc));
This variant has essentially the same errno clobbering issue
as the previous one because sprintrc() uses errno.
The fix is to call sprintrc() right after the syscall and save the result
into a variable that could be passed later to printf().
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190107/116c45c9/attachment.bin>
More information about the Strace-devel
mailing list