summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2020-09-14 15:12:28 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2020-09-14 15:12:28 +0000
commit0a35da9f3c72c706abbd0d45964338634cae333c (patch)
tree702f5bbeaea97c45427b61d1de90e9a805f4ccac
parentb30b7cf88b2e2d7d1d6e2dc8398dbe872f58677d (diff)
Allow snmp mibtree to take one or more arguments who will be converted to
an output format of your choosing. OK deraadt@ jan@
-rw-r--r--usr.bin/snmp/snmp.111
-rw-r--r--usr.bin/snmp/snmpc.c24
2 files changed, 27 insertions, 8 deletions
diff --git a/usr.bin/snmp/snmp.1 b/usr.bin/snmp/snmp.1
index 678893e95b7..db0214060bc 100644
--- a/usr.bin/snmp/snmp.1
+++ b/usr.bin/snmp/snmp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: snmp.1,v 1.14 2020/08/08 07:11:47 martijn Exp $
+.\" $OpenBSD: snmp.1,v 1.15 2020/09/14 15:12:27 martijn Exp $
.\"
.\" Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 8 2020 $
+.Dd $Mdocdate: September 14 2020 $
.Dt SNMP 1
.Os
.Sh NAME
@@ -49,6 +49,7 @@
.Nm
.Cm mibtree
.Op Fl O Ar fns
+.Op Ar oid ...
.Sh DESCRIPTION
The
.Nm
@@ -165,8 +166,12 @@ An SNMP based version of the
.Xr df 1
command.
If no size suffix is shown the sizes are in kilobytes.
-.It Nm Cm mibtree Op Fl O Ar fnS
+.It Nm Cm mibtree Oo Fl O Ar fnS Oc Op Ar oid ...
Dump the tree of compiled-in MIB objects.
+If
+.Ar oid
+is specified it wil print the objects in the requested output format if
+available, or print a warning if the object can't be found.
.El
.Pp
The
diff --git a/usr.bin/snmp/snmpc.c b/usr.bin/snmp/snmpc.c
index b00ce2f8e2a..e9d848b4914 100644
--- a/usr.bin/snmp/snmpc.c
+++ b/usr.bin/snmp/snmpc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpc.c,v 1.29 2020/09/12 18:11:43 martijn Exp $ */
+/* $OpenBSD: snmpc.c,v 1.30 2020/09/14 15:12:27 martijn Exp $ */
/*
* Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
@@ -80,7 +80,7 @@ struct snmp_app snmp_apps[] = {
{ "set", 1, NULL, "agent oid type value [oid type value] ...", snmpc_set },
{ "trap", 1, NULL, "agent uptime oid [oid type value] ...", snmpc_trap },
{ "df", 1, "C:", "[-Ch] [-Cr<maxrep>] agent", snmpc_df },
- { "mibtree", 0, "O:", "[-O fnS]", snmpc_mibtree }
+ { "mibtree", 0, "O:", "[-O fnS] [oid ...]", snmpc_mibtree }
};
struct snmp_app *snmp_app = NULL;
@@ -1060,11 +1060,25 @@ int
snmpc_mibtree(int argc, char *argv[])
{
struct oid *oid;
+ struct ber_oid soid;
char buf[BUFSIZ];
+ int i;
- for (oid = NULL; (oid = smi_foreach(oid)) != NULL;) {
- smi_oid2string(&oid->o_id, buf, sizeof(buf), oid_lookup);
- printf("%s\n", buf);
+ if (argc == 0) {
+ for (oid = NULL; (oid = smi_foreach(oid)) != NULL;) {
+ smi_oid2string(&oid->o_id, buf, sizeof(buf),
+ oid_lookup);
+ printf("%s\n", buf);
+ }
+ } else {
+ for (i = 0; i < argc; i++) {
+ if (smi_string2oid(argv[i], &soid) == -1) {
+ warnx("%s: Unknown object identifier", argv[i]);
+ continue;
+ }
+ smi_oid2string(&soid, buf, sizeof(buf), oid_lookup);
+ printf("%s\n", buf);
+ }
}
return 0;
}