Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/tcpdump/print-ahcp.c
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | static const struct tok ahcp1_opt_str[] = { | ||||
{ AHCP1_OPT_IPV6_PREFIX_DELEGATION, "IPv6 Prefix Delegation" }, | { AHCP1_OPT_IPV6_PREFIX_DELEGATION, "IPv6 Prefix Delegation" }, | ||||
{ AHCP1_OPT_IPV4_PREFIX_DELEGATION, "IPv4 Prefix Delegation" }, | { AHCP1_OPT_IPV4_PREFIX_DELEGATION, "IPv4 Prefix Delegation" }, | ||||
{ AHCP1_OPT_NAME_SERVER, "Name Server" }, | { AHCP1_OPT_NAME_SERVER, "Name Server" }, | ||||
{ AHCP1_OPT_NTP_SERVER, "NTP Server" }, | { AHCP1_OPT_NTP_SERVER, "NTP Server" }, | ||||
{ 0, NULL } | { 0, NULL } | ||||
}; | }; | ||||
static int | static int | ||||
ahcp_time_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_time_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
time_t t; | time_t t; | ||||
struct tm *tm; | struct tm *tm; | ||||
char buf[BUFSIZE]; | char buf[BUFSIZE]; | ||||
if (cp + 4 != ep) | if (cp + 4 != ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 4); | ND_TCHECK2(*cp, 4); | ||||
t = EXTRACT_32BITS(cp); | t = EXTRACT_32BITS(cp); | ||||
Show All 10 Lines | corrupt: | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return 0; | return 0; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return -1; | return -1; | ||||
} | } | ||||
static int | static int | ||||
ahcp_seconds_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_seconds_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
if (cp + 4 != ep) | if (cp + 4 != ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 4); | ND_TCHECK2(*cp, 4); | ||||
ND_PRINT((ndo, ": %us", EXTRACT_32BITS(cp))); | ND_PRINT((ndo, ": %us", EXTRACT_32BITS(cp))); | ||||
return 0; | return 0; | ||||
corrupt: | corrupt: | ||||
ND_PRINT((ndo, ": %s", cstr)); | ND_PRINT((ndo, ": %s", cstr)); | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return 0; | return 0; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return -1; | return -1; | ||||
} | } | ||||
static int | static int | ||||
ahcp_ipv6_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_ipv6_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
const char *sep = ": "; | const char *sep = ": "; | ||||
while (cp < ep) { | while (cp < ep) { | ||||
if (cp + 16 > ep) | if (cp + 16 > ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 16); | ND_TCHECK2(*cp, 16); | ||||
#ifdef INET6 | #ifdef INET6 | ||||
ND_PRINT((ndo, "%s%s", sep, ip6addr_string(ndo, cp))); | ND_PRINT((ndo, "%s%s", sep, ip6addr_string(ndo, cp))); | ||||
Show All 10 Lines | corrupt: | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return 0; | return 0; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return -1; | return -1; | ||||
} | } | ||||
static int | static int | ||||
ahcp_ipv4_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_ipv4_addresses_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
const char *sep = ": "; | const char *sep = ": "; | ||||
while (cp < ep) { | while (cp < ep) { | ||||
if (cp + 4 > ep) | if (cp + 4 > ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 4); | ND_TCHECK2(*cp, 4); | ||||
ND_PRINT((ndo, "%s%s", sep, ipaddr_string(ndo, cp))); | ND_PRINT((ndo, "%s%s", sep, ipaddr_string(ndo, cp))); | ||||
cp += 4; | cp += 4; | ||||
sep = ", "; | sep = ", "; | ||||
} | } | ||||
return 0; | return 0; | ||||
corrupt: | corrupt: | ||||
ND_PRINT((ndo, ": %s", cstr)); | ND_PRINT((ndo, ": %s", cstr)); | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return 0; | return 0; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return -1; | return -1; | ||||
} | } | ||||
static int | static int | ||||
ahcp_ipv6_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_ipv6_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
const char *sep = ": "; | const char *sep = ": "; | ||||
while (cp < ep) { | while (cp < ep) { | ||||
if (cp + 17 > ep) | if (cp + 17 > ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 17); | ND_TCHECK2(*cp, 17); | ||||
#ifdef INET6 | #ifdef INET6 | ||||
ND_PRINT((ndo, "%s%s/%u", sep, ip6addr_string(ndo, cp), *(cp + 16))); | ND_PRINT((ndo, "%s%s/%u", sep, ip6addr_string(ndo, cp), *(cp + 16))); | ||||
Show All 10 Lines | corrupt: | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return 0; | return 0; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return -1; | return -1; | ||||
} | } | ||||
static int | static int | ||||
ahcp_ipv4_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp_ipv4_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
const char *sep = ": "; | const char *sep = ": "; | ||||
while (cp < ep) { | while (cp < ep) { | ||||
if (cp + 5 > ep) | if (cp + 5 > ep) | ||||
goto corrupt; | goto corrupt; | ||||
ND_TCHECK2(*cp, 5); | ND_TCHECK2(*cp, 5); | ||||
ND_PRINT((ndo, "%s%s/%u", sep, ipaddr_string(ndo, cp), *(cp + 4))); | ND_PRINT((ndo, "%s%s/%u", sep, ipaddr_string(ndo, cp), *(cp + 4))); | ||||
cp += 5; | cp += 5; | ||||
Show All 25 Lines | (* const data_decoders[AHCP1_OPT_MAX + 1])(netdissect_options *, const u_char *, const u_char *) = { | ||||
/* [AHCP1_OPT_IPV4_ADDRESS] = */ ahcp_ipv4_addresses_print, | /* [AHCP1_OPT_IPV4_ADDRESS] = */ ahcp_ipv4_addresses_print, | ||||
/* [AHCP1_OPT_IPV6_PREFIX_DELEGATION] = */ ahcp_ipv6_prefixes_print, | /* [AHCP1_OPT_IPV6_PREFIX_DELEGATION] = */ ahcp_ipv6_prefixes_print, | ||||
/* [AHCP1_OPT_IPV4_PREFIX_DELEGATION] = */ ahcp_ipv4_prefixes_print, | /* [AHCP1_OPT_IPV4_PREFIX_DELEGATION] = */ ahcp_ipv4_prefixes_print, | ||||
/* [AHCP1_OPT_NAME_SERVER] = */ ahcp_ipv6_addresses_print, | /* [AHCP1_OPT_NAME_SERVER] = */ ahcp_ipv6_addresses_print, | ||||
/* [AHCP1_OPT_NTP_SERVER] = */ ahcp_ipv6_addresses_print, | /* [AHCP1_OPT_NTP_SERVER] = */ ahcp_ipv6_addresses_print, | ||||
}; | }; | ||||
static void | static void | ||||
ahcp1_options_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp1_options_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
uint8_t option_no, option_len; | uint8_t option_no, option_len; | ||||
while (cp < ep) { | while (cp < ep) { | ||||
/* Option no */ | /* Option no */ | ||||
ND_TCHECK2(*cp, 1); | ND_TCHECK2(*cp, 1); | ||||
option_no = *cp; | option_no = *cp; | ||||
cp += 1; | cp += 1; | ||||
ND_PRINT((ndo, "\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no))); | ND_PRINT((ndo, "\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no))); | ||||
Show All 23 Lines | corrupt: | ||||
ND_PRINT((ndo, " %s", cstr)); | ND_PRINT((ndo, " %s", cstr)); | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return; | return; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
} | } | ||||
static void | static void | ||||
ahcp1_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { | ahcp1_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) | ||||
{ | |||||
uint8_t type, mbz; | uint8_t type, mbz; | ||||
uint16_t body_len; | uint16_t body_len; | ||||
if (cp + AHCP1_BODY_MIN_LEN > ep) | if (cp + AHCP1_BODY_MIN_LEN > ep) | ||||
goto corrupt; | goto corrupt; | ||||
/* Type */ | /* Type */ | ||||
ND_TCHECK2(*cp, 1); | ND_TCHECK2(*cp, 1); | ||||
type = *cp; | type = *cp; | ||||
Show All 27 Lines | corrupt: | ||||
ND_PRINT((ndo, " %s", cstr)); | ND_PRINT((ndo, " %s", cstr)); | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return; | return; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
} | } | ||||
void | void | ||||
ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len) { | ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len) | ||||
{ | |||||
const u_char *ep = cp + len; | const u_char *ep = cp + len; | ||||
uint8_t version; | uint8_t version; | ||||
ND_PRINT((ndo, "AHCP")); | ND_PRINT((ndo, "AHCP")); | ||||
if (len < 2) | if (len < 2) | ||||
goto corrupt; | goto corrupt; | ||||
/* Magic */ | /* Magic */ | ||||
ND_TCHECK2(*cp, 1); | ND_TCHECK2(*cp, 1); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
corrupt: | corrupt: | ||||
ND_PRINT((ndo, " %s", cstr)); | ND_PRINT((ndo, " %s", cstr)); | ||||
ND_TCHECK2(*cp, ep - cp); | ND_TCHECK2(*cp, ep - cp); | ||||
return; | return; | ||||
trunc: | trunc: | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
} | } | ||||