summaryrefslogtreecommitdiff
path: root/usr.bin/systat
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-03 20:29:22 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-03 20:29:22 +0000
commit3074e9622f75e1f2b3fb26800335865f87ef5a95 (patch)
tree642ac3220f9973f5a850e359451531cd559a1a97 /usr.bin/systat
parent1cc692ac6f0ec73df29cdc29aeb0eac74a7cb407 (diff)
Show interface description names in "systat if 1"; some help from canacar
sthen likes it
Diffstat (limited to 'usr.bin/systat')
-rw-r--r--usr.bin/systat/if.c48
1 files changed, 37 insertions, 11 deletions
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 <markus@openbsd.org>
*
@@ -21,6 +21,7 @@
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
+#include <sys/sockio.h>
#include <stdlib.h>
#include <string.h>
@@ -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);