net.c: do not print sockaddr_in6.sin6_scope_id unnecessarily
Prior to RFC2553, struct sockaddr_in6 had no sin6_scope_id field.
As the kernel still accepts RFC2133 editions of struct sockaddr_in6,
print sockaddr_in6.sin6_scope_id only when it is specified.
* net.c (SIN6_MIN_LEN): New macro.
(print_sockaddr_data_in6): Print sockaddr_in6.sin6_scope_id only when
socket address length exceeds SIN6_MIN_LEN.
diff --git a/net.c b/net.c
index 938b212..1654883 100644
--- a/net.c
+++ b/net.c
@@ -145,6 +145,8 @@
tprintf("%u", ifindex);
}
+#define SIN6_MIN_LEN offsetof(struct sockaddr_in6, sin6_scope_id)
+
static void
print_sockaddr_data_in6(const void *const buf, const int addrlen)
{
@@ -157,6 +159,10 @@
", \"%s\", &sin6_addr), sin6_flowinfo=%u",
ntohs(sa_in6->sin6_port), string_addr,
sa_in6->sin6_flowinfo);
+
+ if (addrlen <= (int) SIN6_MIN_LEN)
+ return;
+
tprints(", sin6_scope_id=");
#if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
if (IN6_IS_ADDR_LINKLOCAL(&sa_in6->sin6_addr)