]>
git.ipfire.org Git - thirdparty/squid.git/blob - snmplib/mib.c
2 /***********************************************************
3 Copyright 1988, 1989 by Carnegie Mellon University
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of CMU not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 ******************************************************************/
35 #include <sys/types.h>
41 #include <gnumalloc.h>
58 #include <sys/socket.h>
61 #include <netinet/in.h>
64 #include <arpa/inet.h>
77 #include "snmp_vars.h"
78 #include "snmp_session.h"
79 #include "snmp_impl.h"
85 static struct snmp_mib_tree
*get_symbol(oid
*objid
, int objidlen
, struct snmp_mib_tree
*subtree
, char *buf
);
87 oid RFC1066_MIB
[] = {1, 3, 6, 1, 2, 1};
88 unsigned char RFC1066_MIB_text
[] = ".iso.org.dod.internet.mgmt.mib";
89 struct snmp_mib_tree
*Mib
;
102 static struct snmp_mib_tree
*
103 find_rfc1066_mib(struct snmp_mib_tree
*root
) {
104 oid
*op
= RFC1066_MIB
;
105 struct snmp_mib_tree
*tp
;
108 for (len
= sizeof(RFC1066_MIB
) / sizeof(oid
); len
; len
--, op
++) {
109 for (tp
= root
; tp
; tp
= tp
->next_peer
) {
110 if (tp
->subid
== *op
) {
111 root
= tp
->child_list
;
122 lc_cmp(const char *s1
, const char *s2
)
136 return ((c1
- c2
) > 0 ? 1 : -1);
149 parse_subtree(struct snmp_mib_tree
*subtree
, char *input
, oid
*output
, int *out_len
)
151 char buf
[128], *to
= buf
;
153 struct snmp_mib_tree
*tp
;
156 * No empty strings. Can happen if there is a trailing '.' or two '.'s
157 * in a row, i.e. "..".
159 if ((*input
== '\0') ||
163 if (xisdigit(*input
)) {
165 * Read the number, then try to find it in the subtree.
167 while (xisdigit(*input
)) {
169 subid
+= *input
++ - '0';
171 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
172 if (tp
->subid
== subid
)
178 * Read the name into a buffer.
180 while ((*input
!= '\0') &&
187 * Find the name in the subtree;
189 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
190 if (lc_cmp(tp
->label
, buf
) == 0) {
197 * If we didn't find the entry, punt...
200 snmplib_debug(0, "sub-identifier not found: %s\n", buf
);
206 if (subid
> (u_int
) MAX_SUBID
) {
207 snmplib_debug(0, "sub-identifier too large: %s\n", buf
);
210 if ((*out_len
)-- <= 0) {
211 snmplib_debug(0, "object identifier too long\n");
219 parse_subtree(tp
? tp
->child_list
: NULL
, ++input
, output
, out_len
)) == 0)
225 read_objid(input
, output
, out_len
)
228 int *out_len
; /* number of subid's in "output" */
230 struct snmp_mib_tree
*root
= Mib
;
237 root
= find_rfc1066_mib(root
);
238 for (i
= 0; i
< sizeof(RFC1066_MIB
) / sizeof(oid
); i
++) {
239 if ((*out_len
)-- > 0)
240 *output
++ = RFC1066_MIB
[i
];
242 snmplib_debug(0, "object identifier too long\n");
249 snmplib_debug(0, "Mib not initialized.\n");
252 if ((*out_len
= parse_subtree(root
, input
, output
, out_len
)) == 0)
254 *out_len
+= output
- op
;
260 print_objid(objid
, objidlen
)
262 int objidlen
; /* number of subidentifiers */
265 struct snmp_mib_tree
*subtree
= Mib
;
267 *buf
= '.'; /* this is a fully qualified name */
268 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
269 snmplib_debug(7, "%s\n", buf
);
274 sprint_objid(buf
, objid
, objidlen
)
277 int objidlen
; /* number of subidentifiers */
279 struct snmp_mib_tree
*subtree
= Mib
;
281 *buf
= '.'; /* this is a fully qualified name */
282 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
285 static struct snmp_mib_tree
*
286 get_symbol(objid
, objidlen
, subtree
, buf
)
289 struct snmp_mib_tree
*subtree
;
292 struct snmp_mib_tree
*return_tree
= NULL
;
294 for (; subtree
; subtree
= subtree
->next_peer
) {
295 if (*objid
== subtree
->subid
) {
296 strcpy(buf
, subtree
->label
);
301 /* subtree not found */
302 while (objidlen
--) { /* output rest of name, uninterpreted */
303 sprintf(buf
, "%u.", *objid
++);
307 *(buf
- 1) = '\0'; /* remove trailing dot */
316 return_tree
= get_symbol(objid
+ 1, objidlen
- 1, subtree
->child_list
, buf
);
318 if (return_tree
!= NULL
)
325 print_oid_nums(oid
* O
, int len
)
329 for (x
= 0; x
< len
; x
++)