From f1e94c6f29b079e4ad9d9305ef3e90a719bcbbda Mon Sep 17 00:00:00 2001 From: brooks Date: Fri, 31 Oct 2003 18:32:15 +0000 Subject: Replace the if_name and if_unit members of struct ifnet with new members if_xname, if_dname, and if_dunit. if_xname is the name of the interface and if_dname/unit are the driver name and instance. This change paves the way for interface renaming and enhanced pseudo device creation and configuration symantics. Approved By: re (in principle) Reviewed By: njl, imp Tested On: i386, amd64, sparc64 Obtained From: NetBSD (if_xname) --- usr.bin/netstat/if.c | 18 ++++++------------ usr.bin/netstat/route.c | 9 ++------- 2 files changed, 8 insertions(+), 19 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index e563907..b2527cd 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -169,7 +169,7 @@ intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) short timer; int drops; struct sockaddr *sa = NULL; - char name[32], tname[16]; + char name[IFNAMSIZ]; short network_layer; short link_layer; @@ -216,13 +216,10 @@ intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) if (ifaddraddr == 0) { ifnetfound = ifnetaddr; - if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || - kread((u_long)ifnet.if_name, tname, 16)) + if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) return; - tname[sizeof(tname) - 1] = '\0'; + strlcpy(name, ifnet.if_xname, sizeof(name)); ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); - snprintf(name, sizeof(name), "%s%d", tname, - ifnet.if_unit); if (interface != 0 && (strcmp(name, interface) != 0)) continue; cp = index(name, '\0'); @@ -464,7 +461,7 @@ intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) struct iftot { SLIST_ENTRY(iftot) chain; - char ift_name[16]; /* interface name */ + char ift_name[IFNAMSIZ]; /* interface name */ u_long ift_ip; /* input packets */ u_long ift_ie; /* input errors */ u_long ift_op; /* output packets */ @@ -508,14 +505,11 @@ sidewaysintpr(unsigned interval1, u_long off) interesting = NULL; interesting_off = 0; for (off = firstifnet, ip = iftot; off;) { - char name[16], tname[16]; + char name[IFNAMSIZ]; if (kread(off, (char *)&ifnet, sizeof ifnet)) break; - if (kread((u_long)ifnet.if_name, tname, sizeof(tname))) - break; - tname[sizeof(tname) - 1] = '\0'; - snprintf(name, sizeof(name), "%s%d", tname, ifnet.if_unit); + strlcpy(name, ifnet.if_xname, sizeof(name)); if (interface && strcmp(name, interface) == 0) { interesting = ip; interesting_off = off; diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index a61fb17..3dcd910 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -329,12 +329,9 @@ size_cols_rtentry(struct rtentry *rt) } if (rt->rt_ifp) { if (rt->rt_ifp != lastif) { - len = snprintf(buffer, sizeof(buffer), "%d", - ifnet.if_unit); kget(rt->rt_ifp, ifnet); - kread((u_long)ifnet.if_name, buffer, sizeof(buffer)); lastif = rt->rt_ifp; - len += strlen(buffer); + len = strlen(ifnet.if_xname); wid_if = MAX(len, wid_if); } if (rt->rt_rmx.rmx_expire) { @@ -750,10 +747,8 @@ p_rtentry(struct rtentry *rt) if (rt->rt_ifp) { if (rt->rt_ifp != lastif) { kget(rt->rt_ifp, ifnet); - kread((u_long)ifnet.if_name, buffer, sizeof(buffer)); lastif = rt->rt_ifp; - snprintf(prettyname, sizeof(prettyname), - "%s%d", buffer, ifnet.if_unit); + strlcpy(prettyname, ifnet.if_xname, sizeof(prettyname)); } printf("%*.*s", wid_if, wid_if, prettyname); if (rt->rt_rmx.rmx_expire) { -- cgit v1.1