Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jul 2013 11:59:41 +0000 (UTC)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r253517 - head/sbin/route
Message-ID:  <201307211159.r6LBxfMd001975@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hrs
Date: Sun Jul 21 11:59:41 2013
New Revision: 253517
URL: http://svnweb.freebsd.org/changeset/base/253517

Log:
  - Fix nflag in routename().
  - Display a AF_LINK address in #linkN when sdl_{nlen,alen,slen) == 0 and
    sdl_index != 0.
  - Reduce unnecessary loop in pmsg_addrs().
  - Remove iso_ntoa().  This is not used.

Modified:
  head/sbin/route/route.c

Modified: head/sbin/route/route.c
==============================================================================
--- head/sbin/route/route.c	Sun Jul 21 10:48:50 2013	(r253516)
+++ head/sbin/route/route.c	Sun Jul 21 11:59:41 2013	(r253517)
@@ -120,7 +120,6 @@ static void	set_metric(char *, int);
 static int	set_sofib(int);
 static void	sockaddr(char *, struct sockaddr *, size_t);
 static void	sodump(struct sockaddr *, const char *);
-extern	char *iso_ntoa(void);
 
 struct fibl {
 	TAILQ_ENTRY(fibl)	fl_next;
@@ -493,6 +492,7 @@ retry:
 const char *
 routename(struct sockaddr *sa)
 {
+	struct sockaddr_dl *sdl;
 	const char *cp;
 	static char line[MAXHOSTNAMELEN + 1];
 #ifdef INET
@@ -523,7 +523,7 @@ routename(struct sockaddr *sa)
 		cp = NULL;
 		if (in.s_addr == INADDR_ANY && nflag == 0)
 			return ("default");
-		if (nflag != 0) {
+		if (nflag == 0) {
 			hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
 				AF_INET);
 			if (hp != NULL) {
@@ -574,7 +574,18 @@ routename(struct sockaddr *sa)
 		break;
 
 	case AF_LINK:
-		return (link_ntoa((struct sockaddr_dl *)(void *)sa));
+		sdl = (struct sockaddr_dl *)(void *)sa;
+
+		if (sdl->sdl_nlen == 0 &&
+		    sdl->sdl_alen == 0 &&
+		    sdl->sdl_slen == 0) {
+			n = snprintf(line, sizeof(line), "link#%d",
+			    sdl->sdl_index);
+			if (n > (int)sizeof(line))
+			    line[0] = '\0';
+			return (line);
+		} else
+			return (link_ntoa(sdl));
 		break;
 
 	default:
@@ -602,6 +613,7 @@ routename(struct sockaddr *sa)
 const char *
 netname(struct sockaddr *sa)
 {
+	struct sockaddr_dl *sdl;
 	static char line[MAXHOSTNAMELEN + 1];
 	int n;
 #ifdef INET
@@ -670,7 +682,18 @@ netname(struct sockaddr *sa)
 		break;
 
 	case AF_LINK:
-		return (link_ntoa((struct sockaddr_dl *)(void *)sa));
+		sdl = (struct sockaddr_dl *)(void *)sa;
+
+		if (sdl->sdl_nlen == 0 &&
+		    sdl->sdl_alen == 0 &&
+		    sdl->sdl_slen == 0) {
+			n = snprintf(line, sizeof(line), "link#%d",
+			    sdl->sdl_index);
+			if (n > (int)sizeof(line))
+			    line[0] = '\0';
+			return (line);
+		} else
+			return (link_ntoa(sdl));
 		break;
 
 	default:
@@ -1560,7 +1583,7 @@ print_rtmsg(struct rt_msghdr *rtm, size_
 		    rtm->rtm_version);
 		return;
 	}
-	if (rtm->rtm_type < sizeof(msgtypes) / sizeof(msgtypes[0]))
+	if (rtm->rtm_type < nitems(msgtypes))
 		(void)printf("%s: ", msgtypes[rtm->rtm_type]);
 	else
 		(void)printf("unknown type %d: ", rtm->rtm_type);
@@ -1660,6 +1683,7 @@ print_getmsg(struct rt_msghdr *rtm, int 
 	if (rtm->rtm_msglen > msglen) {
 		warnx("message length mismatch, in packet %d, returned %d",
 		      rtm->rtm_msglen, msglen);
+		return;
 	}
 	if (rtm->rtm_errno)  {
 		errno = rtm->rtm_errno;
@@ -1696,9 +1720,8 @@ print_getmsg(struct rt_msghdr *rtm, int 
 
 #define lock(f)	((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' ')
 #define msec(u)	(((u) + 500) / 1000)		/* usec to msec */
-
-	printf("\n%s\n", "\
- recvpipe  sendpipe  ssthresh  rtt,msec    mtu        weight    expire");
+	printf("\n%9s %9s %9s %9s %9s %10s %9s\n", "recvpipe",
+	    "sendpipe", "ssthresh", "rtt,msec", "mtu   ", "weight", "expire");
 	printf("%8ld%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
 	printf("%8ld%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
 	printf("%8ld%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
@@ -1749,8 +1772,8 @@ pmsg_addrs(char *cp, int addrs, size_t l
 	(void)printf("\nsockaddrs: ");
 	printb(addrs, addrnames);
 	putchar('\n');
-	for (i = 1; i != 0; i <<= 1)
-		if (i & addrs) {
+	for (i = 0; i < RTAX_MAX; i++)
+		if (addrs & (1 << i)) {
 			sa = (struct sockaddr *)cp;
 			if (len == 0 || len < SA_SIZE(sa)) {
 				(void)printf(errfmt, __func__, len);



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