From owner-p4-projects@FreeBSD.ORG Mon Jun 8 14:32:38 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 33BA61065672; Mon, 8 Jun 2009 14:32:35 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C51A1065670 for ; Mon, 8 Jun 2009 14:32:35 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E4E898FC14 for ; Mon, 8 Jun 2009 14:32:34 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n58EWYOV054676 for ; Mon, 8 Jun 2009 14:32:34 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n58EWYsa054674 for perforce@freebsd.org; Mon, 8 Jun 2009 14:32:34 GMT (envelope-from pgj@FreeBSD.org) Date: Mon, 8 Jun 2009 14:32:34 GMT Message-Id: <200906081432.n58EWYsa054674@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to pgj@FreeBSD.org using -f From: Gabor Pali To: Perforce Change Reviews Cc: Subject: PERFORCE change 163787 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2009 14:32:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=163787 Change 163787 by pgj@petymeg-current on 2009/06/08 14:32:21 - Add address properties (as a pure string) - unix.c now entirely uses libnetstat :) Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#8 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#11 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#8 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#10 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#10 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#8 (text+ko) ==== @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -72,7 +73,6 @@ stp = _netstat_st_allocate(list, PF_LOCAL, type, socktype[type]); extract_xunpcb_data(xunp, stp); - stp->xup = *((struct xunpcb *)xug); } } @@ -150,7 +150,6 @@ stp = _netstat_st_allocate(list, PF_LOCAL, type, socktype[type]); extract_xunpcb_data(&xu, stp); - stp->xup = xu; } return (0); @@ -225,6 +224,8 @@ void extract_xunpcb_data(struct xunpcb *xpcb, struct socket_type *stp) { + struct sockaddr_un *sa; + stp->st_qlen = xpcb->xu_socket.so_qlen; stp->st_incqlen = xpcb->xu_socket.so_incqlen; stp->st_qlimit = xpcb->xu_socket.so_qlimit; @@ -236,4 +237,12 @@ stp->st_refs = (long)LIST_FIRST(&xpcb->xu_unp.unp_refs); stp->st_reflink = (long)LIST_NEXT(&xpcb->xu_unp, unp_reflink); stp->st_flags = SOCKTYPE_VNODE | SOCKTYPE_CONN | SOCKTYPE_REFS; + if (xpcb->xu_unp.unp_addr) { + sa = (struct sockaddr_un *)&xpcb->xu_addr; + sprintf(stp->st_address, "%.*s", + (int)(sa->sun_len - offsetof(struct sockaddr_un, sun_path)), + sa->sun_path); + } else { + stp->st_address[0] = '\0'; + } } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#11 (text+ko) ==== @@ -2,11 +2,13 @@ #ifndef _NETSTAT_H_ #define _NETSTAT_H_ +#include #include #define NETSTAT_MAXCALLER 16 #define SOCKTYPE_MAXNAME 32 +#define SOCKTYPE_MAXADDR SOCK_MAXADDRLEN #define NETSTAT_ERROR_UNDEFINED 0 #define NETSTAT_ERROR_NOMEMORY 1 @@ -64,10 +66,7 @@ long netstat_st_get_conn(const struct socket_type *stp); long netstat_st_get_refs(const struct socket_type *stp); long netstat_st_get_reflink(const struct socket_type *stp); - -/* XXX: Remove this hack :) */ -void *XXX_netstat_st_get_pcb(const struct socket_type *stp); - +const char *netstat_st_get_address(const struct socket_type *stp); __END_DECLS #endif /* !_NETSTAT_H_ */ ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#8 (text+ko) ==== @@ -10,6 +10,7 @@ #include #include +/* XXX: not used yet */ /* Address type: * local, foreign, node (Netgraph), raw (domain) */ @@ -26,8 +27,11 @@ int st_flags; char st_name[SOCKTYPE_MAXNAME]; +#if 0 + /* XXX: not used yet */ struct address_type *st_address; /* address(es) */ int st_addrcnt; /* address count */ +#endif u_int st_snd_cc; /* actual chars in the send buffer */ u_int st_rcv_cc; /* actual chars in the receive buffer */ @@ -40,11 +44,7 @@ long st_conn; /* control block of connected socket */ long st_refs; /* referencing socket linked list */ long st_reflink; /* link in references list */ - - /* Mixed properties, needed for different reasons, to be refined - * continuously. - */ - struct xunpcb xup; /* xun */ + char st_address[SOCKTYPE_MAXADDR]; /* list of types */ LIST_ENTRY(socket_type) st_list; ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#10 (text+ko) ==== @@ -312,9 +312,8 @@ return (stp->st_reflink); } -/* XXX: hack alert :) */ -void * -XXX_netstat_st_get_pcb(const struct socket_type *stp) +const char * +netstat_st_get_address(const struct socket_type *stp) { - return (void *)(&stp->xup); + return (stp->st_address); } ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#10 (text+ko) ==== @@ -43,27 +43,14 @@ /* * Display protocol blocks in the unix domain. */ -#include -#include -#include -#include +#include #include -#include -#include -#include -#include - -#include - -#include +#include #include -#include -#include +#include +#include #include #include -#include -#include -#include #include "extern.h" #define USE_ITERATOR_TYPE @@ -126,21 +113,9 @@ static void unixdomainpr(struct socket_type *stp) { - struct unpcb *unp; - struct sockaddr_un *sa; static int first = 1; char buf1[15]; - struct xunpcb *xunp; - struct xsocket *so; - xunp = XXX_netstat_st_get_pcb(stp); - so = &xunp->xu_socket; - unp = &xunp->xu_unp; - if (unp->unp_addr) - sa = &xunp->xu_addr; - else - sa = (struct sockaddr_un *)0; - if (first && !Lflag) { printf("Active UNIX domain sockets\n"); printf( @@ -164,9 +139,5 @@ netstat_st_get_vnode(stp), netstat_st_get_conn(stp), netstat_st_get_refs(stp), netstat_st_get_reflink(stp)); } - if (sa) - printf(" %.*s", - (int)(sa->sun_len - offsetof(struct sockaddr_un, sun_path)), - sa->sun_path); - putchar('\n'); + printf(" %s\n", netstat_st_get_address(stp)); }