summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/main.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-10-22 16:40:25 +0000
committerguenther <guenther@openbsd.org>2013-10-22 16:40:25 +0000
commitcef0bbe1cc5517635356b7faa348b466660ec603 (patch)
tree8a975e0739a2b36fd5200d33c430980754b92498 /usr.bin/netstat/main.c
parent- expand hardware list with iMX boards (diff)
downloadwireguard-openbsd-cef0bbe1cc5517635356b7faa348b466660ec603.tar.xz
wireguard-openbsd-cef0bbe1cc5517635356b7faa348b466660ec603.zip
- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that - delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major) - rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file and KERN_FILE2 to KERN_FILE. ok deraadt@, millert@ ports scan sthen@
Diffstat (limited to 'usr.bin/netstat/main.c')
-rw-r--r--usr.bin/netstat/main.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 88c0c694a64..9b2b62e4310 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.95 2013/03/20 15:23:37 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.96 2013/10/22 16:40:28 guenther Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -31,7 +31,6 @@
*/
#include <sys/param.h>
-#include <sys/file.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
@@ -42,6 +41,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
#include <netdb.h>
@@ -162,6 +162,7 @@ main(int argc, char *argv[])
u_int tableid;
int Tflag = 0;
int repeatcount = 0;
+ int need_nlist;
hideroot = getuid();
@@ -331,6 +332,10 @@ main(int argc, char *argv[])
}
#endif
+ need_nlist = !mflag && (pflag || nlistf != NULL || memf != NULL ||
+ (!iflag && !sflag && (rflag ? Aflag :
+ (gflag || af != AF_UNIX || Pflag))));
+
/*
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
@@ -341,8 +346,8 @@ main(int argc, char *argv[])
if (setresgid(gid, gid, gid) == -1)
err(1, "setresgid");
- if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
- buf)) == NULL) {
+ if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY |
+ (need_nlist ? 0 : KVM_NO_FILES), buf)) == NULL) {
fprintf(stderr, "%s: kvm_openfiles: %s\n", __progname, buf);
exit(1);
}
@@ -351,7 +356,7 @@ main(int argc, char *argv[])
if (setresgid(gid, gid, gid) == -1)
err(1, "setresgid");
- if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) {
+ if (need_nlist && (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0)) {
if (nlistf)
fprintf(stderr, "%s: %s: no namelist\n", __progname,
nlistf);
@@ -429,7 +434,7 @@ main(int argc, char *argv[])
printproto(tp, tp->pr_name, AF_INET6, tableid,
pcbaddr);
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
- unixpr(nl[N_UNIXSW].n_value, pcbaddr);
+ unixpr(kvmd, pcbaddr);
exit(0);
}