cmu_compat.c

00001 #include <net-snmp/net-snmp-config.h>
00002 
00003 #ifdef CMU_COMPATIBLE
00004 
00005 #include <net-snmp/mib_api.h>
00006 #include <net-snmp/pdu_api.h>
00007 #include <net-snmp/session_api.h>
00008 
00009 int
00010 mib_TxtToOid(char *Buf, oid ** OidP, size_t * LenP)
00011 {
00012     return read_objid(Buf, *OidP, LenP);
00013 }
00014 
00015 int
00016 mib_OidToTxt(oid * O, size_t OidLen, char *Buf, size_t BufLen)
00017 {
00018     _sprint_objid(Buf, O, OidLen);
00019     return 1;
00020 }
00021 
00022 
00023 /*
00024  * cmu_snmp_parse - emulate CMU library's snmp_parse.
00025  *
00026  * Parse packet, storing results into PDU.
00027  * Returns community string if success, NULL if fail.
00028  * WARNING: may return a zero length community string.
00029  *
00030  * Note:
00031  * Some CMU-aware apps call init_mib(), but do not
00032  * initialize a session.
00033  * Check Reqid to make sure that this module is initialized.
00034  */
00035 
00036 u_char         *
00037 cmu_snmp_parse(netsnmp_session * session,
00038                netsnmp_pdu *pdu, u_char * data, size_t length)
00039 {
00040     u_char         *bufp = NULL;
00041 
00042     snmp_sess_init(session);    /* gimme a break! */
00043 
00044     switch (pdu->version) {
00045     case SNMP_VERSION_1:
00046     case SNMP_VERSION_2c:
00047     case SNMP_DEFAULT_VERSION:
00048         break;
00049     default:
00050         return NULL;
00051     }
00052 #ifndef NO_INTERNAL_VARLIST
00053     if (snmp_parse(0, session, pdu, data, length) != SNMP_ERR_NOERROR) {
00054         return NULL;
00055     }
00056 #else
00057     /*
00058      * while there are two versions of variable_list:
00059      * use an internal variable list for snmp_parse;
00060      * clone the result.
00061      */
00062     if (1) {
00063         netsnmp_pdu    *snmp_clone_pdu(netsnmp_pdu *);
00064         netsnmp_pdu    *snmp_2clone_pdu(netsnmp_pdu *from_pdu,
00065                                         netsnmp_pdu *to_pdu);
00066 
00067         netsnmp_pdu    *ipdu;
00068         ipdu = snmp_clone_pdu(pdu);
00069         if (snmp_parse(0, session, ipdu, data, length) != SNMP_ERR_NOERROR) {
00070             snmp_free_internal_pdu(ipdu);
00071             return NULL;
00072         }
00073         pdu = snmp_2clone_pdu(ipdu, pdu);
00074         snmp_free_internal_pdu(ipdu);
00075     }
00076 #endif                          /* NO_INTERNAL_VAR_LIST */
00077 
00078     /*
00079      * Add a null to meet the caller's expectations. 
00080      */
00081 
00082     bufp = (u_char *) malloc(1 + pdu->community_len);
00083     if (bufp && pdu->community_len) {
00084         memcpy(bufp, pdu->community, pdu->community_len);
00085         bufp[pdu->community_len] = '\0';
00086     }
00087     return (bufp);
00088 }
00089 
00090 
00091 #endif                          /* CMU_COMPATIBLE */

net-snmpに対してSat Sep 5 13:14:20 2009に生成されました。  doxygen 1.4.7