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

📄 v_vxdemo.c

📁 vxworks demo 有问题写信给我
💻 C
📖 第 1 页 / 共 4 页
字号:
* SEE ALSO:*/int taskEntry_set     (    doList_t      * doHead,      /* Ptr to the list of SNMP outstanding reqs */    doList_t      * doCur,       /* Ptr to free doList element */    ContextInfo   * contextInfo  /* Reserved for future used */    )    {    return (k_taskEntry_set ((taskEntry_t *) (doCur->data), contextInfo, 			     doCur->state));    }/********************************************************************************* sysmemory_get -  Read the value of a variable in the memory group.** This routine returns the value of the requested MIB variable that corresponds* to its group.   All the values from the group are obtain from the "k_"* logic but only the requested value is returned by this function.** RETURNS: A pointer to a VarBind struct, or NULL if the request is invalid.** SEE ALSO:*/VarBind * sysmemory_get     (    OID          * incoming,    /* Ptr to the OID received in the SNMP PDU */    ObjectInfo   * object,      /* Ptr to MIB var in the SNMP MIB tree */    int            searchType,  /* EXACT = GetRequest,NEXT = Get[Next|Bulk] */    ContextInfo  * contextInfo, /* Reserved for future used */    int            serialNum    /* Used for caching */    )    {    static sysmemory_t  		 * memVars;	/* Struct Generated by the MIB Comp. */    static int     lastSerialNum;    void         * dp;          /* Generic ptr used for returned variable */    int            reqVar = -1; /* Variable Requested by the Agent */    int            instLength;  /* Length of the incoming OID */    static OID   * last_incoming;    if ((lastSerialNum != serialNum) || (memVars == NULL) ||	(CmpOIDInst(incoming, last_incoming, object->oid.length) != 0))	{    /*      * instLength represents the length of the (incoming) requested OID     * beyond the Object Identifier specified in the MIB tree.  This value     * is used to validate the request on an EXACT or NEXT search.  Ex.     * The MIB variable fakeMibVar = OID 1.3.6.1.4.1.731.1.1.2 and is      * specified this way in the object variable.  The incoming would     * have fakeMibVar.0 = OID 1.3.6.1.4.1.731.1.1.2.0, the length would     * be 1 and the last value 0.  This information is used to valiate the     * EXACT search.  In the case of a NEXT search the length must be 0     * for leaf variables.  For table entries with an integer index the      * incoming OID would be 1.3.6.1.4.1.731.1.1.2.INDEX and the length     * would represent the index.     */	instLength = incoming->length - object->oid.length;	switch (searchType) 	    {	    case EXACT:		if (instLength == 1 && 		    incoming->oid_ptr[incoming->length - 1] == 0) 		{		    reqVar = object->nominator;		}		break;	    case NEXT:		if (instLength <= 0) 		{		    reqVar = object->nominator;		}		break;	    default:		DPRINTF ((0, "snmpd: Internal error. (invalid search type in \			  sysmemory_get -- %d)\n", searchType));	    }				/* switch */	/* Retrieve the data from the kernel-specific routine.  */	if (reqVar == -1 || (memVars = k_sysmemory_get (serialNum, contextInfo,							reqVar)) == NULL) 	    {	    return ((VarBind *) NULL);	    }	/* Get new catche information */     	lastSerialNum = serialNum;	if (last_incoming != NULL)	    FreeOID(last_incoming);		     	last_incoming = CloneOID(incoming);	}    else	{	reqVar = object->nominator;	}    /*     *  Construct the response for the SNMP agent.  The structure returned     *  will be strung onto the response PDU.  The global strucutre ZeroOid     *  is used for leaf variables.  The S_OFFSET macro computes the offset     *  of the variable in the memVars structure and passes a pointer to the     *  variable to the MakeVarBind function.     */    return (MakeVarBind (object, &ZeroOid, S_OFFSET(memVars, reqVar)));    }/********************************************************************************* sysnfs_get -  Read the value of a variable in the nfs group.** This routine returns the value of the requested MIB variable that corresponds* to its group.   All the values from the group are obtain from the "k_"* logic but only the requested value is returned by this function.** RETURNS: A pointer to a VarBind struct, or NULL if the request is invalid.** SEE ALSO:*/VarBind * sysnfs_get     (    OID          * incoming,    /* Ptr to the OID received in the SNMP PDU */    ObjectInfo   * object,      /* Ptr to MIB var in the SNMP MIB tree */    int            searchType,  /* EXACT = GetRequest,NEXT = Get[Next|Bulk] */    ContextInfo  * contextInfo, /* Reserved for future used */    int            serialNum    /* Used for caching */    )    {    static sysnfs_t     		 * nfsVars;     /* Ptr to struct than contains the MIB vars */    static int     lastSerialNum;    void         * dp;          /* Generic ptr used for returned variable */    int            reqVar = -1; /* Variable Requested by the Agent */    int            instLength;  /* Length of the incoming OID */    static OID   * last_incoming;    if ((lastSerialNum != serialNum) || (nfsVars == NULL) ||	(CmpOIDInst(incoming, last_incoming, object->oid.length) != 0))	{    /*      * instLength represents the length of the (incoming) requested OID     * beyond the Object Identifier specified in the MIB tree.  This value     * is used to validate the request on an EXACT or NEXT search.  Ex.     * The MIB variable fakeMibVar = OID 1.3.6.1.4.1.731.1.1.2 and is      * specified this way in the object variable.  The incoming would     * have fakeMibVar.0 = OID 1.3.6.1.4.1.731.1.1.2.0, the length would     * be 1 and the last value 0.  This information is used to valiate the     * EXACT search.  In the case of a NEXT search the length must be 0     * for leaf variables.  For table entries with an integer index the      * incoming OID would be 1.3.6.1.4.1.731.1.1.2.INDEX and the length     * would represent the index.     */	instLength = incoming->length - object->oid.length;	switch (searchType) 	    {	    case EXACT:		if (instLength == 1 && 		    incoming->oid_ptr [incoming->length - 1] == 0) 		    {		reqVar = object->nominator;		    }		break;	    case NEXT:		if (instLength <= 0) 		    {		    reqVar = object->nominator;		    }		break;	    default:		DPRINTF ((0, "snmpd: Internal error. (invalid search type in \			  sysnfsy_get -- %d)\n", searchType));	    }				/* switch */	/* Retrieve the data from the kernel-specific routine.  */	if (reqVar == -1 || (nfsVars = k_sysnfs_get (serialNum, contextInfo, 						     reqVar)) == NULL) 	    {	    return ((VarBind *) NULL);	    }	/* Get new catche information */     	lastSerialNum = serialNum;		/* Get new catch */	if (last_incoming != NULL)	    FreeOID(last_incoming);		     	last_incoming = CloneOID(incoming);	}    else	{	reqVar = object->nominator;	}    /* Build the variable binding.  */    switch (reqVar) 	{	case I_nfsUserId:	    dp = (void *) &nfsVars->nfsUserId;	    break;	case I_nfsGroupId:	    dp = (void *) &nfsVars->nfsGroupId;	    break;	default:	    return ((VarBind *) NULL);	}    /*     *  Construct the response for the SNMP agent.  The structure returned     *  will be strung onto the response PDU.  The global strucutre ZeroOid     *  is used for leaf variables.     */    return (MakeVarBind (object, &ZeroOid, dp));    }/********************************************************************************* sysnfs_free -  Free the nfs structure.** This routine is invoked indirectly by the SNMP agent to free the system* nfs structure that was allocated during the call to test, and after the call* to set, or after the test fails.** RETURNS: N/A** SEE ALSO:*/LOCAL void sysnfs_free     (    sysnfs_t * nfsVars    )    {    if (nfsVars != NULL) 	{	free ((char *) nfsVars);	}    }/********************************************************************************* sysnfs_cleanup -  Free all the resources allocated in sysnfs_test.** This routine is invoked by the SNMP agent after the set operation has taken* placed or if the test routine failed.** RETURNS: NO_ERROR always successful.** SEE ALSO:*/LOCAL int sysnfs_cleanup    (    doList_t *trash    )    {    sysnfs_free (trash->data);    sysnfs_free (trash->undodata);    return NO_ERROR;    }/********************************************************************************* sysnfs_undo -  provided for future use** RETURNS: ERROR** SEE ALSO:*/LOCAL int sysnfs_undo    (    )    {    return UNDO_FAILED_ERROR;    }/********************************************************************************* sysnfs_test -  Validate new values for the MIB variables.** This routine ensures that the value to which a MIB variable is to be set is* in accordance to its MIB definition in the file vxdemo.my.  After all the* variables required to update the an entry or variable is collected, the state* of the doList structure is set to ADD_MODIFY or DELETE, based on the operaion* requested.** RETURNS: NO_ERROR for successful validation, otherwise an error is returned.** SEE ALSO:*/int sysnfs_test     (    OID           * incoming,    /* Ptr to the OID received in the SNMP PDU */    ObjectInfo    * object,      /* Ptr to MIB var in the SNMP MIB tree */    ObjectSyntax  * value,       /* Ptr the value to set the MIB variable */    doList_t      * doHead,      /* Ptr to the list of SNMP outstanding reqs */    doList_t      * doCur,       /* Ptr to free doList element */    ContextInfo   * contextInfo  /* Reserved for Future Use */    )    {    sysnfs_t      * nfsVars;    int             instLength;    /*      * instLength represents the length of the (incoming) requested OID     * beyond the Object Identifier specified in the MIB tree.  This value     * is used to validate the request on an EXACT or NEXT search.  Ex.     * The MIB variable fakeMibVar = OID 1.3.6.1.4.1.731.1.1.2 and is      * specified this way in the object variable.  The incoming would     * have fakeMibVar.0 = OID 1.3.6.1.4.1.731.1.1.2.0, the length would     * be 1 and the last value 0.  This information is used to valiate the     * EXACT search.  In the case of a NEXT search the length must be 0     * for leaf variables.  For table entries with an integer index the      * incoming OID would be 1.3.6.1.4.1.731.1.1.2.INDEX and the length     * would represent the index.  In the case of a set operation the variable     * needs to be specified exactly and therefore the length must be 1.     */    instLength = incoming->length - object->oid.length;    if (instLength != 1 || incoming->oid_ptr [object->oid.length] != 0)	return (NO_ACCESS_ERROR);    /*     * Create the data portion of the do-list element and initialize it. This     * needs to use "calloc" so all the pointers in this structure are     * initialized to NULL. The state is set to READY since the element will     * be deleted if invalid.     */    if ((doCur->data = (void *) calloc (1, sizeof(sysnfs_t))) == NULL) 	{	return (GEN_ERROR);	}    doCur->setMethod     = sysnfs_set;    doCur->cleanupMethod = sysnfs_cleanup;    doCur->undoMethod   = sysnfs_undo;    doCur->state         = UNKNOWN;    nfsVars = (sysnfs_t *) (doCur->data);    /* Validate the value and store it in the do-list.  */    switch (object->nominator) 	{	case I_nfsUserId:		    /* The User ID must be a positive number */	    if (value->sl_value < 0)		return (WRONG_VALUE_ERROR);	    SET_VALID(I_nfsUserId, nfsVars->valid);  /* Set valid vector */	    nfsVars->nfsUserId = value->sl_value;  /* Cpy to alloc struct */	    break;	case I_nfsGroupId:	    /* The Group ID must be a positive number */	    if (value->sl_value < 0)		return (WRONG_VALUE_ERROR);	    SET_VALID(I_nfsGroupId, nfsVars->valid);  /* Set valid vector */	    nfsVars->nfsGroupId = value->sl_value;  /* Cpy to alloc struct */	    break;	default:	    DPRINTF((0, "snmpd: Internal error (invalid nominator \		    in sysnfs_test)\n"));	    return (GEN_ERROR);    }				/* switch */    doCur->state = ADD_MODIFY;    return (NO_ERROR);    }/********************************************************************************* sysnfs_set -  Invokes k_ logic to set the sysnfs variable.** This set routine assumes that the variables to be set are correct.  This* assumption is safe because the test routine has already validated the* variable(s) and set the state of the operation.** RETURNS: Success or Error to the SNMP agent.** SEE ALSO:*/int sysnfs_set     (    doList_t       * doHead,      /* Ptr to the list of SNMP outstanding reqs */    doList_t       * doCur,       /* Ptr to free doList element */    ContextInfo    * contextInfo  /* Reserved for future used */    )    {    return (k_sysnfs_set ((sysnfs_t *) (doCur->data), contextInfo,			   doCur->state));    }/********************************************************************************* nfsEntry_get -  Read the value of a variable in the requested NFS entry.** This routine returns the value of the requested MIB variable that corresponds* to its group.   All the values from the group are obtain from the "k_"* logic but only the requested value is returned by this function.** RETURNS: A pointer to a VarBind struct, or NULL if the request is invalid.** SEE ALSO:*/VarBind * nfsEntry_get 

⌨️ 快捷键说明

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