cmu__compat_8c-source.html from net-snmp at Krugle
Show cmu__compat_8c-source.html syntax highlighted
<!--#set var="section" value="development" -->
<!--#include virtual="/page-top.html" -->
<!-- CONTENT START -->
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex">
<a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class=
"qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class=
"qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="pages.html">Related Pages</a> | <a class=
"qindex" href="examples.html">Examples</a>
</div>
<div class="nav">
<a class="el" href="dir_000005.html">snmplib</a>
</div>
<h1>cmu_compat.c</h1>
<div class="fragment">
<pre class="fragment">
00001 <span class="preprocessor">#include <net-snmp/net-snmp-config.h></span>
00002
00003 <span class="preprocessor">#ifdef CMU_COMPATIBLE</span>
00004
00005 <span class="preprocessor">#include <net-snmp/mib_api.h></span>
00006 <span class="preprocessor">#include <net-snmp/pdu_api.h></span>
00007 <span class="preprocessor">#include <net-snmp/session_api.h></span>
00008
00009 <span class="keywordtype">int</span>
00010 mib_TxtToOid(<span class="keywordtype">char</span> *Buf, oid ** OidP, size_t * LenP)
00011 {
00012 <span class="keywordflow">return</span> <a class="code" href=
"group__mib__utilities.html#ga62">read_objid</a>(Buf, *OidP, LenP);
00013 }
00014
00015 <span class="keywordtype">int</span>
00016 mib_OidToTxt(oid * O, size_t OidLen, <span class="keywordtype">char</span> *Buf, size_t BufLen)
00017 {
00018 _sprint_objid(Buf, O, OidLen);
00019 <span class="keywordflow">return</span> 1;
00020 }
00021
00022
00023 <span class="comment">/*</span>
00024 <span class="comment"> * cmu_snmp_parse - emulate CMU library's snmp_parse.</span>
00025 <span class="comment"> *</span>
00026 <span class="comment"> * Parse packet, storing results into PDU.</span>
00027 <span class="comment"> * Returns community string if success, NULL if fail.</span>
00028 <span class="comment"> * WARNING: may return a zero length community string.</span>
00029 <span class="comment"> *</span>
00030 <span class="comment"> * Note:</span>
00031 <span class="comment"> * Some CMU-aware apps call init_mib(), but do not</span>
00032 <span class="comment"> * initialize a session.</span>
00033 <span class="comment"> * Check Reqid to make sure that this module is initialized.</span>
00034 <span class="comment"> */</span>
00035
00036 u_char *
00037 cmu_snmp_parse(<a class="code" href="structsnmp__session.html">netsnmp_session</a> * session,
00038 <a class="code" href="structsnmp__pdu.html">netsnmp_pdu</a> *pdu, u_char * data, size_t length)
00039 {
00040 u_char *bufp = NULL;
00041
00042 snmp_sess_init(session); <span class="comment">/* gimme a break! */</span>
00043
00044 <span class="keywordflow">switch</span> (pdu-><a class="code" href="structsnmp__pdu.html#o0">version</a>) {
00045 <span class="keywordflow">case</span> SNMP_VERSION_1:
00046 <span class="keywordflow">case</span> SNMP_VERSION_2c:
00047 <span class="keywordflow">case</span> SNMP_DEFAULT_VERSION:
00048 <span class="keywordflow">break</span>;
00049 <span class="keywordflow">default</span>:
00050 <span class="keywordflow">return</span> NULL;
00051 }
00052 <span class="preprocessor">#ifndef NO_INTERNAL_VARLIST</span>
00053 <span class="keywordflow">if</span> (snmp_parse(0, session, pdu, data, length) != SNMP_ERR_NOERROR) {
00054 <span class="keywordflow">return</span> NULL;
00055 }
00056 <span class="preprocessor">#else</span>
00057 <span class="comment">/*</span>
00058 <span class="comment"> * while there are two versions of variable_list:</span>
00059 <span class="comment"> * use an internal variable list for snmp_parse;</span>
00060 <span class="comment"> * clone the result.</span>
00061 <span class="comment"> */</span>
00062 <span class="keywordflow">if</span> (1) {
00063 <a class="code" href="structsnmp__pdu.html">netsnmp_pdu</a> *snmp_clone_pdu(<a class="code" href=
"structsnmp__pdu.html">netsnmp_pdu</a> *);
00064 <a class="code" href="structsnmp__pdu.html">netsnmp_pdu</a> *snmp_2clone_pdu(<a class="code" href=
"structsnmp__pdu.html">netsnmp_pdu</a> *from_pdu,
00065 <a class="code" href="structsnmp__pdu.html">netsnmp_pdu</a> *to_pdu);
00066
00067 <a class="code" href="structsnmp__pdu.html">netsnmp_pdu</a> *ipdu;
00068 ipdu = snmp_clone_pdu(pdu);
00069 <span class="keywordflow">if</span> (snmp_parse(0, session, ipdu, data, length) != SNMP_ERR_NOERROR) {
00070 snmp_free_internal_pdu(ipdu);
00071 <span class="keywordflow">return</span> NULL;
00072 }
00073 pdu = snmp_2clone_pdu(ipdu, pdu);
00074 snmp_free_internal_pdu(ipdu);
00075 }
00076 <span class="preprocessor">#endif </span><span class="comment">/* NO_INTERNAL_VAR_LIST */</span>
00077
00078 <span class="comment">/*</span>
00079 <span class="comment"> * Add a null to meet the caller's expectations. </span>
00080 <span class="comment"> */</span>
00081
00082 bufp = (u_char *) malloc(1 + pdu-><a class="code" href="structsnmp__pdu.html#o19">community_len</a>);
00083 <span class="keywordflow">if</span> (bufp && pdu-><a class="code" href=
"structsnmp__pdu.html#o19">community_len</a>) {
00084 memcpy(bufp, pdu-><a class="code" href="structsnmp__pdu.html#o18">community</a>, pdu-><a class="code" href=
"structsnmp__pdu.html#o19">community_len</a>);
00085 bufp[pdu-><a class="code" href="structsnmp__pdu.html#o19">community_len</a>] = <span class=
"charliteral">'\0'</span>;
00086 }
00087 <span class="keywordflow">return</span> (bufp);
00088 }
00089
00090
00091 <span class="preprocessor">#endif </span><span class="comment">/* CMU_COMPATIBLE */</span>
</pre>
</div>
<hr size="1" />
<address style="align: right;">
<small>Generated on Fri Dec 30 13:47:44 2005 for net-snmp by <a href="http://www.doxygen.org/index.html"><img src=
"doxygen.png" alt="doxygen" align="middle" border="0" /></a> 1.3.9.1</small>
</address>
<!-- CONTENT END -->
<!--#include virtual="/page-bottom.html" -->
See more files for this project here