X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/b9a93a401ed787e64d11341b76cb87eb92b207e9..refs/pull/482/head:/print-vqp.c diff --git a/print-vqp.c b/print-vqp.c index 21d89fc2..76140113 100644 --- a/print-vqp.c +++ b/print-vqp.c @@ -12,27 +12,18 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * support for the Cisco prop. VQP Protocol + * support for the Cisco prop. VQP Protocol * * Original code by Carles Kishimoto */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-vqp.c,v 1.1 2006-03-03 22:31:16 hannes Exp $"; -#endif - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include -#include -#include -#include - -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -52,23 +43,16 @@ static const char rcsid[] _U_ = */ struct vqp_common_header_t { - u_int8_t version; - u_int8_t msg_type; - u_int8_t error_code; - u_int8_t nitems; - u_int8_t sequence[4]; -}; - -struct vqp_tlv_reqjoinport_t { - u_int8_t obj_type[4]; - u_int8_t obj_length[2]; + uint8_t version; + uint8_t msg_type; + uint8_t error_code; + uint8_t nitems; + uint8_t sequence[4]; }; -struct vqp_tlv_respvlan_t { - u_int8_t obj_type[4]; - u_int8_t unknown1[8]; /* XXX */ - u_int8_t obj_length[2]; - u_int8_t unknown2[4]; /* XXX */ +struct vqp_obj_tlv_t { + uint8_t obj_type[4]; + uint8_t obj_length[2]; }; #define VQP_OBJ_REQ_JOIN_PORT 0x01 @@ -112,119 +96,97 @@ static const struct tok vqp_obj_values[] = { { 0, NULL} }; -#define FALSE 0 -#define TRUE 1 - void -vqp_print(register const u_char *pptr, register u_int len) +vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { const struct vqp_common_header_t *vqp_common_header; - union { - const struct vqp_tlv_reqjoinport_t *reqjoinport; - const struct vqp_tlv_respvlan_t *respvlan; - } vqp_tlv; + const struct vqp_obj_tlv_t *vqp_obj_tlv; const u_char *tptr; - u_int16_t vqp_obj_len; - u_int32_t vqp_obj_type; - int tlen, hexdump; - u_int8_t nitems; + uint16_t vqp_obj_len; + uint32_t vqp_obj_type; + int tlen; + uint8_t nitems; tptr=pptr; tlen = len; vqp_common_header = (const struct vqp_common_header_t *)pptr; - TCHECK(*vqp_common_header); + ND_TCHECK(*vqp_common_header); /* * Sanity checking of the header. */ if (VQP_EXTRACT_VERSION(vqp_common_header->version) != VQP_VERSION) { - printf("VQP version %u packet not supported", - VQP_EXTRACT_VERSION(vqp_common_header->version)); + ND_PRINT((ndo, "VQP version %u packet not supported", + VQP_EXTRACT_VERSION(vqp_common_header->version))); return; } /* in non-verbose mode just lets print the basic Message Type */ - if (vflag < 1) { - printf("VQPv%u %s Message, error-code %s (%u), length %u", + if (ndo->ndo_vflag < 1) { + ND_PRINT((ndo, "VQPv%u %s Message, error-code %s (%u), length %u", VQP_EXTRACT_VERSION(vqp_common_header->version), tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), vqp_common_header->error_code, - len); + len)); return; } - + /* ok they seem to want to know everything - lets fully decode it */ nitems = vqp_common_header->nitems; - printf("\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", + ND_PRINT((ndo, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", VQP_EXTRACT_VERSION(vqp_common_header->version), tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), vqp_common_header->error_code, EXTRACT_32BITS(&vqp_common_header->sequence), nitems, - len); + len)); /* skip VQP Common header */ tptr+=sizeof(const struct vqp_common_header_t); tlen-=sizeof(const struct vqp_common_header_t); - while (nitems > 0) { - - switch (vqp_common_header->msg_type) { - case VQP_OBJ_REQ_JOIN_PORT: - vqp_tlv.reqjoinport = (const struct vqp_tlv_reqjoinport_t *)tptr; - vqp_obj_type = EXTRACT_32BITS(vqp_tlv.reqjoinport->obj_type); - vqp_obj_len = EXTRACT_16BITS(vqp_tlv.reqjoinport->obj_length); - tptr+=sizeof(struct vqp_tlv_reqjoinport_t); - tlen-=sizeof(struct vqp_tlv_reqjoinport_t); - break; - case VQP_OBJ_RESP_VLAN: - vqp_tlv.respvlan = (const struct vqp_tlv_respvlan_t *)tptr; - vqp_obj_type = EXTRACT_32BITS(vqp_tlv.respvlan->obj_type); - vqp_obj_len = EXTRACT_16BITS(vqp_tlv.respvlan->obj_length); - tptr+=sizeof(struct vqp_tlv_respvlan_t); - tlen-=sizeof(struct vqp_tlv_respvlan_t); - break; - default: - /* bail - don't know the TLV format of the message type */ - return; - } + while (nitems > 0 && tlen > 0) { - /* did we capture enough for fully decoding the object ? */ - if (!TTEST2(*tptr, vqp_obj_len)) - goto trunc; - hexdump=FALSE; + vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; + vqp_obj_type = EXTRACT_32BITS(vqp_obj_tlv->obj_type); + vqp_obj_len = EXTRACT_16BITS(vqp_obj_tlv->obj_length); + tptr+=sizeof(struct vqp_obj_tlv_t); + tlen-=sizeof(struct vqp_obj_tlv_t); - printf("\n\t %s Object (0x%08x), length %u, value: ", + ND_PRINT((ndo, "\n\t %s Object (0x%08x), length %u, value: ", tok2str(vqp_obj_values, "Unknown", vqp_obj_type), - vqp_obj_type, vqp_obj_len); + vqp_obj_type, vqp_obj_len)); /* basic sanity check */ if (vqp_obj_type == 0 || vqp_obj_len ==0) { return; } + /* did we capture enough for fully decoding the object ? */ + ND_TCHECK2(*tptr, vqp_obj_len); + switch(vqp_obj_type) { case VQP_OBJ_IP_ADDRESS: - printf("%s (0x%08x)", ipaddr_string(tptr), EXTRACT_32BITS(tptr)); + ND_PRINT((ndo, "%s (0x%08x)", ipaddr_string(ndo, tptr), EXTRACT_32BITS(tptr))); break; /* those objects have similar semantics - fall through */ case VQP_OBJ_PORT_NAME: case VQP_OBJ_VLAN_NAME: case VQP_OBJ_VTP_DOMAIN: case VQP_OBJ_ETHERNET_PKT: - safeputs(tptr, vqp_obj_len); + safeputs(ndo, tptr, vqp_obj_len); break; /* those objects have similar semantics - fall through */ case VQP_OBJ_MAC_ADDRESS: case VQP_OBJ_MAC_NULL: - printf("%s", etheraddr_string(tptr)); + ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr))); break; default: - if (vflag <= 1) - print_unknown_data(tptr, "\n\t ", vqp_obj_len); + if (ndo->ndo_vflag <= 1) + print_unknown_data(ndo,tptr, "\n\t ", vqp_obj_len); break; } tptr += vqp_obj_len; @@ -233,5 +195,5 @@ vqp_print(register const u_char *pptr, register u_int len) } return; trunc: - printf("\n\t[|VQP]"); + ND_PRINT((ndo, "\n\t[|VQP]")); }