Subject: bin/6109: ifconfig doesn't print out ip aliases
To: None <gnats-bugs@gnats.netbsd.org>
From: Phil Nelson <phil@ldc.cs.wwu.edu>
List: netbsd-bugs
Date: 09/05/1998 21:49:47
>Number:         6109
>Category:       bin
>Synopsis:       ifconfig doesn't print out ip aliases
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Sep  5 22:05:00 1998
>Last-Modified:
>Originator:     Phil Nelson
>Organization:
	Western Washington University
>Release:        NetBSD-1.3.2
>Environment:
System: NetBSD nooksack 1.3.2 NetBSD 1.3.2 (NOOKSACK) #6: Fri Aug 28 10:38:26 PDT 1998 phil@phoenix:/usr/src/sys/arch/i386/compile/NOOKSACK i386


>Description:
	ifconfig does not print out the ip alias of any interface.
	Even with the -a option nothing appears.  (Repeat of PR1129
	but this has a "fix".)
>How-To-Repeat:
	add an ip alias to one interface
	ifconfig -a
>Fix:
	The following patch is relative to 1.3.2 release.  It does
	patch cleanly to -current version, but I don't have -current
	running to the point where I can test it.  If I get no objections
	before I get a -current version up and working to that point,
	I'll commit these changes and close this pr.

	The ip alias is printed only when invoked as "ifconfig -a".
	No netmask is printed with the ip alias.  (The alias shouldn't
	run with different netmask than the primary, should it?)

--- ifconfig.c.orig	Fri Sep  4 19:00:15 1998
+++ ifconfig.c	Sat Sep  5 20:43:26 1998
@@ -210,6 +210,7 @@
  * XNS support liberally adapted from code written at the University of
  * Maryland principally by James O'Toole and Chris Torek.
  */
+void	in_alias __P((struct ifreq *creq));
 void	in_status __P((int));
 void 	in_getaddr __P((char *, int));
 void	at_status __P((int));
@@ -486,8 +487,11 @@
 		if (ifr->ifr_addr.sa_family == AF_LINK)
 			sdl = (const struct sockaddr_dl *) &ifr->ifr_addr;
 		if (!strncmp(ifreq.ifr_name, ifr->ifr_name,
-			     sizeof(ifr->ifr_name)))
+			     sizeof(ifr->ifr_name))) {
+			if (ifr->ifr_addr.sa_family == AF_INET)
+				in_alias(ifr);
 			continue;
+		}
 		(void) strncpy(name, ifr->ifr_name, sizeof(ifr->ifr_name));
 		ifreq = *ifr;
 
@@ -1106,6 +1110,37 @@
 		ifr.ifr_addr.sa_family = p->af_af;
 		(*p->af_status)(0);
 	}
+}
+
+void
+in_alias(struct ifreq *creq)
+{
+	struct sockaddr_in *sin;
+
+	if (lflag)
+		return;
+
+	/* Get the non-alias address for this interface. */
+	getsock(AF_INET);
+	if (s < 0) {
+		if (errno == EPROTONOSUPPORT)
+			return;
+		err(1, "socket");
+	}
+	(void) memset(&ifr, 0, sizeof(ifr));
+	(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+	if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
+		if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
+			return;
+		} else
+			warn("SIOCGIFADDR");
+	}
+	/* If creq and ifr are the same address, this is not an alias. */
+	if (memcmp(&ifr.ifr_addr, &creq->ifr_addr,
+		   sizeof(creq->ifr_addr)) == 0)
+		return;
+	sin = (struct sockaddr_in *)&creq->ifr_addr;
+	printf("\tinet alias %s\n", inet_ntoa(sin->sin_addr));
 }
 
 void

>Audit-Trail:
>Unformatted: