void decnet_print(register const u_char *ap, register u_int length, register u_int caplen) { register const union routehdr *rhp; register int mflags; int dst, src, hops; u_int nsplen, pktlen; const u_char *nspp; if (length < sizeof(struct shorthdr)) { (void)printf("[|decnet]"); return; } TCHECK2(*ap, sizeof(short)); pktlen = EXTRACT_LE_16BITS(ap); if (pktlen < sizeof(struct shorthdr)) { (void)printf("[|decnet]"); return; } if (pktlen > length) { (void)printf("[|decnet]"); return; } length = pktlen; rhp = (const union routehdr *)&(ap[sizeof(short)]); TCHECK(rhp->rh_short.sh_flags); mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); if (mflags & RMF_PAD) { /* pad bytes of some sort in front of message */ u_int padlen = mflags & RMF_PADMASK; if (vflag) (void) printf("[pad:%d] ", padlen); if (length < padlen + 2) { (void)printf("[|decnet]"); return; } TCHECK2(ap[sizeof(short)], padlen); ap += padlen; length -= padlen; caplen -= padlen; rhp = (const union routehdr *)&(ap[sizeof(short)]); mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); } if (mflags & RMF_FVER) { (void) printf("future-version-decnet"); default_print(ap, min(length, caplen)); return; } /* is it a control message? */ if (mflags & RMF_CTLMSG) { if (!print_decnet_ctlmsg(rhp, length, caplen)) goto trunc; return; } switch (mflags & RMF_MASK) { case RMF_LONG: if (length < sizeof(struct longhdr)) { (void)printf("[|decnet]"); return; } TCHECK(rhp->rh_long); dst = EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr); src = EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr); hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits); nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]); nsplen = length - sizeof(struct longhdr); break; case RMF_SHORT: TCHECK(rhp->rh_short); dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst); src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src); hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1; nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]); nsplen = length - sizeof(struct shorthdr); break; default: (void) printf("unknown message flags under mask"); default_print((u_char *)ap, min(length, caplen)); return; } (void)printf("%s > %s %d ", dnaddr_string(src), dnaddr_string(dst), pktlen); if (vflag) { if (mflags & RMF_RQR) (void)printf("RQR "); if (mflags & RMF_RTS) (void)printf("RTS "); if (mflags & RMF_IE) (void)printf("IE "); (void)printf("%d hops ", hops); } if (!print_nsp(nspp, nsplen)) goto trunc; return; trunc: (void)printf("[|decnet]"); return; }
u_int ieee802_15_4_if_print(struct netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; int hdrlen; u_int16_t fc; u_int8_t seq; if (caplen < 3) { ND_PRINT((ndo, "[|802.15.4] %x", caplen)); return caplen; } fc = EXTRACT_LE_16BITS(p); hdrlen = extract_header_length(fc); seq = EXTRACT_LE_8BITS(p + 2); p += 3; caplen -= 3; ND_PRINT((ndo,"IEEE 802.15.4 %s packet ", ftypes[fc & 0x7])); if (vflag) ND_PRINT((ndo,"seq %02x ", seq)); if (hdrlen == -1) { ND_PRINT((ndo,"malformed! ")); return caplen; } if (!vflag) { p+= hdrlen; caplen -= hdrlen; } else { u_int16_t panid = 0; switch ((fc >> 10) & 0x3) { case 0x00: ND_PRINT((ndo,"none ")); break; case 0x01: ND_PRINT((ndo,"reserved destination addressing mode")); return 0; case 0x02: panid = EXTRACT_LE_16BITS(p); p += 2; ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p))); p += 2; break; case 0x03: panid = EXTRACT_LE_16BITS(p); p += 2; ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p))); p += 8; break; } ND_PRINT((ndo,"< "); switch ((fc >> 14) & 0x3) { case 0x00: ND_PRINT((ndo,"none ")); break; case 0x01: ND_PRINT((ndo,"reserved source addressing mode")); return 0; case 0x02: if (!(fc & (1 << 6))) { panid = EXTRACT_LE_16BITS(p); p += 2; } ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p))); p += 2; break; case 0x03: if (!(fc & (1 << 6))) { panid = EXTRACT_LE_16BITS(p); p += 2; } ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p)))); p += 8; break; } caplen -= hdrlen; } if (!suppress_default_print) (ndo->ndo_default_print)(ndo, p, caplen); return 0; }
static int print_decnet_ctlmsg(register const union routehdr *rhp, u_int length, u_int caplen) { int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); register union controlmsg *cmp = (union controlmsg *)rhp; int src, dst, info, blksize, eco, ueco, hello, other, vers; etheraddr srcea, rtea; int priority; char *rhpx = (char *)rhp; int ret; switch (mflags & RMF_CTLMASK) { case RMF_INIT: (void)printf("init "); if (length < sizeof(struct initmsg)) goto trunc; TCHECK(cmp->cm_init); src = EXTRACT_LE_16BITS(cmp->cm_init.in_src); info = EXTRACT_LE_8BITS(cmp->cm_init.in_info); blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize); vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers); eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco); ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco); hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello); print_t_info(info); (void)printf( "src %sblksize %d vers %d eco %d ueco %d hello %d", dnaddr_string(src), blksize, vers, eco, ueco, hello); ret = 1; break; case RMF_VER: (void)printf("verification "); if (length < sizeof(struct verifmsg)) goto trunc; TCHECK(cmp->cm_ver); src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src); other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval); (void)printf("src %s fcnval %o", dnaddr_string(src), other); ret = 1; break; case RMF_TEST: (void)printf("test "); if (length < sizeof(struct testmsg)) goto trunc; TCHECK(cmp->cm_test); src = EXTRACT_LE_16BITS(cmp->cm_test.te_src); other = EXTRACT_LE_8BITS(cmp->cm_test.te_data); (void)printf("src %s data %o", dnaddr_string(src), other); ret = 1; break; case RMF_L1ROUT: (void)printf("lev-1-routing "); if (length < sizeof(struct l1rout)) goto trunc; TCHECK(cmp->cm_l1rou); src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src); (void)printf("src %s ", dnaddr_string(src)); ret = print_l1_routes(&(rhpx[sizeof(struct l1rout)]), length - sizeof(struct l1rout)); break; case RMF_L2ROUT: (void)printf("lev-2-routing "); if (length < sizeof(struct l2rout)) goto trunc; TCHECK(cmp->cm_l2rout); src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src); (void)printf("src %s ", dnaddr_string(src)); ret = print_l2_routes(&(rhpx[sizeof(struct l2rout)]), length - sizeof(struct l2rout)); break; case RMF_RHELLO: (void)printf("router-hello "); if (length < sizeof(struct rhellomsg)) goto trunc; TCHECK(cmp->cm_rhello); vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers); eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco); ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco); memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src), sizeof(srcea)); src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info); blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize); priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority); hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello); print_i_info(info); (void)printf( "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d", vers, eco, ueco, dnaddr_string(src), blksize, priority, hello); ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]), length - sizeof(struct rhellomsg)); break; case RMF_EHELLO: (void)printf("endnode-hello "); if (length < sizeof(struct ehellomsg)) goto trunc; TCHECK(cmp->cm_ehello); vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers); eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco); ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco); memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src), sizeof(srcea)); src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info); blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize); /*seed*/ memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router), sizeof(rtea)); dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr); hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello); other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data); print_i_info(info); (void)printf( "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o", vers, eco, ueco, dnaddr_string(src), blksize, dnaddr_string(dst), hello, other); ret = 1; break; default: (void)printf("unknown control message"); default_print((u_char *)rhp, min(length, caplen)); ret = 1; break; } return (ret); trunc: return (0); }
static void print_nsp(const u_char *nspp, u_int nsplen) { const struct nsphdr *nsphp = (struct nsphdr *)nspp; int dst, src, flags; flags = EXTRACT_LE_8BITS(nsphp->nh_flags); dst = EXTRACT_LE_16BITS(nsphp->nh_dst); src = EXTRACT_LE_16BITS(nsphp->nh_src); switch (flags & NSP_TYPEMASK) { case MFT_DATA: switch (flags & NSP_SUBMASK) { case MFS_BOM: case MFS_MOM: case MFS_EOM: case MFS_BOM+MFS_EOM: printf("data %d>%d ", src, dst); { struct seghdr *shp = (struct seghdr *)nspp; int ack; #ifdef PRINT_NSPDATA u_char *dp; #endif u_int data_off = sizeof(struct minseghdr); ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); data_off += sizeof(short); if (ack & SGQ_OACK) { /* ackoth field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("onak %d ", ack & SGQ_MASK); else (void)printf("oack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); data_off += sizeof(short); } } (void)printf("seg %d ", ack & SGQ_MASK); #ifdef PRINT_NSPDATA dp = &(nspp[data_off]); pdata(dp, 10); #endif } break; case MFS_ILS+MFS_INT: printf("intr "); { struct seghdr *shp = (struct seghdr *)nspp; int ack; #ifdef PRINT_NSPDATA u_char *dp; #endif u_int data_off = sizeof(struct minseghdr); ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); data_off += sizeof(short); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); data_off += sizeof(short); } } (void)printf("seg %d ", ack & SGQ_MASK); #ifdef PRINT_NSPDATA dp = &(nspp[data_off]); pdata(dp, 10); #endif } break; case MFS_ILS: (void)printf("link-service %d>%d ", src, dst); { struct seghdr *shp = (struct seghdr *)nspp; struct lsmsg *lsmp = (struct lsmsg *)&(nspp[sizeof(struct seghdr)]); int ack; int lsflags, fcval; ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); } } (void)printf("seg %d ", ack & SGQ_MASK); lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags); fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval); switch (lsflags & LSI_MASK) { case LSI_DATA: (void)printf("dat seg count %d ", fcval); switch (lsflags & LSM_MASK) { case LSM_NOCHANGE: break; case LSM_DONOTSEND: (void)printf("donotsend-data "); break; case LSM_SEND: (void)printf("send-data "); break; default: (void)printf("reserved-fcmod? %x", lsflags); break; } break; case LSI_INTR: (void)printf("intr req count %d ", fcval); break; default: (void)printf("reserved-fcval-int? %x", lsflags); break; } } break; default: (void)printf("reserved-subtype? %x %d > %d", flags, src, dst); break; } break; case MFT_ACK: switch (flags & NSP_SUBMASK) { case MFS_DACK: (void)printf("data-ack %d>%d ", src, dst); { struct ackmsg *amp = (struct ackmsg *)nspp; int ack; ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); if (ack & SGQ_OACK) { /* ackoth field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("onak %d ", ack & SGQ_MASK); else (void)printf("oack %d ", ack & SGQ_MASK); } } } break; case MFS_IACK: (void)printf("ils-ack %d>%d ", src, dst); { struct ackmsg *amp = (struct ackmsg *)nspp; int ack; ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); } } } break; case MFS_CACK: (void)printf("conn-ack %d", dst); break; default: (void)printf("reserved-acktype? %x %d > %d", flags, src, dst); break; } break; case MFT_CTL: switch (flags & NSP_SUBMASK) { case MFS_CI: case MFS_RCI: if ((flags & NSP_SUBMASK) == MFS_CI) (void)printf("conn-initiate "); else (void)printf("retrans-conn-initiate "); (void)printf("%d>%d ", src, dst); { struct cimsg *cimp = (struct cimsg *)nspp; int services, info, segsize; #ifdef PRINT_NSPDATA u_char *dp; #endif services = EXTRACT_LE_8BITS(cimp->ci_services); info = EXTRACT_LE_8BITS(cimp->ci_info); segsize = EXTRACT_LE_16BITS(cimp->ci_segsize); switch (services & COS_MASK) { case COS_NONE: break; case COS_SEGMENT: (void)printf("seg "); break; case COS_MESSAGE: (void)printf("msg "); break; case COS_CRYPTSER: (void)printf("crypt "); break; } switch (info & COI_MASK) { case COI_32: (void)printf("ver 3.2 "); break; case COI_31: (void)printf("ver 3.1 "); break; case COI_40: (void)printf("ver 4.0 "); break; case COI_41: (void)printf("ver 4.1 "); break; } (void)printf("segsize %d ", segsize); #ifdef PRINT_NSPDATA dp = &(nspp[sizeof(struct cimsg)]); pdata(dp, nsplen - sizeof(struct cimsg)); #endif } break; case MFS_CC: (void)printf("conn-confirm %d>%d ", src, dst); { struct ccmsg *ccmp = (struct ccmsg *)nspp; int services, info; u_int segsize, optlen; #ifdef PRINT_NSPDATA u_char *dp; #endif services = EXTRACT_LE_8BITS(ccmp->cc_services); info = EXTRACT_LE_8BITS(ccmp->cc_info); segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize); optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen); switch (services & COS_MASK) { case COS_NONE: break; case COS_SEGMENT: (void)printf("seg "); break; case COS_MESSAGE: (void)printf("msg "); break; case COS_CRYPTSER: (void)printf("crypt "); break; } switch (info & COI_MASK) { case COI_32: (void)printf("ver 3.2 "); break; case COI_31: (void)printf("ver 3.1 "); break; case COI_40: (void)printf("ver 4.0 "); break; case COI_41: (void)printf("ver 4.1 "); break; } (void)printf("segsize %d ", segsize); if (optlen) { (void)printf("optlen %d ", optlen); #ifdef PRINT_NSPDATA optlen = min(optlen, nsplen - sizeof(struct ccmsg)); dp = &(nspp[sizeof(struct ccmsg)]); pdata(dp, optlen); #endif } } break; case MFS_DI: (void)printf("disconn-initiate %d>%d ", src, dst); { struct dimsg *dimp = (struct dimsg *)nspp; int reason; u_int optlen; #ifdef PRINT_NSPDATA u_char *dp; #endif reason = EXTRACT_LE_16BITS(dimp->di_reason); optlen = EXTRACT_LE_8BITS(dimp->di_optlen); print_reason(reason); if (optlen) { (void)printf("optlen %d ", optlen); #ifdef PRINT_NSPDATA optlen = min(optlen, nsplen - sizeof(struct dimsg)); dp = &(nspp[sizeof(struct dimsg)]); pdata(dp, optlen); #endif } } break; case MFS_DC: (void)printf("disconn-confirm %d>%d ", src, dst); { struct dcmsg *dcmp = (struct dcmsg *)nspp; int reason; reason = EXTRACT_LE_16BITS(dcmp->dc_reason); print_reason(reason); } break; default: (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst); break; } break; default: (void)printf("reserved-type? %x %d > %d", flags, src, dst); break; } }