X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/513f782ae18791f0c925b9235da749b38159b607..a8abce5c5e2dce2ba6dbccd5d3829da104b80f9c:/print-decnet.c diff --git a/print-decnet.c b/print-decnet.c index f90ca6a0..06985d0d 100644 --- a/print-decnet.c +++ b/print-decnet.c @@ -22,7 +22,7 @@ /* \summary: DECnet printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif #include "netdissect-stdinc.h" @@ -31,9 +31,6 @@ #include #include -struct mbuf; -struct rtentry; - #ifdef HAVE_DNET_HTOA #ifdef HAVE_NETDNET_DN_H #include @@ -57,7 +54,6 @@ struct dn_naddr { #include "extract.h" #include "addrtoname.h" -static const char tstr[] = "[|decnet]"; #ifndef _WIN32 typedef nd_uint8_t byte; /* single byte field */ @@ -492,10 +488,10 @@ struct dcmsg /* disconnect confirm message */ /* Forwards */ static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int); static void print_t_info(netdissect_options *, u_int); -static int print_l1_routes(netdissect_options *, const char *, u_int); -static int print_l2_routes(netdissect_options *, const char *, u_int); +static int print_l1_routes(netdissect_options *, const u_char *, u_int); +static int print_l2_routes(netdissect_options *, const u_char *, u_int); static void print_i_info(netdissect_options *, u_int); -static int print_elist(const char *, u_int); +static int print_elist(const u_char *, u_int); static int print_nsp(netdissect_options *, const u_char *, u_int); static void print_reason(netdissect_options *, u_int); @@ -510,25 +506,26 @@ decnet_print(netdissect_options *ndo, u_int nsplen, pktlen; const u_char *nspp; + ndo->ndo_protocol = "decnet"; if (length < sizeof(struct shorthdr)) { - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } ND_TCHECK_LEN(ap, sizeof(short)); pktlen = EXTRACT_LE_U_2(ap); if (pktlen < sizeof(struct shorthdr)) { - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } if (pktlen > length) { - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } length = pktlen; rhp = (const union routehdr *)(ap + sizeof(short)); - ND_TCHECK(rhp->rh_short.sh_flags); + ND_TCHECK_1(rhp->rh_short.sh_flags); mflags = EXTRACT_U_1(rhp->rh_short.sh_flags); if (mflags & RMF_PAD) { @@ -537,7 +534,7 @@ decnet_print(netdissect_options *ndo, if (ndo->ndo_vflag) ND_PRINT("[pad:%u] ", padlen); if (length < padlen + 2) { - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } ND_TCHECK_LEN(ap + sizeof(short), padlen); @@ -545,7 +542,7 @@ decnet_print(netdissect_options *ndo, length -= padlen; caplen -= padlen; rhp = (const union routehdr *)(ap + sizeof(short)); - ND_TCHECK(rhp->rh_short.sh_flags); + ND_TCHECK_1(rhp->rh_short.sh_flags); mflags = EXTRACT_U_1(rhp->rh_short.sh_flags); } @@ -565,10 +562,10 @@ decnet_print(netdissect_options *ndo, switch (mflags & RMF_MASK) { case RMF_LONG: if (length < sizeof(struct longhdr)) { - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } - ND_TCHECK(rhp->rh_long); + ND_TCHECK_SIZE(&rhp->rh_long); dst = EXTRACT_LE_U_2(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr); src = @@ -578,7 +575,7 @@ decnet_print(netdissect_options *ndo, nsplen = length - sizeof(struct longhdr); break; case RMF_SHORT: - ND_TCHECK(rhp->rh_short); + ND_TCHECK_SIZE(&rhp->rh_short); dst = EXTRACT_LE_U_2(rhp->rh_short.sh_dst); src = EXTRACT_LE_U_2(rhp->rh_short.sh_src); hops = (EXTRACT_U_1(rhp->rh_short.sh_visits) & VIS_MASK)+1; @@ -608,7 +605,7 @@ decnet_print(netdissect_options *ndo, return; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return; } @@ -621,9 +618,8 @@ print_decnet_ctlmsg(netdissect_options *ndo, u_int mflags = EXTRACT_U_1(rhp->rh_short.sh_flags); const union controlmsg *cmp = (const union controlmsg *)rhp; u_int src, dst, info, blksize, eco, ueco, hello, other, vers; - etheraddr srcea, rtea; u_int priority; - const char *rhpx = (const char *)rhp; + const u_char *rhpx = (const u_char *)rhp; int ret; switch (mflags & RMF_CTLMASK) { @@ -631,7 +627,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("init "); if (length < sizeof(struct initmsg)) goto trunc; - ND_TCHECK(cmp->cm_init); + ND_TCHECK_SIZE(&cmp->cm_init); src = EXTRACT_LE_U_2(cmp->cm_init.in_src); info = EXTRACT_U_1(cmp->cm_init.in_info); blksize = EXTRACT_LE_U_2(cmp->cm_init.in_blksize); @@ -649,7 +645,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("verification "); if (length < sizeof(struct verifmsg)) goto trunc; - ND_TCHECK(cmp->cm_ver); + ND_TCHECK_SIZE(&cmp->cm_ver); src = EXTRACT_LE_U_2(cmp->cm_ver.ve_src); other = EXTRACT_U_1(cmp->cm_ver.ve_fcnval); ND_PRINT("src %s fcnval %o", dnaddr_string(ndo, src), other); @@ -659,7 +655,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("test "); if (length < sizeof(struct testmsg)) goto trunc; - ND_TCHECK(cmp->cm_test); + ND_TCHECK_SIZE(&cmp->cm_test); src = EXTRACT_LE_U_2(cmp->cm_test.te_src); other = EXTRACT_U_1(cmp->cm_test.te_data); ND_PRINT("src %s data %o", dnaddr_string(ndo, src), other); @@ -669,7 +665,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("lev-1-routing "); if (length < sizeof(struct l1rout)) goto trunc; - ND_TCHECK(cmp->cm_l1rou); + ND_TCHECK_SIZE(&cmp->cm_l1rou); src = EXTRACT_LE_U_2(cmp->cm_l1rou.r1_src); ND_PRINT("src %s ", dnaddr_string(ndo, src)); ret = print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]), @@ -679,7 +675,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("lev-2-routing "); if (length < sizeof(struct l2rout)) goto trunc; - ND_TCHECK(cmp->cm_l2rout); + ND_TCHECK_SIZE(&cmp->cm_l2rout); src = EXTRACT_LE_U_2(cmp->cm_l2rout.r2_src); ND_PRINT("src %s ", dnaddr_string(ndo, src)); ret = print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]), @@ -689,13 +685,12 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("router-hello "); if (length < sizeof(struct rhellomsg)) goto trunc; - ND_TCHECK(cmp->cm_rhello); + ND_TCHECK_SIZE(&cmp->cm_rhello); vers = EXTRACT_U_1(cmp->cm_rhello.rh_vers); eco = EXTRACT_U_1(cmp->cm_rhello.rh_eco); ueco = EXTRACT_U_1(cmp->cm_rhello.rh_ueco); - memcpy((char *)&srcea, (const char *)&(cmp->cm_rhello.rh_src), - sizeof(srcea)); - src = EXTRACT_LE_U_2(srcea.dne_remote.dne_nodeaddr); + src = + EXTRACT_LE_U_2(cmp->cm_rhello.rh_src.dne_remote.dne_nodeaddr); info = EXTRACT_U_1(cmp->cm_rhello.rh_info); blksize = EXTRACT_LE_U_2(cmp->cm_rhello.rh_blksize); priority = EXTRACT_U_1(cmp->cm_rhello.rh_priority); @@ -711,19 +706,17 @@ print_decnet_ctlmsg(netdissect_options *ndo, ND_PRINT("endnode-hello "); if (length < sizeof(struct ehellomsg)) goto trunc; - ND_TCHECK(cmp->cm_ehello); + ND_TCHECK_SIZE(&cmp->cm_ehello); vers = EXTRACT_U_1(cmp->cm_ehello.eh_vers); eco = EXTRACT_U_1(cmp->cm_ehello.eh_eco); ueco = EXTRACT_U_1(cmp->cm_ehello.eh_ueco); - memcpy((char *)&srcea, (const char *)&(cmp->cm_ehello.eh_src), - sizeof(srcea)); - src = EXTRACT_LE_U_2(srcea.dne_remote.dne_nodeaddr); + src = + EXTRACT_LE_U_2(cmp->cm_ehello.eh_src.dne_remote.dne_nodeaddr); info = EXTRACT_U_1(cmp->cm_ehello.eh_info); blksize = EXTRACT_LE_U_2(cmp->cm_ehello.eh_blksize); /*seed*/ - memcpy((char *)&rtea, (const char *)&(cmp->cm_ehello.eh_router), - sizeof(rtea)); - dst = EXTRACT_LE_U_2(rtea.dne_remote.dne_nodeaddr); + dst = + EXTRACT_LE_U_2(cmp->cm_ehello.eh_router.dne_remote.dne_nodeaddr); hello = EXTRACT_LE_U_2(cmp->cm_ehello.eh_hello); other = EXTRACT_U_1(cmp->cm_ehello.eh_data); print_i_info(ndo, info); @@ -764,7 +757,7 @@ print_t_info(netdissect_options *ndo, static int print_l1_routes(netdissect_options *ndo, - const char *rp, u_int len) + const u_char *rp, u_int len) { u_int count; u_int id; @@ -795,7 +788,7 @@ trunc: static int print_l2_routes(netdissect_options *ndo, - const char *rp, u_int len) + const u_char *rp, u_int len) { u_int count; u_int area; @@ -844,7 +837,7 @@ print_i_info(netdissect_options *ndo, } static int -print_elist(const char *elp _U_, u_int len _U_) +print_elist(const u_char *elp _U_, u_int len _U_) { /* Not enough examples available for me to debug this */ return (1); @@ -879,7 +872,7 @@ print_nsp(netdissect_options *ndo, if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[0]); + ND_TCHECK_2(shp->sh_seq[0]); ack = EXTRACT_LE_U_2(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) @@ -889,7 +882,7 @@ print_nsp(netdissect_options *ndo, data_off += sizeof(short); if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[1]); + ND_TCHECK_2(shp->sh_seq[1]); ack = EXTRACT_LE_U_2(shp->sh_seq[1]); if (ack & SGQ_OACK) { /* ackoth field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) @@ -899,7 +892,7 @@ print_nsp(netdissect_options *ndo, data_off += sizeof(short); if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[2]); + ND_TCHECK_2(shp->sh_seq[2]); ack = EXTRACT_LE_U_2(shp->sh_seq[2]); } } @@ -915,7 +908,7 @@ print_nsp(netdissect_options *ndo, if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[0]); + ND_TCHECK_2(shp->sh_seq[0]); ack = EXTRACT_LE_U_2(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) @@ -925,7 +918,7 @@ print_nsp(netdissect_options *ndo, data_off += sizeof(short); if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[1]); + ND_TCHECK_2(shp->sh_seq[1]); ack = EXTRACT_LE_U_2(shp->sh_seq[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) @@ -935,7 +928,7 @@ print_nsp(netdissect_options *ndo, data_off += sizeof(short); if (nsplen < data_off) goto trunc; - ND_TCHECK(shp->sh_seq[2]); + ND_TCHECK_2(shp->sh_seq[2]); ack = EXTRACT_LE_U_2(shp->sh_seq[2]); } } @@ -953,21 +946,21 @@ print_nsp(netdissect_options *ndo, if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg)) goto trunc; - ND_TCHECK(shp->sh_seq[0]); + ND_TCHECK_2(shp->sh_seq[0]); ack = EXTRACT_LE_U_2(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) ND_PRINT("nak %u ", ack & SGQ_MASK); else ND_PRINT("ack %u ", ack & SGQ_MASK); - ND_TCHECK(shp->sh_seq[1]); + ND_TCHECK_2(shp->sh_seq[1]); ack = EXTRACT_LE_U_2(shp->sh_seq[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) ND_PRINT("nakdat %u ", ack & SGQ_MASK); else ND_PRINT("ackdat %u ", ack & SGQ_MASK); - ND_TCHECK(shp->sh_seq[2]); + ND_TCHECK_2(shp->sh_seq[2]); ack = EXTRACT_LE_U_2(shp->sh_seq[2]); } } @@ -1048,7 +1041,7 @@ print_nsp(netdissect_options *ndo, ND_PRINT("nak %u ", ack & SGQ_MASK); else ND_PRINT("ack %u ", ack & SGQ_MASK); - ND_TCHECK(amp->ak_acknum[1]); + ND_TCHECK_2(amp->ak_acknum[1]); ack = EXTRACT_LE_U_2(amp->ak_acknum[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) @@ -1246,10 +1239,11 @@ dnnum_string(netdissect_options *ndo, u_short dnaddr) u_int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT; u_int node = dnaddr & NODEMASK; + /* malloc() return used by the 'dnaddrtable' hash table: do not free() */ str = (char *)malloc(siz = sizeof("00.0000")); if (str == NULL) - (*ndo->ndo_error)(ndo, "dnnum_string: malloc"); - snprintf(str, siz, "%u.%u", area, node); + (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "dnnum_string: malloc"); + nd_snprintf(str, siz, "%u.%u", area, node); return(str); }