Network order or Host order for raw xlat style

Dmitry V. Levin ldv at altlinux.org
Sun Jan 6 23:47:40 UTC 2019


Hi,

On Fri, Jan 04, 2019 at 08:41:45PM -0800, shankarapailoor wrote:
> Sorry, just to be more clear, attached is the updated patch which
> prints the fields as hex strings.
[...]
> Subject: [PATCH v1] handle xlat styles when decoding sockaddr_in and
>  sockaddr_in6
> 
> * print_fields.h (PRINT_FIELD_INET4_ADDR, PRINT_FIELD_NET_PORT): Handle XLAT_RAW and XLAT_VERBOSE.
> * sockaddr.c (print_sockaddr_data_ll, print_inet_addr, print_sockaddr_data_in6): Likewise.
> * tests/sockaddr_xlat.c.c: New file.
> * tests/sockaddr_xlat-Xabbrev.c: Likewise.
> * tests/sockaddr_xlat-Xraw.c: Likewise.
> * tests/sockaddr_xlat-Xverbose.c: Likewise.
> * tests/gen_tests.in (sockaddr_xlat, sockaddr_xlat-Xabbrev, sockaddr_xlat-Xraw, sockaddr_xlat-Xverbose): New tests.
> * tests/pure_executables.list: Add sockaddr_xlat, sockaddr_xlat-Xabbrev, sockaddr_xlat-Xraw, sockaddr_xlat-Xverbose.
> * tests/.gitignore: Likewise.

Please try to wrap these lines so they won't exceed the limit of 72
symbols.

[...]
> @@ -378,11 +417,32 @@ static void
>  print_sockaddr_data_ll(const void *const buf, const int addrlen)
>  {
>  	const struct sockaddr_ll *const sa_ll = buf;
> +	int x_style = xlat_verbose(xlat_verbosity);
> +
> +	tprints("sll_protocol=");
> +	if (x_style != XLAT_STYLE_ABBREV)
> +		print_quoted_string(&sa_ll->sll_protocol,
> +					sizeof(sa_ll->sll_protocol),
> +					QUOTE_FORCE_HEX);
> +
> +	if (x_style == XLAT_STYLE_VERBOSE)
> +		tprints(" /* ");
> +
> +	if (x_style == XLAT_STYLE_VERBOSE
> +			|| x_style == XLAT_STYLE_ABBREV) {
> +		tprints("htons(");
> +		printxvals_ex(ntohs(sa_ll->sll_protocol),
> +				"ETH_P_???",
> +				XLAT_STYLE_ABBREV,
> +				ethernet_protocols,
> +				NULL);
> +		tprints(")");
> +	}
> +
> +	if (x_style == XLAT_STYLE_VERBOSE)
> +		tprints(" */");
>  
> -	tprints("sll_protocol=htons(");
> -	printxval_search(ethernet_protocols, ntohs(sa_ll->sll_protocol),
> -			 "ETH_P_???");
> -	PRINT_FIELD_IFINDEX("), ", *sa_ll, sll_ifindex);
> +	PRINT_FIELD_IFINDEX(", ", *sa_ll, sll_ifindex);
>  	tprints(", sll_hatype=");
>  	printxval_search(arp_hardware_types, sa_ll->sll_hatype, "ARPHRD_???");
>  	tprints(", sll_pkttype=");

I have problems compiling this hunk:

sockaddr.c: In function 'print_sockaddr_data_ll':
sockaddr.c:424:23: error: passing argument 1 of 'print_quoted_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
   print_quoted_string(&sa_ll->sll_protocol,
                       ^~~~~~~~~~~~~~~~~~~~
In file included from sockaddr.c:13:
defs.h:641:32: note: expected 'const char *' but argument is of type 'const __be16 *' {aka 'const short unsigned int *'}
 extern int print_quoted_string(const char *, unsigned int, unsigned int);
                                ^~~~~~~~~~~~

btw, could you create a new static function, e.g. print_sll_protocol,
and move this new code there, please?

[...]
> +	int ret = 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) = %d EBADF (%m)\n",

Here and in other similar places there is a chance that one of printf
statements will clobber errno and %m will print something unexpected.

I suggest introducing a new static wrapper function that will invoke
connect() and assign a variable (e.g. errstr as in many tests) that could
be used to print the error string.  Alternatively, you can assign this
variable manually after each connect() invocation.


-- 
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/f0720edf/attachment.bin>


More information about the Strace-devel mailing list