* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
* Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
* Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016-2017 The strace developers.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
const unsigned int len,
const char *const var_name)
{
- const char *af_name = NULL;
char buf[INET6_ADDRSTRLEN];
switch (af) {
case AF_INET:
- af_name = "AF_INET";
+ if (inet_ntop(af, addr, buf, sizeof(buf))) {
+ if (var_name)
+ tprintf("%s=inet_addr(\"%s\")", var_name, buf);
+ else
+ tprints(buf);
+ return true;
+ }
break;
case AF_INET6:
- af_name = "AF_INET6";
+ if (inet_ntop(af, addr, buf, sizeof(buf))) {
+ if (var_name)
+ tprintf("inet_pton(%s, \"%s\", &%s)",
+ "AF_INET6", buf, var_name);
+ else
+ tprints(buf);
+ return true;
+ }
break;
}
- if (af_name && inet_ntop(af, addr, buf, sizeof(buf))) {
- tprintf("inet_pton(%s, \"%s\", &%s)", af_name, buf, var_name);
- return true;
- } else {
+ if (var_name)
tprintf("%s=", var_name);
- print_quoted_string(addr, len, 0);
+ print_quoted_string(addr, len, QUOTE_FORCE_HEX);
+ return false;
+}
+
+bool
+decode_inet_addr(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const int family,
+ const char *const var_name)
+{
+ union {
+ struct in_addr a4;
+ struct in6_addr a6;
+ } addrbuf;
+ size_t size = 0;
+
+ switch (family) {
+ case AF_INET:
+ size = sizeof(addrbuf.a4);
+ break;
+ case AF_INET6:
+ size = sizeof(addrbuf.a6);
+ break;
+ }
+
+ if (!size || len < size) {
+ if (var_name)
+ tprintf("%s=", var_name);
+ printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
return false;
}
+
+ if (umoven(tcp, addr, size, &addrbuf) < 0) {
+ if (var_name)
+ tprintf("%s=", var_name);
+ printaddr(addr);
+ return false;
+ }
+
+ return print_inet_addr(family, &addrbuf, size, var_name);
}
static void
tprintf("%s%#02x", i ? ", " : "",
sa_ipx->sipx_node[i]);
}
- tprintf("], sipx_type=%#02x", sa_ipx->sipx_type);
+ PRINT_FIELD_0X("], ", *sa_ipx, sipx_type);
}
static void
{
const struct sockaddr_nl *const sa_nl = buf;
- tprintf("nl_pid=%d, nl_groups=%#08x",
- sa_nl->nl_pid, sa_nl->nl_groups);
+ PRINT_FIELD_D("", *sa_nl, nl_pid);
+ PRINT_FIELD_0X(", ", *sa_nl, nl_groups);
}
static void