From 5d8eff0053a6e684ec22a570cc76fa1a5cc2af68 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 15 Jun 2001 20:47:01 +0000 Subject: [PATCH] Print symbolic names for appletalk ports. Also some very minor style 9 issues. PR: bin/4157 Submitted by: Denny Gentry --- usr.bin/netstat/atalk.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c index a8ddbcf70c47..fddda0c263f6 100644 --- a/usr.bin/netstat/atalk.c +++ b/usr.bin/netstat/atalk.c @@ -50,8 +50,9 @@ static const char rcsid[] = #include #include -#include #include +#include +#include #include #include #include "netstat.h" @@ -106,6 +107,7 @@ static char * at_pr_port(struct sockaddr_at *sat) { static char mybuf[50]; + struct servent *serv; switch(sat->sat_port) { case ATADDR_ANYPORT: @@ -113,7 +115,18 @@ static char mybuf[50]; case 0xff: return "????"; default: - sprintf(mybuf,"%d",(unsigned int)sat->sat_port); + if (nflag) { + (void)snprintf(mybuf, sizeof(mybuf), "%d", + (unsigned int)sat->sat_port); + } else { + serv = getservbyport(sat->sat_port, "ddp"); + if (serv == NULL) + (void)snprintf(mybuf, sizeof(mybuf), "%d", + (unsigned int) sat->sat_port); + else + (void) snprintf(mybuf, sizeof(mybuf), "%s", + serv->s_name); + } } return mybuf; }