Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Jul 2012 18:37:32 +0000
From:      exxo@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r239275 - soc2012/exxo/freebsd-head/usr.bin/systat
Message-ID:  <20120711183732.8CF54106566B@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: exxo
Date: Wed Jul 11 18:37:31 2012
New Revision: 239275
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239275

Log:
  Add IPV6 definitions to usr.bin/systat

Modified:
  soc2012/exxo/freebsd-head/usr.bin/systat/netcmds.c

Modified: soc2012/exxo/freebsd-head/usr.bin/systat/netcmds.c
==============================================================================
--- soc2012/exxo/freebsd-head/usr.bin/systat/netcmds.c	Wed Jul 11 17:11:54 2012	(r239274)
+++ soc2012/exxo/freebsd-head/usr.bin/systat/netcmds.c	Wed Jul 11 18:37:31 2012	(r239275)
@@ -63,7 +63,9 @@
 
 union storage_addr {
 	struct in_addr	in;
+#ifdef INET6
 	struct in6_addr in6;
+#endif
 };
 
 static	struct hitem {
@@ -134,7 +136,11 @@
 	struct servent *sp;
 	struct addrinfo hint, *res, *res0;
 	union storage_addr addr;
+#ifdef INET6
 	int family = AF_UNSPEC;
+#else
+	int family = AF_INET;
+#endif
 
 	tmpstr = tmpstr1 = strdup(args);
 	cp = strchr(tmpstr1, '\n');
@@ -154,10 +160,12 @@
 			family = AF_INET;
 			continue;
 		}
+#ifdef INET6
 		else if (streq(tmpstr1, "-6")) {
 			family = AF_INET6;
 			continue;
 		}
+#endif
 		sp = getservbyname(tmpstr1,
 		    protos == TCP ? "tcp" : protos == UDP ? "udp" : 0);
 		if (sp) {
@@ -179,11 +187,13 @@
 				    &((struct sockaddr_in *)res->ai_addr)->sin_addr,
 				    sizeof(addr.in));
 				break;
+#ifdef INET6
 			case AF_INET6 :
 				memcpy(&addr.in6,
 				    &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
 				    sizeof(addr.in6));
 				break;
+#endif
 			default :
 				continue;
 			}
@@ -285,7 +295,9 @@
 }
 
 #define af4cmp(x, y)	(memcmp(&x.s_addr, &y.s_addr, sizeof(x.s_addr))==0)
+#ifdef INET6
 #define af6cmp(x, y)	(memcmp(&x.s6_addr, &y.s6_addr, sizeof(x.s6_addr))==0)
+#endif
 
 static int
 selecthost(union storage_addr *addr, int family, int onoff)
@@ -300,8 +312,12 @@
 		return (1);
 	}
 	for (p = hosts; p < hosts+nhosts; p++)
+#ifdef INET6
 		if (p->family == family && family == AF_INET ?
 		    af4cmp(p->addr.in, addr->in) : af6cmp(p->addr.in6, addr->in6))
+#else
+		if (p->family == family && af4cmp(p->addr.in, addr->in))
+#endif
 		{
 			p->onoff = onoff;
 			return (0);
@@ -326,10 +342,11 @@
 	for (p = hosts; p < hosts+nhosts; p++)
 		if (((inp->inp_vflag & INP_IPV4) && p->family == AF_INET &&
 		    (af4cmp(p->addr.in, inp->inp_laddr) || af4cmp(p->addr.in, inp->inp_faddr)))
-		    ||
-		    ((inp->inp_vflag & INP_IPV6) && p->family == AF_INET6 &&
-		    (af6cmp(p->addr.in6, inp->in6p_laddr) || af6cmp(p->addr.in6, inp->in6p_faddr))))
-			return (p->onoff);
+#ifdef INET6
+		    || ((inp->inp_vflag & INP_IPV6) && p->family == AF_INET6 &&
+		    (af6cmp(p->addr.in6, inp->in6p_laddr) || af6cmp(p->addr.in6, inp->in6p_faddr)))
+#endif
+		    ) return (p->onoff);
 	return (1);
 }
 
@@ -340,7 +357,11 @@
 	struct hostent *hp;
 	const void *host;
 	socklen_t len;
+#ifdef INET6
 	char str[INET6_ADDRSTRLEN];
+#else
+	char str[INET_ADDRSTRLEN];
+#endif
 
 	for (p = hosts; p < hosts+nhosts; p++) {
 		switch (p->family) {
@@ -348,17 +369,23 @@
 			host = (const void *)&p->addr.in;
 			len = sizeof(p->addr.in);
 			break;
+#ifdef INET6
 		case AF_INET6 :
 			host = (const void *)&p->addr.in6;
 			len = sizeof(p->addr.in6);
 			break;
+#endif
 		default :
 			continue;
 		}
 		hp = gethostbyaddr(host, len, p->family);
 		if (!p->onoff)
 			addch('!');
+#ifdef INET6
 		printw("%s%s ", hp ? hp->h_name : (char *)inet_ntop(p->family, host, str, INET6_ADDRSTRLEN),
 		    p->family == AF_INET ? "(v4)" : "(v6)");
+#else
+		printw("%s ", hp ? hp->h_name : (char *)inet_ntoa(p->addr.in));
+#endif
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120711183732.8CF54106566B>