From 3074e9622f75e1f2b3fb26800335865f87ef5a95 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 3 Apr 2009 20:29:22 +0000 Subject: Show interface description names in "systat if 1"; some help from canacar sthen likes it --- usr.bin/systat/if.c | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/systat/if.c b/usr.bin/systat/if.c index 2e56471f68f..4a855671113 100644 --- a/usr.bin/systat/if.c +++ b/usr.bin/systat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.12 2008/06/12 22:26:01 canacar Exp $ */ +/* $OpenBSD: if.c,v 1.13 2009/04/03 20:29:21 deraadt Exp $ */ /* * Copyright (c) 2004 Markus Friedl * @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,7 @@ struct ifcount { struct ifstat { char ifs_name[IFNAMSIZ]; /* interface name */ + char ifs_description[IFDESCRSIZE]; struct ifcount ifs_cur; struct ifcount ifs_old; struct ifcount ifs_now; @@ -64,7 +66,7 @@ static void showtotal(void); /* Define fields */ field_def fields_if[] = { {"IFACE", 8, 16, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, - {"STATE", 10, 16, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, + {"STATE", 4, 6, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, {"IPKTS", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"IBYTES", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"IERRS", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, @@ -72,6 +74,7 @@ field_def fields_if[] = { {"OBYTES", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"OERRS", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"COLLS", 5, 8, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"DESC", 14, 64, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, }; @@ -86,13 +89,14 @@ field_def fields_if[] = { #define FLD_IF_OBYTES FIELD_ADDR(6) #define FLD_IF_OERRS FIELD_ADDR(7) #define FLD_IF_COLLS FIELD_ADDR(8) +#define FLD_IF_DESC FIELD_ADDR(9) /* Define views */ field_def *view_if_0[] = { - FLD_IF_IFACE, FLD_IF_STATE, FLD_IF_IPKTS, FLD_IF_IBYTES, - FLD_IF_IERRS, FLD_IF_OPKTS, FLD_IF_OBYTES, FLD_IF_OERRS, - FLD_IF_COLLS, NULL + FLD_IF_IFACE, FLD_IF_STATE, FLD_IF_DESC, FLD_IF_IPKTS, + FLD_IF_IBYTES, FLD_IF_IERRS, FLD_IF_OPKTS, FLD_IF_OBYTES, + FLD_IF_OERRS, FLD_IF_COLLS, NULL }; /* Define view managers */ @@ -191,6 +195,7 @@ fetchifstat(void) struct sockaddr *info[RTAX_MAX]; struct sockaddr_dl *sdl; char *buf, *next, *lim; + static int s = -1; int mib[6]; size_t need; @@ -233,12 +238,31 @@ fetchifstat(void) rt_getaddrinfo( (struct sockaddr *)((struct if_msghdr *)next + 1), ifm.ifm_addrs, info); - if ((sdl = (struct sockaddr_dl *)info[RTAX_IFP])) { - if (sdl->sdl_family == AF_LINK && - sdl->sdl_nlen > 0) { - bcopy(sdl->sdl_data, ifs->ifs_name, - sdl->sdl_nlen); - ifs->ifs_name[sdl->sdl_nlen] = '\0'; + sdl = (struct sockaddr_dl *)info[RTAX_IFP]; + + if (sdl && sdl->sdl_family == AF_LINK && + sdl->sdl_nlen > 0) { + struct ifreq ifrdesc; + char ifdescr[IFDESCRSIZE]; + int s; + + bcopy(sdl->sdl_data, ifs->ifs_name, + sdl->sdl_nlen); + ifs->ifs_name[sdl->sdl_nlen] = '\0'; + + /* Get the interface description */ + memset(&ifrdesc, 0, sizeof(ifrdesc)); + strlcpy(ifrdesc.ifr_name, ifs->ifs_name, + sizeof(ifrdesc.ifr_name)); + ifrdesc.ifr_data = (caddr_t)&ifdescr; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s != -1) { + if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0) + strlcpy(ifs->ifs_description, + ifrdesc.ifr_data, + sizeof(ifs->ifs_description)); + close(s); } } if (ifs->ifs_name[0] == '\0') @@ -281,6 +305,8 @@ showifstat(struct ifstat *ifs) print_fld_tb(FLD_IF_STATE); + print_fld_str(FLD_IF_DESC, ifs->ifs_description); + print_fld_size(FLD_IF_IBYTES, ifs->ifs_cur.ifc_ib); print_fld_size(FLD_IF_IPKTS, ifs->ifs_cur.ifc_ip); print_fld_size(FLD_IF_IERRS, ifs->ifs_cur.ifc_ie); -- cgit v1.2.3