diff options
author | mlaier <mlaier@FreeBSD.org> | 2010-06-11 19:35:05 +0000 |
---|---|---|
committer | mlaier <mlaier@FreeBSD.org> | 2010-06-11 19:35:05 +0000 |
commit | 43cad37f433a21222f0841a55be848bf1a9d15ec (patch) | |
tree | f6c51b31a2eeb3a5d7a08ca6b676260cca88d55f /usr.sbin/arp/arp.c | |
parent | 324886002f85f17304dae0b8970911d2c9f1a6f4 (diff) | |
download | FreeBSD-src-43cad37f433a21222f0841a55be848bf1a9d15ec.zip FreeBSD-src-43cad37f433a21222f0841a55be848bf1a9d15ec.tar.gz |
Cache the last result from if_indextoname for printing. This speeds up
"arp -an" when using a lot of aliases (on a single interface).
A better fix would include a better interface for if_indextoname than
getting the whole address list from the kernel just to find the one
index->name mapping.
Reported & analyzed by: Nick Rogers
MFC after: 3 days
Diffstat (limited to 'usr.sbin/arp/arp.c')
-rw-r--r-- | usr.sbin/arp/arp.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c index a0e228c..2ee9d67 100644 --- a/usr.sbin/arp/arp.c +++ b/usr.sbin/arp/arp.c @@ -555,6 +555,9 @@ search(u_long addr, action_fn *action) /* * Display an arp entry */ +static char lifname[IF_NAMESIZE]; +static int64_t lifindex = -1; + static void print_entry(struct sockaddr_dl *sdl, struct sockaddr_inarp *addr, struct rt_msghdr *rtm) @@ -562,7 +565,6 @@ print_entry(struct sockaddr_dl *sdl, const char *host; struct hostent *hp; struct iso88025_sockaddr_dl_data *trld; - char ifname[IF_NAMESIZE]; int seg; if (nflag == 0) @@ -591,8 +593,12 @@ print_entry(struct sockaddr_dl *sdl, } } else printf("(incomplete)"); - if (if_indextoname(sdl->sdl_index, ifname) != NULL) - printf(" on %s", ifname); + if (sdl->sdl_index != lifindex && + if_indextoname(sdl->sdl_index, lifname) != NULL) { + lifindex = sdl->sdl_index; + printf(" on %s", lifname); + } else if (sdl->sdl_index == lifindex) + printf(" on %s", lifname); if (rtm->rtm_rmx.rmx_expire == 0) printf(" permanent"); else { |