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

📄 ax_sa_cr.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
return(envoy_ax_pkt_encode(&ax_pkt, 0, ebuffp, 0));}/********************************************************************************* envoy_ax_pkt_create_agent_caps - create an encoded AgentX agent capabilities packet* SYNOPSIS** \cs* int envoy_ax_pkt_create_agent_caps*     ( *     EBUFFER_T *  ebuffp *     bits8_t      version, *     bits8_t      pdu_type, *     bits8_t      flags, *     bits32_t     packet_id, *     bits32_t     session_id, *     bits32_t     descr_len, *     bits8_t   *  descr, *     bits32_t     context_len, *     bits8_t   *  context, *     OBJ_ID_T  *  obj*     )* \ce** DESCRIPTION** This routine creates an encoded AgentX agent capabilities packet and places * the encoded packet in <ebuffp>. Since this routine does not create a lasting * AgentX packet structure, it does not keep a pointer to <context> or <descr>.** PARAMETERS* \is* \i <*ebuffp>* Point to an 'EBUFFER_T' structure that will be filled with the encoded * packet. The <ebuffp> may be a start pointer to an offset in this <ebuffp> or * a next pointer to another <ebuffp>. If no space is provided in the <ebuffp>, * it is the responsibility of the caller to free this space. You can use * SNMP_memory_alloc(), SNMP_memory_free() to allocate space in an <ebuffp>.* \i <version>* Specify the AgentX version number. At this release, the only supported * version is 'ENVOY_AX_VERSION_1'.* \i <pdu_type>* Indicate which type of message you are trying to create. This routine * supports the following types: 'ENVOY_AX_ADD_AC' or 'ENVOY_AX_REMOVE_AC.'* \i <flags>* Specify the bits for the flag word of the packet header. This routine * supports the following flags:* \is* \i 'ENVOY_AX_BIT_ND C'* Select a non-default context supplied by the user.* \i 'ENVOY_AX_BIT_BYTE_ORDER'* Select network-byte order for encoding or decoding.* \ie* \i <packet_id>* Specify a number that allows the requester to match responses to requests.* \i <session_id>* Indicate to which session this packet belongs. When a subagent first opens a * session, this value is 0. Afterward, this value is the session ID supplied by * the master.* \i <descr_len>* Specify the length in bytes of a descriptive field (<descr>), which is passed * to the master agent to describe the subagent in an open request or the agent * capabilities when adding an agent capabilities packet.* \i <*descr>* Specify the descriptive string.* \i <context_len>* Indicate the length in bytes of the context string (<context>), which is * passed to the master agent when a non-default context is used.* \i <*context>* Specify the context string.* \i <*obj>* Specify the object ID to add or remove depending on the PDU type.* \ie** RETURNS: If successful, this routine returns 0. Otherwise, it returns one of * the following values:* \is* \i 'ENVOY_AX_ALLOCATION_FAILURE'* Unable to allocate an AgentX packet.* \i 'ENVOY_AX_BAD_SIZE'* Insufficient space requested.* \i 'ENVOY_AX_BAD_VALUE'* The packet was badly formed or <ebuffp> did not match its expected size.* \i 'ENVOY_AX_TOO_SMALL'* The string is either smaller than the minimum PDU size or does not match the * expected length.* \ie** ERRNO: N/A** SEE ALSO: envoy_ax_pkt_create_all(), envoy_ax_pkt_create_close(), * envoy_ax_pkt_create_open(), envoy_ax_pkt_create_ping(), * envoy_ax_pkt_create_registrations(), envoy_ax_pkt_create_variables(), * SNMP_memory_alloc(), SNMP_memory_free()*/int  envoy_ax_pkt_create_agent_caps(EBUFFER_T * ebuffp,				 bits8_t     version,				 bits8_t     pdu_type,				 bits8_t     flags,				 bits32_t    packet_id,				 bits32_t    session_id,				 bits32_t    descr_len,				 bits8_t   * descr,				 bits32_t    context_len,				 bits8_t   * context,				 OBJ_ID_T  * obj){ENVOY_AX_PKT_T ax_pkt;envoy_ax_pkt_init(&ax_pkt);/* validity check the arguments */if ((version != ENVOY_AX_VERSION_1) ||    (flags & (ENVOY_AX_BIT_NEW_INDEX | ENVOY_AX_BIT_ANY_INDEX |	      ENVOY_AX_BIT_INSTANCE))) {    return(ENVOY_AX_BAD_VALUE);    }if (pdu_type == ENVOY_AX_ADD_AC) {    ax_pkt.type = ENVOY_AX_ADD_AC;    EBufferPreLoad(BFL_IS_STATIC, &ax_pkt.data.open_data.descr,		   descr, descr_len);    }else if (pdu_type == ENVOY_AX_REMOVE_AC) {    ax_pkt.type = ENVOY_AX_REMOVE_AC;    }else    return(ENVOY_AX_BAD_VALUE);ax_pkt.version   = version;ax_pkt.flags     = flags;ax_pkt.packet_id  = packet_id;ax_pkt.session_id = session_id;/* Note that we don't build a new copy of the object id here   so we MUST NOT free it later on, we do this to avoid allocating   memory and because we have control of the packet. */ax_pkt.data.open_data.sub_id.num_components = obj->num_components;ax_pkt.data.open_data.sub_id.component_list = obj->component_list;if (flags & ENVOY_AX_BIT_NDC) {    EBufferPreLoad(BFL_IS_STATIC, &ax_pkt.context, context, context_len);    }return(envoy_ax_pkt_encode(&ax_pkt, 0, ebuffp, 0));}/********************************************************************************* envoy_ax_pkt_create_variables - allocate space for an AgentX packet structure* SYNOPSIS** \cs* ENVOY_AX_PKT_T * envoy_ax_pkt_create_variables*     ( *     int      *  err, *     bits8_t     version, *     bits8_t     pdu_type, *     bits8_t     flags, *     bits32_t    session_id, *     bits32_t    packet_id, *     bits32_t    context_len, *     bits8_t  *  context, *     int         context_dynamic, *     int         num_vbs*     )* \ce** DESCRIPTION** This routine allocates space for an AgentX packet structure and a * 'VarBindList' with space for the requested number of 'VarBinds'. After you * create a packet with this routine, you must call an AgentX bind routine to * bind the 'VarBinds' into the packet. Use this routine for index allocation, * index deallocation, and notifies.** PARAMETERS* \is* \i <*err>* Contain an error code when this routine fails.* \i <version>* Specify the AgentX version number. At this release, the only supported * version is 'ENVOY_AX_VERSION_1'.* \i <pdu_type>* Indicate which type of message you are trying to create. This routine * supports the following types: 'ENVOY_AX_INDEX_ALLOCATE', * 'ENVOY_AX_INDEX_DEALLOCATE', or 'ENVOY_AX_NOTIFY'.* \i <flags>* Specify the bits for the flag word of the packet header. This routine * supports the following flags:* \is* \i 'ENVOY_AX_BIT_ANY_INDEX'* Indicate that any unused index will do. This flag is useful only for index * allocate requests.* \i 'ENVOY_AX_BIT_NEW_INDEX'* Indicate that indices that have not been used before are desired. This flag * is useful only for index allocate requests.* \i 'ENVOY_AX_BIT_NDC'* Select a non-default context supplied by the user.* \i 'ENVOY_AX_BIT_BYTE_ORDER'* Select network-byte order.* \ie* \i <session_id>* Indicate to which session this packet belongs. When a subagent first opens a * session, this value is 0. Afterward, this value is the session ID supplied by * the master.* \i <packet_id>* Specify a number that allows the requester to match responses to requests.* \i <context_len>* Indicate the length in bytes of the context string (<context>), which is * passed to the master agent when a non-default context is used.* \i <*context>* Specify the context string.* \i <context_dynamic>* Indicate whether context is dynamic ('BFL_IS_DYNAMIC') and should be freed * when the packet is cleaned or not ('BFL_IS_STATIC'). If you choose to use a * non-default context, set the 'ENVOY_AX_BIT_NDC' flag.* \i <num_vbs>* Indicate the number of 'VarBinds' in the 'VarBindList'.* \ie** RETURNS: If successful, this routine returns a pointer to the newly created * packet. Otherwise, it returns 0 and returns one of the following values:* \is* \i 'ENVOY_AX_ALLOCATION_FAILURE'* Unable to allocate an AgentX packet.* \i 'ENVOY_AX_BAD_SIZE'* Insufficient space requested.* \i 'ENVOY_AX_BAD_VALUE'* The packet was badly formed or <ebuffp> did not match its expected size.* \i 'ENVOY_AX_TOO_SMALL'* The string is either smaller than the minimum PDU size or does not match the * expected length.* \ie** ERRNO: N/A** SEE ALSO: envoy_ax_pkt_create_all(), envoy_ax_pkt_create_agent_caps(), * envoy_ax_pkt_create_close(), envoy_ax_pkt_create_open(), * envoy_ax_pkt_create_ping(), envoy_ax_pkt_create_registrations()*/ENVOY_AX_PKT_T *  envoy_ax_pkt_create_variables(int      *err,				bits8_t   version,				bits8_t   pdu_type,				bits8_t   flags,				bits32_t  session_id,				bits32_t  packet_id,				bits32_t  context_len,				bits8_t  *context,				int       context_dynamic,				int       num_vbs){ENVOY_AX_PKT_T *ax_pkt;/* test the version before we get the packet */if (version != ENVOY_AX_VERSION_1) {    *err = ENVOY_AX_BAD_VALUE;    return(0);    }switch(pdu_type) {    default:        *err = ENVOY_AX_BAD_VALUE;	return(0);    case ENVOY_AX_NOTIFY:        if (flags & (ENVOY_AX_BIT_NEW_INDEX | ENVOY_AX_BIT_ANY_INDEX |		     ENVOY_AX_BIT_INSTANCE)) {	    *err = ENVOY_AX_BAD_VALUE;	    return(0);	    }        break;    case ENVOY_AX_INDEX_ALLOCATE:        if (flags & ENVOY_AX_BIT_INSTANCE) {	    *err = ENVOY_AX_BAD_VALUE;	    return(0);	    }	break;    case ENVOY_AX_INDEX_DEALLOCATE:        if (flags & (ENVOY_AX_BIT_NEW_INDEX | ENVOY_AX_BIT_ANY_INDEX |		     ENVOY_AX_BIT_INSTANCE)) {	    *err = ENVOY_AX_BAD_VALUE;	    return(0);	    }	break;    }/* get the packet */ax_pkt = envoy_ax_pkt_allocate();if (ax_pkt == 0) {    *err = ENVOY_AX_ALLOCATION_FAILURE;    return(0);    }/* Do we need to allocate a var bind list? */if (num_vbs == 0) {    ax_pkt->data.proc_data.vbl_str.vbl_count = 0;    ax_pkt->data.proc_data.vbl_str.vblist = 0;    }else {    ax_pkt->data.proc_data.vbl_str.vblist = VarBindList_Allocate(num_vbs);    if (ax_pkt->data.proc_data.vbl_str.vblist == 0) {        envoy_ax_pkt_free(ax_pkt);	*err = ENVOY_AX_ALLOCATION_FAILURE;	return(0);        }    ax_pkt->data.proc_data.vbl_str.vbl_count = num_vbs;    }/* put the generic stuff into the packet */ ax_pkt->version   = version;ax_pkt->type      = pdu_type;ax_pkt->flags     = flags;ax_pkt->session_id = session_id;ax_pkt->packet_id  = packet_id;if (flags & ENVOY_AX_BIT_NDC) {    EBufferPreLoad(context_dynamic, &ax_pkt->context, context, context_len);    }return(ax_pkt);}/****************************************************************************NAME: ax_index_to_vbpPURPOSE: translate a (zero based) index into the specified vbpPARAMETERS: ENVOY_AX_PKT_T *	    intRETURNS: VB_T *, 0 on failure****************************************************************************/static VB_T *  ax_index_to_vbp(ENVOY_AX_PKT_T *ax_pkt,		  int             indx){VBL_T *vblp;/* Does this type of packet have a varbind list? */switch(ax_pkt->type) {    default:        return(0);    case ENVOY_AX_NOTIFY:    case ENVOY_AX_INDEX_ALLOCATE:    case ENVOY_AX_INDEX_DEALLOCATE:	break;    }vblp = &ax_pkt->data.proc_data.vbl_str;/* Check whether the requested index is within the VarBindList  */for (; vblp; vblp = vblp->vblp) {    if (vblp->vbl_count > indx)        return &(vblp->vblist[indx]);    else        indx -= vblp->vbl_count;    }return (0);}/********************************************************************************* envoy_ax_bind_integer - bind an integer valued 'VarBind' into an AgentX packet* SYNOPSIS** \cs* int envoy_ax_bind_integer*     (*     ENVOY_AX_PKT_T *  ax_pkt, *     int               index, *     int               tcount, *     OIDC_T         *  tlist, *     sbits32_t         value*     )* \ce** DESCRIPTION** This routine binds an integer valued 'VarBind' into the list of an AgentX * packet structure created by envoy_ax_pkt_create_variables().** PARAMETERS* \is* \i <*ax_pkt>* Specify an AgentX packet.* \i <index>* Specify the zero-based index indicating which 'VarBind' entry to use.* \i <tcount>* Specify the component count of the object identifier of the 'VarBind' being * bound.* \i <*tlist>* Specify the components of the object identifier of the 'VarBind' being bound.* \i <value>* Specify the integer value to be bound.* \ie** RETURNS: If successful, this routine returns 0. Otherwise, it returns -1.** ERRNO: N/A** SEE ALSO: envoy_ax_bind_ip_address(), envoy_ax_bind_null(), * envoy_ax_bind_object_id(), envoy_ax_bind_string(), envoy_ax_bind_uint(), * envoy_ax_bind_uint_64(), envoy_ax_pkt_create_variables()*/int  envoy_ax_bind_integer(ENVOY_AX_PKT_T *ax_pkt,			int             indx,			int             tcount,			OIDC_T         *tlist,			sbits32_t       value){VB_T    *vbp;if ((vbp = ax_index_to_vbp(ax_pkt, indx)) == 0)    return -1;if (build_object_id(tcount, tlist, &(vbp->vb_obj_id)) == -1)    return -1;vbp->vb_data_flags_n_type = VT_NUMBER;vbp->value_u.v_number = value;return 0;}/********************************************************************************* envoy_ax_bind_ip_address - bind an IP address valued 'VarBind' into the list* SYNOPSIS** \cs* int envoy_ax_bind_ip_address*     ( *     ENVOY_AX_PKT_T *  ax_pkt, 

⌨️ 快捷键说明

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