📄 c-extend3.html
字号:
} void sysconfig_get(OIDC_T lastmatch, int compc, OIDC_T *compl, SNMP_PKT_T *pktp, VB_T *vbp) { STRUCT_sysconfig data; /* !!! */ int error; /* find all the varbinds that share the same getproc and instance */ snmpdGroupByGetprocAndInstance(pktp, vbp, compc, compl); /* check that the instance is exactly .0 */ if (!((compc == 1) && (*compl == 0))) for ( ; vbp; vbp = vbp->vb_link) getproc_nosuchins(pktp, vbp); /* grab the actual data for this variable. this lookup routine * probably have to be changed for your system. for scalar variables * there might not even be any lookup routine. */ else if (sysconfig_lookup(&data) != 0) /* !!! */ for ( ; vbp; vbp = vbp->vb_link) getproc_error(pktp, vbp, GEN_ERR); else { /* retrieve all the values from the same data structure */ for ( ; vbp; vbp = vbp->vb_link) { if ((error = sysconfig_get_value(vbp->vb_ml.ml_last_match, pktp, vbp, &data)) != NO_ERROR) getproc_error(pktp, vbp, error); } } } void sysconfig_next(OIDC_T lastmatch, int compc, OIDC_T *compl, SNMP_PKT_T *pktp, VB_T *vbp) { STRUCT_sysconfig data; /* !!! */ OIDC_T instance = 0; /* the only time there's a next for a scalar is if we're given * no instance at all. */ if (compc != 0) nextproc_no_next(pktp, vbp); /* grab the data for these variables. you'll probably have to change * this lookup routine for your system. for scalar variables there * might not even be any lookup routine. */ else if (sysconfig_lookup(&data)); /* !!! */ getproc_error(pktp, vbp, GEN_ERR); else { /* find all the varbinds in this group and retrieve their * values from the same data structure */ for (snmpdGroupByGetprocAndInstance(pktp, vbp, compc, compl); vbp; vbp = vbp->vb_link) { nextproc_next_instance(pktp, vbp, 1, &instance); sysconfig_get_value(vbp->vb_ml.ml_last_match, pktp, vbp, &data); } } } void sysconfig_test(OIDC_T lastmatch, int compc, OIDC_T *compl, SNMP_PKT_T *pktp, VB_T *vbp) { VB_T *group_vbp; /* Only scalar variables here, check for .0 */ if (!((compc == 1) && (*compl == 0))) { testproc_error(pktp, vbp, NO_SUCH_NAME); return; } /* find all the varbinds that share the same getproc and instance and * group them together. */ snmpdGroupByGetprocAndInstance(pktp, vbp, compc, compl); /* now check each varbind */ for (group_vbp = vbp; group_vbp; group_vbp = group_vbp->vb_link) { /* !!! Add any value checking you wish to do. */ switch (group_vbp->vb_ml.ml_last_match) { case LEAF_sysState: /* !!! modify this switch to give an error for values your * implementation doesn't allow */ switch (VB_GET_INT32(group_vbp)) { case VAL_sysState_system_running: case VAL_sysState_system_reboot: break; default: testproc_error(pktp, group_vbp, WRONG_VALUE); continue; } testproc_good(pktp, group_vbp); break; case LEAF_sysUserName: { ALENGTH_T length = EBufferUsed(VB_GET_STRING(group_vbp)); /* !!! These are the lengths from the MIB. Modify if your * implementation differs. */ if (!((length >= MINSIZE_sysUserName) && (length <= MAXSIZE_sysUserName))) { testproc_error(pktp, group_vbp, WRONG_VALUE); break; } } testproc_good(pktp, group_vbp); break; case LEAF_sysUserPassw: { ALENGTH_T length = EBufferUsed(VB_GET_STRING(group_vbp)); /* !!! These are the lengths from the MIB. Modify if your * implementation differs. */ if (!((length >= MINSIZE_sysUserPassw) && (length <= MAXSIZE_sysUserPassw))) { testproc_error(pktp, group_vbp, WRONG_VALUE); break; } } testproc_good(pktp, group_vbp); break; default: testproc_error(pktp, group_vbp, GEN_ERR); return; } } } void sysconfig_set(OIDC_T lastmatch, int compc, OIDC_T *compl, SNMP_PKT_T *pktp, VB_T *vbp) { for ( ; vbp; vbp = vbp->vb_link) { switch (vbp->vb_ml.ml_last_match) { case LEAF_sysState: sysState = VB_GET_INT32(vbp); /* !!! */ setproc_good(pktp, vbp); break; case LEAF_sysUserName: sysUserName = VB_GET_STRING(vbp); /* !!! */ setproc_good(pktp, vbp); break; case LEAF_sysUserPassw: sysUserPassw = VB_GET_STRING(vbp); /* !!! */ setproc_good(pktp, vbp); break; default: setproc_error(pktp, vbp, COMMIT_FAILED); return; } } }</a></b></pre></dl></dl><h4 class="EntityTitle"><a name="83906"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-4: Augmented <b class="command">mibcomp</b> Output</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83907"> </a>The following example shows <b class="file">demo.c</b> after it has been augmented by a MIB designer, complete with method routines.</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83908">#include <asn1.h> #include <buffer.h> #include <mib.h> #include <localio.h> #include <snmpdefs.h> #include <snmp.h> #include <auxfuncs.h> #include "mibleaf.h" /* * Method routines for the sysconfig variables: * * sysState -- read-write * The VxWorks target status is reported through this * field. The only valid state that this field can be * set to is system-reboot. The system will be rebooted * five seconds after changing the state. * * sysUserName -- read-write * The user name the VxWorks target uses for remote * machine access. * * sysUserPassw -- read-write * The user password the VxWorks target uses for remote * machine access. */ /* An internal routine to retrieve the values of the variables, used * by the method routines sysconfig_get and sysconfig_next. * You need to replace the type STRUCT_sysconfig with something * appropriate to your system. */ /* ############################################### This is a structure we define to set and retrieve the prameters of thie sysconfig group */ typedef struct { int sysState; char sysUserName [MAXSIZE_sysUserName + 1]; char sysUserPassw [MAXSIZE_sysUserPassw + 1]; } STRUCT_sysconfig; /* ############################################### Define an instance of this structure. */ static STRUCT_sysconfig sysVars; /* This routine is a utility routine which will be used by both the the get and the next method routine. It takes the STRUCT_sysconfig structure we defined above as input and extracts the appropriate value from it for installaltion into the response packet with the relevant getproc procedure. This STRUCT_sysconfig structure would have been filled in with the required value from within the get or next method routine as appropriate. */ static int sysconfig_get_value(OIDC_T lastmatch, SNMP_PKT_T *pktp, VB_T *vbp, STRUCT_sysconfig *data) /* !!! */ { switch(lastmatch) { case LEAF_sysState: /* Values: * system-running(1) = VAL_sysState_system_running * system-reboot(2) = VAL_sysState_system_reboot */ getproc_got_int32(pktp, vbp, data->sysState); /* !!! */ break; case LEAF_sysUserName: /* if the data being returned is in dynamic storage and needs * to be free'd, change the 0 argument to a 1. */ getproc_got_string(pktp, vbp, strlen (data->sysUserName), data->sysUserName, 0, VT_STRING); /* !!! */ break; case LEAF_sysUserPassw: /* if the data being returned is in dynamic storage and needs * to be free'd, change the 0 argument to a 1. */ getproc_got_string(pktp, vbp, strlen(data->sysUserPassw), data->sysUserPassw, 0, VT_STRING); /* !!! */ break; default: return GEN_ERR; } return NO_ERROR; } /* This is the get method routine. After doing some checks on the input varbind we retreive the required values with the appropriate vxworks calls aand call the utility rtn defined above. */ void sysconfig_get(OIDC_T lastmatch, int compc, OIDC_T *compl, SNMP_PKT_T *pktp, VB_T *vbp) { int error; /* find all the varbinds that share the same getproc and instance */ snmpdGroupByGetprocAndInstance(pktp, vbp, compc, compl); /* check that the instance is exactly .0 */ if (!((compc == 1) && (*compl == 0))) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -