* net.c (printsock): DRY if_indextoname() logic. Signed-off-by: Ben Noordhuis <i...@bnoordhuis.nl> --- net.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/net.c b/net.c index f55c6af..ca108e1 100644 --- a/net.c +++ b/net.c @@ -200,6 +200,9 @@ # include "xlat/af_packet_types.h" #endif +static void +print_interface(unsigned int index); + void printsock(struct tcb *tcp, long addr, int addrlen) { @@ -279,29 +282,14 @@ printsock(struct tcb *tcp, long addr, int addrlen) ntohs(addrbuf.sa6.sin6_port), string_addr, addrbuf.sa6.sin6_flowinfo); #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - { -#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL) - int numericscope = 0; - if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr) - || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) { - char scopebuf[IFNAMSIZ + 1]; - - if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL) - numericscope++; - else { - tprints(", sin6_scope_id=if_nametoindex("); - print_quoted_string(scopebuf, - sizeof(scopebuf), - QUOTE_0_TERMINATED); - tprints(")"); - } - } else - numericscope++; - - if (numericscope) -#endif - tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id); - } + tprints(", sin6_scope_id="); +#if defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL) + if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr) + || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) + print_interface(addrbuf.sa6.sin6_scope_id); + else +#endif + tprintf("%u", addrbuf.sa6.sin6_scope_id); #endif break; #endif -- 2.1.0 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel