Skip to content

Instantly share code, notes, and snippets.

@oogali
Created May 31, 2013 15:28
Show Gist options
  • Save oogali/5685762 to your computer and use it in GitHub Desktop.
Save oogali/5685762 to your computer and use it in GitHub Desktop.
Convert ASCII OIDs to numeric -- I guess I did not know about snmptranslate at the time
/*
* Copyright (c) 2006 Omachonu Ogali <[email protected]>
* 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 AUTHOR 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 AUTHOR 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 <stdio.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
void print_oid(oid *o, int len)
{
int i;
for (i = 0; i < len; i++) {
printf(".%ld", o[i]);
}
printf("\n");
}
int main(int argc, char **argv)
{
int i;
if (argc < 2) {
fprintf(stderr, "%s OID [OID]\n", argv[0]);
return -1;
}
init_mib();
for (i = 1; i < argc; i++) {
oid o[MAX_OID_LEN];
size_t o_len = sizeof(o) / sizeof(oid);
if (read_objid(argv[i], o, &o_len) == 0) {
fprintf(stderr, "%s: could not parse\n", argv[i]);
} else {
printf("%s: ", argv[i]);
print_oid(o, o_len);
}
}
return 0;
}
@oogali
Copy link
Author

oogali commented May 31, 2013

$ ls -la snmpresolve/snmpresolve.c
-rw-r--r--  1 missnglnk  staff  2029 Mar 26  2006 snmpresolve/snmpresolve.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment