summaryrefslogtreecommitdiff
path: root/usr.bin/sockstat
diff options
context:
space:
mode:
authorpooka <pooka@NetBSD.org>2011-01-28 18:52:48 +0000
committerpooka <pooka@NetBSD.org>2011-01-28 18:52:48 +0000
commitc0442ec123627f87f1ab754dbe158c95dccfaac7 (patch)
treebd2ec7d1883180c293eb0b004f999b13df70f6ae /usr.bin/sockstat
parent9d4578348896f806b04fe10378ce4381d5b53893 (diff)
support rump.sockstat
Diffstat (limited to 'usr.bin/sockstat')
-rw-r--r--usr.bin/sockstat/Makefile8
-rw-r--r--usr.bin/sockstat/prog_ops.h50
-rw-r--r--usr.bin/sockstat/sockstat.c13
-rw-r--r--usr.bin/sockstat/sockstat_hostops.c41
-rw-r--r--usr.bin/sockstat/sockstat_rumpops.c45
5 files changed, 151 insertions, 6 deletions
diff --git a/usr.bin/sockstat/Makefile b/usr.bin/sockstat/Makefile
index 79e9fdd7ada..a649110f71b 100644
--- a/usr.bin/sockstat/Makefile
+++ b/usr.bin/sockstat/Makefile
@@ -1,8 +1,12 @@
-# $NetBSD: Makefile,v 1.2 2005/08/10 20:32:57 rpaulo Exp $
+# $NetBSD: Makefile,v 1.3 2011/01/28 18:52:49 pooka Exp $
.include <bsd.own.mk>
-PROG= sockstat
+RUMPPRG= sockstat
+
+.PATH: ${.CURDIR}/../../lib/libc/gen
+CPPFLAGS+= -DRUMP_ACTION
+RUMPSRCS+= sysctlgetmibinfo.c sysctlnametomib.c
.if (${USE_INET6} != "no")
CPPFLAGS+=-DINET6
diff --git a/usr.bin/sockstat/prog_ops.h b/usr.bin/sockstat/prog_ops.h
new file mode 100644
index 00000000000..2039a89ccde
--- /dev/null
+++ b/usr.bin/sockstat/prog_ops.h
@@ -0,0 +1,50 @@
+/* $NetBSD: prog_ops.h,v 1.1 2011/01/28 18:52:49 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PROG_OPS_H_
+#define _PROG_OPS_H_
+
+#include <sys/types.h>
+
+#ifndef CRUNCHOPS
+struct prog_ops {
+ int (*op_init)(void);
+
+ int (*op_sysctl)(const int *, u_int, void *, size_t *,
+ const void *, size_t);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_sysctl prog_ops.op_sysctl
+#else
+#define prog_init ((int (*)(void))NULL)
+#define prog_sysctl sysctl
+#endif
+
+#endif /* _PROG_OPS_H_ */
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index ebc1f8a5a9a..0a9f1b1e6fb 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sockstat.c,v 1.15 2009/04/13 10:56:56 lukem Exp $ */
+/* $NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: sockstat.c,v 1.15 2009/04/13 10:56:56 lukem Exp $");
+__RCSID("$NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $");
#endif
#include <sys/types.h>
@@ -67,6 +67,8 @@ __RCSID("$NetBSD: sockstat.c,v 1.15 2009/04/13 10:56:56 lukem Exp $");
#include <unistd.h>
#include <util.h>
+#include "prog_ops.h"
+
#define satosun(sa) ((struct sockaddr_un *)(sa))
#define satosin(sa) ((struct sockaddr_in *)(sa))
#ifdef INET6
@@ -172,6 +174,9 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
+ if (prog_init && prog_init() == -1)
+ err(1, "init");
+
if ((portmap != NULL) && (pf_list == 0)) {
pf_list = PF_LIST_INET;
#ifdef INET6
@@ -355,7 +360,7 @@ sysctl_sucker(int *name, u_int namelen, void **vp, size_t *szp)
v = NULL;
sz = 0;
do {
- rc = sysctl(&name[0], namelen, v, &sz, NULL, 0);
+ rc = prog_sysctl(&name[0], namelen, v, &sz, NULL, 0);
if (rc == -1 && errno != ENOMEM)
err(1, "sysctl");
if (rc == -1 && v != NULL) {
@@ -534,7 +539,7 @@ get_proc(struct kinfo_proc2 *p, int pid)
name[namelen++] = sz;
name[namelen++] = 1;
- return (sysctl(&name[0], namelen, p, &sz, NULL, 0));
+ return (prog_sysctl(&name[0], namelen, p, &sz, NULL, 0));
}
int
diff --git a/usr.bin/sockstat/sockstat_hostops.c b/usr.bin/sockstat/sockstat_hostops.c
new file mode 100644
index 00000000000..dc0a1c5c865
--- /dev/null
+++ b/usr.bin/sockstat/sockstat_hostops.c
@@ -0,0 +1,41 @@
+/* $NetBSD: sockstat_hostops.c,v 1.1 2011/01/28 18:52:49 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: sockstat_hostops.c,v 1.1 2011/01/28 18:52:49 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_sysctl = sysctl,
+};
diff --git a/usr.bin/sockstat/sockstat_rumpops.c b/usr.bin/sockstat/sockstat_rumpops.c
new file mode 100644
index 00000000000..fabc1630a0a
--- /dev/null
+++ b/usr.bin/sockstat/sockstat_rumpops.c
@@ -0,0 +1,45 @@
+/* $NetBSD: sockstat_rumpops.c,v 1.1 2011/01/28 18:52:49 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: sockstat_rumpops.c,v 1.1 2011/01/28 18:52:49 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_init = rumpclient_init,
+
+ .op_sysctl = rump_sys___sysctl,
+};