]>
git.proxmox.com Git - mirror_frr.git/blob - lib/snmp.c
2 * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <net-snmp/net-snmp-config.h>
24 #include <net-snmp/net-snmp-includes.h>
28 int oid_compare(const oid
*o1
, int o1_len
, const oid
*o2
, int o2_len
)
32 for (i
= 0; i
< MIN(o1_len
, o2_len
); i
++) {
35 else if (o1
[i
] > o2
[i
])
46 void *oid_copy(void *dest
, const void *src
, size_t size
)
48 return memcpy(dest
, src
, size
* sizeof(oid
));
51 void oid2in_addr(oid oid
[], int len
, struct in_addr
*addr
)
59 pnt
= (uint8_t *)addr
;
61 for (i
= 0; i
< len
; i
++)
65 void oid2in6_addr(oid oid
[], struct in6_addr
*addr
)
70 pnt
= (uint8_t *)addr
;
72 for (i
= 0; i
< sizeof(struct in6_addr
); i
++)
76 void oid2int(oid oid
[], int *dest
)
82 pnt
= (uint8_t *)&network_dest
;
84 for (i
= 0; i
< sizeof(int); i
++)
86 *dest
= ntohl(network_dest
);
89 void oid_copy_in_addr(oid oid
[], const struct in_addr
*addr
)
93 int len
= sizeof(struct in_addr
);
95 pnt
= (uint8_t *)addr
;
97 for (i
= 0; i
< len
; i
++)
102 void oid_copy_in6_addr(oid oid
[], const struct in6_addr
*addr
)
106 int len
= sizeof(struct in6_addr
);
108 pnt
= (uint8_t *)addr
;
110 for (i
= 0; i
< len
; i
++)
114 void oid_copy_int(oid oid
[], int *val
)
120 network_val
= htonl(*val
);
121 pnt
= (uint8_t *)&network_val
;
123 for (i
= 0; i
< sizeof(int); i
++)
127 void oid2string(oid oid
[], int len
, char *string
)
135 pnt
= (uint8_t *)string
;
137 for (i
= 0; i
< len
; i
++)
138 *pnt
++ = (uint8_t)oid
[i
];
141 void oid_copy_str(oid oid
[], const char *string
, int len
)
149 pnt
= (uint8_t *)string
;
151 for (i
= 0; i
< len
; i
++)
155 int smux_header_generic(struct variable
*v
, oid
*name
, size_t *length
,
156 int exact
, size_t *var_len
, WriteMethod
**write_method
)
158 oid fulloid
[MAX_OID_LEN
];
161 oid_copy(fulloid
, v
->name
, v
->namelen
);
162 fulloid
[v
->namelen
] = 0;
163 /* Check against full instance. */
164 ret
= oid_compare(name
, *length
, fulloid
, v
->namelen
+ 1);
166 /* Check single instance. */
167 if ((exact
&& (ret
!= 0)) || (!exact
&& (ret
>= 0)))
170 /* In case of getnext, fill in full instance. */
171 memcpy(name
, fulloid
, (v
->namelen
+ 1) * sizeof(oid
));
172 *length
= v
->namelen
+ 1;
175 *var_len
= sizeof(long); /* default to 'long' results */
177 return MATCH_SUCCEEDED
;
180 int smux_header_table(struct variable
*v
, oid
*name
, size_t *length
, int exact
,
181 size_t *var_len
, WriteMethod
**write_method
)
183 /* If the requested OID name is less than OID prefix we
184 handle, adjust it to our prefix. */
185 if ((oid_compare(name
, *length
, v
->name
, v
->namelen
)) < 0) {
188 oid_copy(name
, v
->name
, v
->namelen
);
189 *length
= v
->namelen
;
193 *var_len
= sizeof(long);
195 return MATCH_SUCCEEDED
;