Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/fstat Resolve names of datagram services correctly.



details:   https://anonhg.NetBSD.org/src/rev/51ef7f696c45
branches:  trunk
changeset: 336632:51ef7f696c45
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Mar 08 06:46:51 2015 +0000

description:
Resolve names of datagram services correctly.

diffstat:

 usr.bin/fstat/fstat.c |  37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diffs (123 lines):

diff -r e05fb54906c7 -r 51ef7f696c45 usr.bin/fstat/fstat.c
--- a/usr.bin/fstat/fstat.c     Sun Mar 08 04:21:41 2015 +0000
+++ b/usr.bin/fstat/fstat.c     Sun Mar 08 06:46:51 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $     */
+/*     $NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)fstat.c    8.3 (Berkeley) 5/2/95";
 #else
-__RCSID("$NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $");
+__RCSID("$NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -165,10 +165,10 @@
 static int     msdosfs_filestat(struct vnode *, struct filestat *);
 static int     nfs_filestat(struct vnode *, struct filestat *);
 static const char *inet_addrstr(char *, size_t, const struct in_addr *,
-    uint16_t);
+    uint16_t, bool);
 #ifdef INET6
 static const char *inet6_addrstr(char *, size_t, const struct in6_addr *,
-    uint16_t);
+    uint16_t, bool);
 #endif
 static const char *at_addrstr(char *, size_t, const struct sockaddr_at *);
 static void    socktrans(struct socket *, int);
@@ -877,11 +877,14 @@
 }
 
 static const char *
-inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p)
+inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p, bool isdg)
 {
        char addr[256], serv[256];
        struct sockaddr_in sin;
-       const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0;
+       const int niflags =
+               (nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0) |
+               (isdg ? NI_DGRAM : 0);
+
 
        (void)memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
@@ -914,11 +917,13 @@
 
 #ifdef INET6
 static const char *
-inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p)
+inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p, bool isdg)
 {
        char addr[256], serv[256];
        struct sockaddr_in6 sin6;
-       const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0;
+       const int niflags =
+               (nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0) |
+               (isdg ? NI_DGRAM : 0);
 
        (void)memset(&sin6, 0, sizeof(sin6));
        sin6.sin6_family = AF_INET6;
@@ -1010,6 +1015,7 @@
        int len;
        char dname[32];
        char lbuf[512], fbuf[512], pbuf[24];
+       bool isdgram;
 
        pbuf[0] = '\0';
        /* fill in socket */
@@ -1054,12 +1060,14 @@
         */
        fbuf[0] = '\0';
        lbuf[0] = '\0';
+       isdgram = false;
        switch(dom.dom_family) {
        case AF_INET:
                getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol);
                switch (proto.pr_protocol) {
+               case IPPROTO_UDP:
+                       isdgram = true;
                case IPPROTO_TCP:
-               case IPPROTO_UDP:
                        if (so.so_pcb == NULL)
                                break;
                        if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb,
@@ -1068,9 +1076,9 @@
                                goto bad;
                        }
                        inet_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr,
-                           ntohs(inpcb.inp_lport));
+                           ntohs(inpcb.inp_lport), isdgram);
                        inet_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr,
-                           ntohs(inpcb.inp_fport));
+                           ntohs(inpcb.inp_fport), isdgram);
                        break;
                default:
                        break;
@@ -1080,8 +1088,9 @@
        case AF_INET6:
                getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol);
                switch (proto.pr_protocol) {
+               case IPPROTO_UDP:
+                       isdgram = true;
                case IPPROTO_TCP:
-               case IPPROTO_UDP:
                        if (so.so_pcb == NULL)
                                break;
                        if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb,
@@ -1090,9 +1099,9 @@
                                goto bad;
                        }
                        inet6_addrstr(lbuf, sizeof(lbuf), &in6pcb.in6p_laddr,
-                           ntohs(in6pcb.in6p_lport));
+                           ntohs(in6pcb.in6p_lport), isdgram);
                        inet6_addrstr(fbuf, sizeof(fbuf), &in6pcb.in6p_faddr,
-                           ntohs(in6pcb.in6p_fport));
+                           ntohs(in6pcb.in6p_fport), isdgram);
                        break;
                default:
                        break;



Home | Main Index | Thread Index | Old Index