void ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint8_t version; ND_PRINT((ndo, "AHCP")); if (len < 2) goto invalid; /* Magic */ ND_TCHECK2(*cp, 1); if (*cp != AHCP_MAGIC_NUMBER) goto invalid; cp += 1; /* Version */ ND_TCHECK2(*cp, 1); version = *cp; cp += 1; switch (version) { case AHCP_VERSION_1: { ND_PRINT((ndo, " Version 1")); if (len < AHCP1_HEADER_FIX_LEN) goto invalid; if (!ndo->ndo_vflag) { ND_TCHECK2(*cp, AHCP1_HEADER_FIX_LEN - 2); cp += AHCP1_HEADER_FIX_LEN - 2; } else { /* Hopcount */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\tHopcount %u", *cp)); cp += 1; /* Original Hopcount */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Original Hopcount %u", *cp)); cp += 1; /* Nonce */ ND_TCHECK2(*cp, 4); ND_PRINT((ndo, ", Nonce 0x%08x", EXTRACT_32BITS(cp))); cp += 4; /* Source Id */ ND_TCHECK2(*cp, 8); ND_PRINT((ndo, ", Source Id %s", linkaddr_string(ndo, cp, 0, 8))); cp += 8; /* Destination Id */ ND_TCHECK2(*cp, 8); ND_PRINT((ndo, ", Destination Id %s", linkaddr_string(ndo, cp, 0, 8))); cp += 8; } /* Body */ ahcp1_body_print(ndo, cp, ep); break; } default: ND_PRINT((ndo, " Version %u (unknown)", version)); break; } return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); }
void ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = ndo->ndo_snapend; uint8_t version; ndo->ndo_protocol = "ahcp"; ND_PRINT("AHCP"); if (len < 2) goto invalid; /* Magic */ ND_TCHECK_1(cp); if (EXTRACT_U_1(cp) != AHCP_MAGIC_NUMBER) goto invalid; cp += 1; /* Version */ ND_TCHECK_1(cp); version = EXTRACT_U_1(cp); cp += 1; switch (version) { case AHCP_VERSION_1: { ND_PRINT(" Version 1"); if (len < AHCP1_HEADER_FIX_LEN) goto invalid; if (!ndo->ndo_vflag) { ND_TCHECK_LEN(cp, AHCP1_HEADER_FIX_LEN - 2); cp += AHCP1_HEADER_FIX_LEN - 2; } else { /* Hopcount */ ND_TCHECK_1(cp); ND_PRINT("\n\tHopcount %u", EXTRACT_U_1(cp)); cp += 1; /* Original Hopcount */ ND_TCHECK_1(cp); ND_PRINT(", Original Hopcount %u", EXTRACT_U_1(cp)); cp += 1; /* Nonce */ ND_TCHECK_4(cp); ND_PRINT(", Nonce 0x%08x", EXTRACT_BE_U_4(cp)); cp += 4; /* Source Id */ ND_TCHECK_8(cp); ND_PRINT(", Source Id %s", linkaddr_string(ndo, cp, 0, 8)); cp += 8; /* Destination Id */ ND_TCHECK_8(cp); ND_PRINT(", Destination Id %s", linkaddr_string(ndo, cp, 0, 8)); cp += 8; } /* Body */ ahcp1_body_print(ndo, cp, ep); break; } default: ND_PRINT(" Version %u (unknown)", version); break; } return; invalid: ND_PRINT("%s", istr); ND_TCHECK_LEN(cp, ep - cp); return; trunc: nd_print_trunc(ndo); }