Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/netstat print multiple tags if exists, comma separated
details: https://anonhg.NetBSD.org/src/rev/9cc620ec7940
branches: trunk
changeset: 766403:9cc620ec7940
user: kefren <kefren%NetBSD.org@localhost>
date: Tue Jun 21 19:42:45 2011 +0000
description:
print multiple tags if exists, comma separated
diffstat:
usr.bin/netstat/netstat.h | 4 +++-
usr.bin/netstat/route.c | 18 ++++++++++--------
usr.bin/netstat/show.c | 36 +++++++++++++++++++++---------------
3 files changed, 34 insertions(+), 24 deletions(-)
diffs (127 lines):
diff -r ac39732a53bd -r 9cc620ec7940 usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Tue Jun 21 18:13:19 2011 +0000
+++ b/usr.bin/netstat/netstat.h Tue Jun 21 19:42:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netstat.h,v 1.42 2011/05/03 18:28:46 dyoung Exp $ */
+/* $NetBSD: netstat.h,v 1.43 2011/06/21 19:42:45 kefren Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -175,4 +175,6 @@
kvm_t *get_kvmd(void);
+char *mpls_ntoa(const struct sockaddr *);
+
#define PLEN (LONG_BIT / 4 + 2)
diff -r ac39732a53bd -r 9cc620ec7940 usr.bin/netstat/route.c
--- a/usr.bin/netstat/route.c Tue Jun 21 18:13:19 2011 +0000
+++ b/usr.bin/netstat/route.c Tue Jun 21 19:42:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $ */
+/* $NetBSD: route.c,v 1.78 2011/06/21 19:42:45 kefren Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-__RCSID("$NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $");
+__RCSID("$NetBSD: route.c,v 1.78 2011/06/21 19:42:45 kefren Exp $");
#endif
#endif /* not lint */
@@ -270,13 +270,15 @@
putchar((rt->rt_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
if (tagflag == 1) {
if (rt->rt_tag != NULL) {
- const struct sockaddr_mpls *sampls =
- (const struct sockaddr_mpls*)kgetsa(rt->rt_tag);
- union mpls_shim shim;
+ const struct sockaddr *tagsa = kgetsa(rt->rt_tag);
+ char *tagstr;
- if (sampls->smpls_family == AF_MPLS) {
- shim.s_addr = ntohl(sampls->smpls_addr.s_addr);
- printf("%7d", shim.shim.label);
+ if (tagsa->sa_family == AF_MPLS) {
+ tagstr = mpls_ntoa(tagsa);
+ if (strlen(tagstr) < 7)
+ printf("%7s", tagstr);
+ else
+ printf("%s", tagstr);
}
else
printf("%7s", "-");
diff -r ac39732a53bd -r 9cc620ec7940 usr.bin/netstat/show.c
--- a/usr.bin/netstat/show.c Tue Jun 21 18:13:19 2011 +0000
+++ b/usr.bin/netstat/show.c Tue Jun 21 19:42:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.13 2011/02/04 14:31:23 martin Exp $ */
+/* $NetBSD: show.c,v 1.14 2011/06/21 19:42:45 kefren Exp $ */
/* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */
/*
@@ -61,7 +61,6 @@
char *any_ntoa(const struct sockaddr *);
char *link_print(struct sockaddr *);
-char *mpls_ntoa(const struct sockaddr *);
#define PFKEYV2_CHUNK sizeof(u_int64_t)
@@ -382,17 +381,17 @@
static void
p_tag(const struct sockaddr *sa)
{
- const struct sockaddr_mpls *sampls =
- (const struct sockaddr_mpls *)sa;
- union mpls_shim mshim;
+ char *line;
if (sa == NULL || sa->sa_family != AF_MPLS) {
printf("%7s", "-");
return;
}
-
- mshim.s_addr = ntohl(sampls->smpls_addr.s_addr);
- printf("%7d", mshim.shim.label);
+ line = mpls_ntoa(sa);
+ if (strlen(line) < 7)
+ printf("%7s", line);
+ else
+ printf("%s", line);
}
static char line[MAXHOSTNAMELEN];
@@ -718,15 +717,22 @@
char *
mpls_ntoa(const struct sockaddr *sa)
{
- static char obuf[100];
- const struct sockaddr_mpls *sm;
+ static char obuf[16];
+ const union mpls_shim *pms;
union mpls_shim ms;
+ int psize = sizeof(struct sockaddr_mpls);
+
+ pms = &((const struct sockaddr_mpls*)sa)->smpls_addr;
+ ms.s_addr = ntohl(pms->s_addr);
- sm = (const struct sockaddr_mpls*)sa;
- ms.s_addr = ntohl(sm->smpls_addr.s_addr);
+ snprintf(obuf, sizeof(obuf), "%u", ms.shim.label);
- snprintf(obuf, sizeof(obuf), "%u",
- ms.shim.label);
-
+ while(psize < sa->sa_len) {
+ pms++;
+ ms.s_addr = ntohl(pms->s_addr);
+ snprintf(obuf, sizeof(obuf), "%s,%u", obuf,
+ ms.shim.label);
+ psize+=sizeof(ms);
+ }
return obuf;
}
Home |
Main Index |
Thread Index |
Old Index