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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include <net-snmp/net-snmp-config.h>
26 #include <net-snmp/net-snmp-includes.h>
30 #define min(A,B) ((A) < (B) ? (A) : (B))
33 oid_compare (const oid *o1, int o1_len, const oid *o2, int o2_len)
37 for (i = 0; i < min (o1_len, o2_len); i++)
41 else if (o1[i] > o2[i])
53 oid_copy (void *dest, const void *src, size_t size)
55 return memcpy (dest, src, size * sizeof (oid));
59 oid2in_addr (oid oid[], int len, struct in_addr *addr)
67 pnt = (u_char *) addr;
69 for (i = 0; i < len; i++)
74 oid_copy_addr (oid oid[], struct in_addr *addr, int len)
82 pnt = (u_char *) addr;
84 for (i = 0; i < len; i++)
89 smux_header_generic (struct variable *v, oid *name, size_t *length, int exact,
90 size_t *var_len, WriteMethod **write_method)
92 oid fulloid[MAX_OID_LEN];
95 oid_copy (fulloid, v->name, v->namelen);
96 fulloid[v->namelen] = 0;
97 /* Check against full instance. */
98 ret = oid_compare (name, *length, fulloid, v->namelen + 1);
100 /* Check single instance. */
101 if ((exact && (ret != 0)) || (!exact && (ret >= 0)))
104 /* In case of getnext, fill in full instance. */
105 memcpy (name, fulloid, (v->namelen + 1) * sizeof (oid));
106 *length = v->namelen + 1;
109 *var_len = sizeof(long); /* default to 'long' results */
111 return MATCH_SUCCEEDED;
115 smux_header_table (struct variable *v, oid *name, size_t *length, int exact,
116 size_t *var_len, WriteMethod **write_method)
118 /* If the requested OID name is less than OID prefix we
119 handle, adjust it to our prefix. */
120 if ((oid_compare (name, *length, v->name, v->namelen)) < 0)
124 oid_copy(name, v->name, v->namelen);
125 *length = v->namelen;
129 *var_len = sizeof(long);
131 return MATCH_SUCCEEDED;
133 #endif /* HAVE_SNMP */