PERFORCE change 163787 for review
Gabor Pali
pgj at FreeBSD.org
Mon Jun 8 14:32:38 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163787
Change 163787 by pgj at 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 <sys/types.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/stddef.h>
#include <sys/sysctl.h>
#include <sys/un.h>
#include <sys/unpcb.h>
@@ -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 <sys/socket.h>
#include <sys/sockbuf.h>
#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 <sys/unpcb.h>
#include <kvm.h>
+/* 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 <sys/param.h>
-#include <sys/queue.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
+#include <sys/types.h>
#include <sys/socketvar.h>
-#include <sys/mbuf.h>
-#include <sys/sysctl.h>
-#include <sys/un.h>
-#include <sys/unpcb.h>
-
-#include <netinet/in.h>
-
-#include <errno.h>
+#include <sys/stdint.h>
#include <err.h>
-#include <stddef.h>
-#include <stdint.h>
+#include <kvm.h>
+#include <netstat.h>
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
-#include <kvm.h>
-#include <netstat.h>
#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));
}
More information about the p4-projects
mailing list