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

📄 ax_core.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
int i;if (vbp) {    while(vbp) {        need += ax_varbind_size(vbp);	vbp = vbp->vb_link;        }    }else {    while(vblp) {        for(i = vblp->vbl_count, tempvbp = vblp->vblist; 	    i;	    i--, tempvbp++) {	    need += ax_varbind_size(tempvbp);	    }	vblp = vblp->vblp;        }    }return(need);}/****************************************************************************NAME: ax_search_list_sizePURPOSE: Figure out how big a search list will be.	 If the varbind pointer isn't 0 we use it as the root	 for the linked list of varbinds we are interested in,	 otherwise we use the list(s) from the vbl.PARAMETERS: VBL_T *	    VB_T *RETURNS: bits32_t the required space, 0 indicates problems.****************************************************************************/static bits32_t  ax_search_list_size(VBL_T *vblp,		      VB_T  *vbp){bits32_t need = 0; VB_T *tempvbp;int i;if (vbp) {    while(vbp) {        need += ax_obj_id_size(&vbp->vb_obj_id, 0) +	        ax_obj_id_size(&vbp->ax_search_end, 0);	vbp = vbp->vb_link;        }    }else {    while(vblp) {        for(i = vblp->vbl_count, tempvbp = vblp->vblist; 	    i;	    i--, tempvbp++) {	    need += ax_obj_id_size(&tempvbp->vb_obj_id, 0) +	            ax_obj_id_size(&tempvbp->ax_search_end, 0);	    }	vblp = vblp->vblp;        }    }return(need);}/********************************************************************************* envoy_ax_pkt_size - determine the expected encoded size of an AgentX packet* SYNOPSIS** \cs* ALENGTH_T envoy_ax_pkt_size*     ( *     ENVOY_AX_PKT_T *  ax_pkt, *     VB_T           *  vbp*     )* \ce** DESCRIPTION** This routine determines how much space the specified packet will require when * it is encoded. This routine assumes that the packet is properly formatted and * does not contain any unused defined fields.** PARAMETERS* \is* \i <*ax_pkt>* Specify an AgentX packet.* \i <*vbp>* Specify the root of a linked list of 'VarBinds'. To use the 'VarBindList' * from the packet structure, set this value to 0.* \ie** RETURNS: If successful, this routine returns the size of the packet in * encoded form. Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: envoy_ax_pkt_encode()*/ALENGTH_T  envoy_ax_pkt_size(ENVOY_AX_PKT_T *ax_pkt,		    VB_T           *vbp){bits32_t   need;/* start with the header */need = SIZEOF_AGENTX_PDU;/* add in the context if it exists */if (ax_pkt->flags & ENVOY_AX_BIT_NDC) {    need += ax_string_size(&ax_pkt->context);    }switch(ax_pkt->type) {    default:        return(0);    case ENVOY_AX_OPEN:        /* we have 4 bytes of tags, an oid and a string */        need += 4 + ax_obj_id_size(&ax_pkt->data.open_data.sub_id, 0) +	        ax_string_size(&ax_pkt->data.open_data.descr);        break;    case ENVOY_AX_CLOSE:	/* we have 4 bytes of tags */	need += SIZEOF_AGENTX_CLOSE;	break;    case ENVOY_AX_REGISTER:    case ENVOY_AX_UNREGISTER:	/* we always have 4 bytes of tags and an oid */	need += 4 + ax_obj_id_size(&ax_pkt->data.reg_data.region, 				   ax_pkt->data.reg_data.range);	/* if we have a range we have another oidc, 4 bytes) */	if (ax_pkt->data.reg_data.range)	    need += 4;	break;    case ENVOY_AX_GET:    case ENVOY_AX_NEXT:	/* we have a search list */	need += ax_search_list_size(&ax_pkt->data.proc_data.vbl_str, vbp);	break;    case ENVOY_AX_BULK:	/* we have non reps (2) & max reps (2) + a search list */	need += SIZEOF_AGENTX_BULK;	need += ax_search_list_size(&ax_pkt->data.proc_data.vbl_str, vbp);	break;    case ENVOY_AX_RESPONSE:	/* uptime and error index & status: 8,	   and a varbind list (which may be empty) */	need += SIZEOF_AGENTX_RESP;	need += ax_varbind_list_size(&ax_pkt->data.proc_data.vbl_str, vbp);	break;    case ENVOY_AX_TEST:    case ENVOY_AX_NOTIFY:    case ENVOY_AX_INDEX_ALLOCATE:    case ENVOY_AX_INDEX_DEALLOCATE:	/* a varbind list */	need += ax_varbind_list_size(&ax_pkt->data.proc_data.vbl_str, vbp);	break;    case ENVOY_AX_COMMIT:    case ENVOY_AX_UNDO:    case ENVOY_AX_CLEANUP:    case ENVOY_AX_PING:	/* just headers */	break;    case ENVOY_AX_ADD_AC:	/* a string and an oid */	need += ax_string_size(&ax_pkt->data.open_data.descr) +	        ax_obj_id_size(&ax_pkt->data.open_data.sub_id, 0);	break;    case ENVOY_AX_REMOVE_AC:	/* an oid */	need += ax_obj_id_size(&ax_pkt->data.open_data.sub_id, 0);	break;    }/* Check for 16-bit overflow. */if ((need & 0xffff) == need)     return((ALENGTH_T) need);else     return(0);}/****************************************************************************NAME: ax_obj_id_encodePURPOSE: Encode an object id	 The object id should be complete (all subids intact, no	 prefix manipulation occurring) and we will return the	 length including the object header but without any	 prefixable subids.	 The length will be 4 + (4 * non-prefix subids).PARAMETERS: EBUFFER_T *	    bist8_t	    OBJ_ID_T *	    bits8_tRETURNS: void****************************************************************************/static void  ax_obj_id_encode(EBUFFER_T *ebuffp,		   bits8_t    order,		   OBJ_ID_T  *objid,		   bits8_t    inc,		   bits8_t    range_id){bits8_t  *bytes;OIDC_T prefix = 0, *subid;int num;bytes = EBufferNext(ebuffp);num = objid->num_components;subid = objid->component_list;if (ax_is_prefix(objid, range_id)) {    prefix = objid->component_list[4];    subid += 5;    num -= 5;    }/* because we encode using the bytes pointer we can update   the ebuffer before we write to it, this avoids having   to reget num after we decrement it. */ (void) EBufferSeek(ebuffp, SIZEOF_AGENTX_OID + (num * 4), 1);SET_AGENTX_OID_N_SUBID(bytes, num);SET_AGENTX_OID_PREFIX(bytes, prefix);SET_AGENTX_OID_INCLUDE(bytes, inc);bytes[3] = 0;bytes += SIZEOF_AGENTX_OID;if (order)    for(; num; num--, subid++, bytes += 4) {        GLUE_SB32((GLUE_CAST_PTR(bytes)), GLUE_CAST32(*subid));        }else    for(; num; num--, subid++, bytes += 4) {        GLUE_SL32((GLUE_CAST_PTR(bytes)), GLUE_CAST32(*subid));        }}/****************************************************************************NAME: ax_string_encodePURPOSE: Encode a string	 The length will be 4 + strlen + padding bytesPARAMETERS: EBUFFER_T * the string to encode info into	    EBUFFER_T * the string to copyRETURNS: void****************************************************************************/static void  ax_string_encode(EBUFFER_T *ebuffp,		   bits8_t    order,		   EBUFFER_T *strbuf){bits8_t   *bytes;ALENGTH_T temp;bytes = EBufferNext(ebuffp);temp = EBufferUsed(strbuf);/* the length */if (order) {    SET_AGENTX_OCT_STR_LEN_B(bytes, temp);    }else {    SET_AGENTX_OCT_STR_LEN_L(bytes, temp);    }bytes += SIZEOF_AGENTX_OCT_STR_LEN;/* if we have bytes the string */if (temp) {    MEMCPY(bytes, EBufferStart(strbuf), temp);    bytes += temp;    }/* the padding */temp = temp%4; if (temp) {    temp = (4-temp);    MEMSET(bytes, 0, temp);    } (void) EBufferSeek(ebuffp, SIZEOF_AGENTX_OCT_STR_LEN +		            EBufferUsed(strbuf) + temp, 1);}/****************************************************************************NAME: ax_varbind_encodePURPOSE: encode a varbind	 The length will be 4 + objectid + dataPARAMETERS: EBUFFER_T *	    bits8_t   	    VB_T      *RETURNS: void****************************************************************************/static void  ax_varbind_encode(EBUFFER_T *ebuffp,		    bits8_t    order,		    VB_T      *vbp){bits8_t *bytes;bytes = EBufferNext(ebuffp);if (order) {    SET_AGENTX_VARBIND_TYPE_B(bytes, vbp->vb_data_flags_n_type);    }else {    SET_AGENTX_VARBIND_TYPE_L(bytes, vbp->vb_data_flags_n_type);    }bytes[2] = bytes[3] = 0;EBufferSeek(ebuffp, 4, 1);ax_obj_id_encode(ebuffp, order, &vbp->vb_obj_id, vbp->ax_flags, 0);bytes = EBufferNext(ebuffp);switch(vbp->vb_data_flags_n_type) {    default:        /* unknown type, shouldn't get here */        return;    case VT_NUMBER:    case VT_COUNTER:    case VT_GAUGE:    case VT_TIMETICKS:	if (order) {	    GLUE_SB32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_number));	    }	else {	    GLUE_SL32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_number));	    }	EBufferSeek(ebuffp, SIZEOF_AGENTX_UNSIGNED32, 1);	break;    case VT_STRING:    case VT_OPAQUE:	ax_string_encode(ebuffp, order, &vbp->value_u.v_string);	break;    case VT_OBJECT:	ax_obj_id_encode(ebuffp, order, &vbp->value_u.v_object, 0, 0);	break;    case VT_EMPTY:    case VT_NOSUCHOBJ:    case VT_NOSUCHINS:    case VT_ENDOFMIB:	break;    case VT_IPADDRESS:	if (order) {	    GLUE_SB32((GLUE_CAST_PTR(bytes)), GLUE_CAST32(4L));	    }	else {	    GLUE_SL32((GLUE_CAST_PTR(bytes)), GLUE_CAST32(4L));	    }	MEMCPY(bytes + SIZEOF_AGENTX_OCT_STR,	       vbp->value_u.v_network_address, 4);	EBufferSeek(ebuffp, SIZEOF_AGENTX_OCT_STR + 4, 1);	break;    case VT_COUNTER64:	if (order) {	    GLUE_SB32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_counter64.high));	    bytes += SIZEOF_AGENTX_UNSIGNED32;	    GLUE_SB32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_counter64.low));	    }	else {	    GLUE_SL32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_counter64.low));	    bytes += SIZEOF_AGENTX_UNSIGNED32;	    GLUE_SL32((GLUE_CAST_PTR(bytes)),		      GLUE_CAST32(vbp->value_u.v_counter64.high));	    }	EBufferSeek(ebuffp, SIZEOF_AGENTX_UNSIGNED64, 1);	break;    }}/****************************************************************************NAME: ax_varbind_list_encodePURPOSE: Figure out how big a varbind list will be.	 If the varbind pointer isn't 0 we use it as the root	 for the linked list of varbinds we are interested in,	 otherwise we use the list(s) from the vbl.PARAMETERS: EBUFFER_T *	    bits8_t   	    VBL_T     *	    VB_T      *RETURNS: void****************************************************************************/static void  ax_varbind_list_encode(EBUFFER_T *ebuffp,			 bits8_t    order,			 VBL_T     *vblp,			 VB_T      *vbp){VB_T *tempvbp;int i;if (vbp) {    while(vbp) {        ax_varbind_encode(ebuffp, order, vbp);	vbp = vbp->vb_link;        }    }else {    while(vblp) {        for(i = vblp->vbl_count, tempvbp = vblp->vblist; 	    i;	    i--, tempvbp++) {	    ax_varbind_encode(ebuffp, order, tempvbp);	    }	vblp = vblp->vblp;        }    }}/****************************************************************************NAME: ax_search_list_encodePURPOSE: Figure out how big a search list will be.	 If the varbind pointer isn't 0 we use it as the root	 for the linked list of varbinds we are interested in,	 otherwise we use the list(s) from the vbl.PARAMETERS: EBUFFER_T *	    bits8_t	    VBL_T *	    VB_T *RETURNS: void****************************************************************************/

⌨️ 快捷键说明

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