⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpdlib.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
*  <compl>    - input oid sequence*  <pOutOid>  - output OID sequence. This buffer must be provided by the caller,*               and be big enough for an oid sequence of length oidLen.*  <pMaxOid>  - The max possible table index of this kind.*               e.g. for the udpTable the index can be max ff.ff.ff.ff.ffff*  <oidLen>   - length of index oid sequence** RETURNS:*    0    if valid next index generated in OutOid.*    1    if no next index value possible.** NOMANUAL*/int snmpNextIndex     (    int               compc,     /* Component count */    const OIDC_T *    compl,     /* Oid for which lexicographic next is reqd */    OIDC_T *          pOutOid,   /* Output oid i.e. the next feasible oid */    const OIDC_T *    pMaxOid,   /* max possible value for the index oid */    int               oidLen     /* length of index oid */    )    {    int     ix;	    int     lastCarryIndex = oidLen;    int     carryFlag = 0;    /* Ignore  components beyond end of index. They don't  matter */    if (compc > oidLen)        {        compc = oidLen;        }    memset (pOutOid, 0, oidLen * sizeof *pOutOid);    memcpy (pOutOid, compl, compc * sizeof *pOutOid);    /*  add a 1 to least significant end if and only if input oid      *  sequence  has length  equal to length of the table index.     */    for (ix = oidLen - 1; ix >= 0; --ix)        {        if ( pOutOid [ix] >= pMaxOid [ix] )            {            if ( ix == 0 )                {                return (1);                }            lastCarryIndex = ix;            carryFlag = 1;            }        else if (carryFlag == 1)            {            ++ pOutOid [ix];            carryFlag = 0;            }        }    for ( ix = lastCarryIndex; ix < oidLen; ++ix)        {        pOutOid [ix] = 0;        }    if ((lastCarryIndex == oidLen)  && (compc == oidLen))        {        ++ pOutOid [compc - 1];        }    return (0);    }/********************************************************************************* snmpNextError - select error type for failed next request** Routine to decide on type of response to a getnext request if the * associated m2Get{*} call  failed. When an m2Get{*} call made with* the M2_NEXT_MATCH flag fails the failure could be due to a non-existent* next value or some other.** RETURNS: N/A** NOMANUAL*/void snmpNextError    (    SNMP_PKT_T*     pPkt,   /* snmp packet */    VB_T*           pVbp     /* varbind */    )    {    if ( errno == S_m2Lib_ENTRY_NOT_FOUND )        {        nextproc_no_next(pPkt, pVbp);        }    else        {        nextproc_error(pPkt, pVbp, GEN_ERR);        }    }    /******************************************************************************** snmpVbPrivFree** Routine for freeing memory allocated in the vb_priv field of a var bind** RETURNS: N/A* NOMANUAL*/void  snmpVbPrivFree    (    VB_T *             pVbp   /* varbind */    )    {    if ( pVbp->vb_priv != NULL )        {        snmpdMemoryFree (pVbp->vb_priv);        pVbp->vb_priv = NULL;        }    }/********************************************************************************* snmpOidToIpHostOrder** Converts an oid sequence representing an ip address to an ip address* in host order** RETURNS: 0 if valid ip address generated else non zero** NOMANUAL*/int snmpOidToIpHostOrder    (    int             compLen,   /* component length */    OIDC_T *        pCompSeq,  /* component sequence */    ulong_t *       pIpAddr    /* ip address */    )    {    int             status;    status = oid_to_ip (compLen, pCompSeq, pIpAddr);    *pIpAddr = ntohl (*pIpAddr);    return (status);    }/******************************************************************************** snmpOidStrToArray - Convert oid in string form to oid component array *  * Convert an oid in string form <pOidStr> to an array of oid components, * <pOidArray> which is a user supplied array and must be of sufficient size.** RETURNS: 0 on failure else number of oid components in the array* * NOMANUAL*/int snmpOidStrToArray    (    char *        pOidStr,     /* input oid string */    OIDC_T *      pOidArray    /* output oid compononent array */    )    {    int           oidLen = 0;    char *        pIx;    for (pIx = pOidStr;         ; ++ pIx )        {        if ( !isdigit ((int) *pIx))            {            /* Non digit char where we stop must be either '.' or EOS.             * Also when we stop at one of these it must not be the first             * char encountered. This could happen for example if we heve             * 2 consecutive '.' chars in the input or it starts with a '.'.             *              */             if ( (*pIx != '.' && *pIx != EOS) || pIx == pOidStr)                {                snmpdLog (SNMP_WARN, "Invalid object identifier syntax\n");                errno = S_snmpdLib_INVALID_OID_SYNTAX;                return (0);                }                pOidArray [oidLen ++] = atol (pOidStr);            if (*pIx == EOS)                 {                break;                }                      pOidStr = pIx + 1;            }        }    return (oidLen);    }/******************************************************************************** snmpdInitFinish - complete the initialization of the agent** This routine is required to be called by the user to complete the* initialization of the SNMP agent after the transport endpoint has* been initialized. This routine must be called \f2after\fR the endpoint has* been established, since it depends on that endpoint to function* correctly.** This routine also installs any user-supplied hooks for customizing* the agent. If a hook is not required, a NULL pointer should be passed* in that position. The function snmpIoTrapSend() is invoked by this* routine, so any configuration required by that routine should be* done prior to calling snmpdInitFinish().** The hook routines are as follows:** .iP "<pPrivRlse>" 8 * This routine is used by the agent to free any memory attached to the* private field of the SNMP_PKT_T structure. * .iP "<pSetPduVldt>"* This routine is called before any processing of a `set' request has* taken place.  It can be used to perform global validation of the* request, if needed. The return values for this routine must meet the* following requirements:* * 0 - indicates that the `set' PDU is valid, and processing should continue.* * 1 - indicates that the `set' PDU is valid, and that this routine has* already completed all the required `set' operations.* * -1 - indicates that the `set' PDU is invalid and should be rejected.* .iP "<pPreSet>"* This routine is called after all `testproc' operations have* completed successfully, but before any `setproc' operation is begun.* Return value requirements are as follows* * 0 - indicates that the `set' PDU is valid, and processing should continue.* * 1 - indicates that the `set' PDU is valid, and that this routine has* already completed all the required `set' operations.* * -1 - indicates that the `set' PDU is invalid and should be rejected.* .iP "<pPostSet>"* This routine is called after all `setproc' have completed* successfully. This routine can be used to free resources allocated* during `set' processing. * .iP "<pSetFailed>"* This routine is possibly called under two sets of circumstances:* after all `testproc' operations have returned and some of them have* failed, and/or after all `undoproc' operations have returned and* some `setproc' operations have failed.  It can be used to do any* required cleanup.  * .LP** RETURNS: N/A*/void snmpdInitFinish     (    VOIDFUNCPTR    pPrivRlse,     /* user's privare release routine */    FUNCPTR        pSetPduVldt,   /* user's set pdu validate routine */    FUNCPTR        pPreSet,       /* user's pre set routine */    FUNCPTR        pPostSet,      /* user's post set routine */    FUNCPTR        pSetFailed     /* user's set failed routine */    )    {    snmpHkPrivRlseRtn = pPrivRlse;    snmpHkSetPduVldtRtn = pSetPduVldt;    snmpHkPreSetRtn = pPreSet;    snmpHkPostSetRtn = pPostSet;    snmpHkSetFailedRtn = pSetFailed;    snmpIoTrapSend (COLD_START, 0);    snmpMibsInit ();    }/******************************************************************************** snmpdExit - exit the SNMP agent** This routine causes the SNMP agent to exit.  It is available in case* the user encounters some problem after a successful startup. * * This routine must be called from the main thread. Any other tasks* spawned by the user (for asynchronous method routines) should be* deleted prior to calling this function.** RETURNS: N/A**/void snmpdExit (void)    {    snmpdCleanup ();    snmpIoClose ();    snmpdViewTblRemove ();    }/******************************************************************************** snmpHookPrivRelease - release private memory used by hooks** This routine is used by the agent to free any memory attached to the* private field of the SNMP_PKT_T structure.  This routine must be* provided by the user, if it is required.** RETURNS: N/A** NOMANUAL*/void snmpHookPrivRelease    (    SNMP_PKT_T  *pPkt    /* snmp packet */    )    {    if (snmpHkPrivRlseRtn != NULL)        {        ((*snmpHkPrivRlseRtn) (pPkt));        }    }/******************************************************************************** snmpHookSetPduValidate - validate a `set' request PDU** This routine is called before any processing of a `set' request has* taken place.  It can be used to perform global validation of the* request, if needed.  This routine must be provided by the user, if* it is required.** RETURNS:   *   0 indicates that the `set' PDU is valid, and processing should continue.*   1 indicates that the `set' PDU is valid, and that this routine has*   already completed all the required `set' operations.*   -1 indicates that the `set' PDU is invalid and should be rejected.** NOMANUAL*/int snmpHookSetPduValidate    (    SNMP_PKT_T *     pPkt            /* Pointer to SNMP packet */    )    {    if (snmpHkSetPduVldtRtn != NULL)        {        return ((*snmpHkSetPduVldtRtn) (pPkt));        }    return 0;    }/******************************************************************************** snmpHookPreSet - perform user-specified actions before a `set' operation** This routine is called after all `testproc' operations have* completed successfully, but before any `setproc' operation is begun.* This routine must be provided by the user, if it is required.** RETURNS:   *   0 indicates that the `set' PDU is valid, and processing should continue.*   1 indicates that the `set' PDU is valid, and that this routine has*   already completed all the required `set' operations.*   -1 indicates that the `set' PDU is invalid and should be rejected.** NOMANUAL*/int  snmpHookPreSet    (    SNMP_PKT_T *    pPkt            /* Pointer to SNMP packet */    )    {    if (snmpHkPreSetRtn != NULL)        {        return ((*snmpHkPreSetRtn) (pPkt));        }    return 0;    }/******************************************************************************* snmpHookPostSet - perform user-specified actions after a `set' operation** This routine is called after all `setproc' have completed* successfully. This routine can be used to free resources allocated* during `set' processing.  This routine must be provided by the user,* if it is required.** RETURNS: N/A** NOMANUAL*/int  snmpHookPostSet    (    SNMP_PKT_T *     pPkt            /* Pointer to SNMP packet */    )    {    if (snmpHkPostSetRtn != NULL)        {        return ((*snmpHkPostSetRtn) (pPkt));        }    return 0;    }/******************************************************************************** snmpHookSetFailed  - perform user-specified actions on failure of a `set' operation** This routine is possibly called under two sets of circumstances:* after all `testproc' operations have returned and some of them have* failed, and/or after all `undoproc' operations have returned and* some `setproc' operations have failed.  It can be used to do any* required cleanup.  This routine must be provided by the user, if it* is required.** RETURNS: N/A** NOMANUAL*/int  snmpHookSetFailed    (    SNMP_PKT_T *     pPkt           /* Pointer to SNMP packet */    )    {    if (snmpHkSetFailedRtn != NULL)        {        return ((*snmpHkSetFailedRt

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -