[PATCH 2/2] DRY if_indextoname() logic
Ben Noordhuis
info at bnoordhuis.nl
Thu Feb 5 18:28:46 UTC 2015
* net.c (printsock): DRY if_indextoname() logic.
Signed-off-by: Ben Noordhuis <info at 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
More information about the Strace-devel
mailing list