X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/d57e945e5eb1a24ed43670f9cca6d51cf6d6fd99..0845bc813c1cc48b18cdefff0b387c110647463c:/print-l2tp.c diff --git a/print-l2tp.c b/print-l2tp.c index 8dde75d1..0c7d5114 100644 --- a/print-l2tp.c +++ b/print-l2tp.c @@ -21,14 +21,13 @@ * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net) */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif #include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #define L2TP_FLAG_TYPE 0x8000 /* Type (0=Data, 1=Control) */ @@ -281,13 +280,13 @@ print_octets(netdissect_options *ndo, const u_char *dat, u_int length) } static void -print_16bits_val(netdissect_options *ndo, const u_int16_t *dat) +print_16bits_val(netdissect_options *ndo, const uint16_t *dat) { ND_PRINT((ndo, "%u", EXTRACT_16BITS(dat))); } static void -print_32bits_val(netdissect_options *ndo, const u_int32_t *dat) +print_32bits_val(netdissect_options *ndo, const uint32_t *dat) { ND_PRINT((ndo, "%lu", (u_long)EXTRACT_32BITS(dat))); } @@ -298,7 +297,7 @@ print_32bits_val(netdissect_options *ndo, const u_int32_t *dat) static void l2tp_msgtype_print(netdissect_options *ndo, const u_char *dat) { - u_int16_t *ptr = (u_int16_t*)dat; + const uint16_t *ptr = (const uint16_t *)dat; ND_PRINT((ndo, "%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u", EXTRACT_16BITS(ptr)))); @@ -307,7 +306,7 @@ l2tp_msgtype_print(netdissect_options *ndo, const u_char *dat) static void l2tp_result_code_print(netdissect_options *ndo, const u_char *dat, u_int length) { - u_int16_t *ptr = (u_int16_t *)dat; + const uint16_t *ptr = (const uint16_t *)dat; ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr))); ptr++; /* Result Code */ if (length > 2) { /* Error Code (opt) */ @@ -315,12 +314,12 @@ l2tp_result_code_print(netdissect_options *ndo, const u_char *dat, u_int length) } if (length > 4) { /* Error Message (opt) */ ND_PRINT((ndo, " ")); - print_string(ndo, (u_char *)ptr, length - 4); + print_string(ndo, (const u_char *)ptr, length - 4); } } static void -l2tp_proto_ver_print(netdissect_options *ndo, const u_int16_t *dat) +l2tp_proto_ver_print(netdissect_options *ndo, const uint16_t *dat) { ND_PRINT((ndo, "%u.%u", (EXTRACT_16BITS(dat) >> 8), (EXTRACT_16BITS(dat) & 0xff))); @@ -329,7 +328,7 @@ l2tp_proto_ver_print(netdissect_options *ndo, const u_int16_t *dat) static void l2tp_framing_cap_print(netdissect_options *ndo, const u_char *dat) { - u_int32_t *ptr = (u_int32_t *)dat; + const uint32_t *ptr = (const uint32_t *)dat; if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { ND_PRINT((ndo, "A")); @@ -342,7 +341,7 @@ l2tp_framing_cap_print(netdissect_options *ndo, const u_char *dat) static void l2tp_bearer_cap_print(netdissect_options *ndo, const u_char *dat) { - u_int32_t *ptr = (u_int32_t *)dat; + const uint32_t *ptr = (const uint32_t *)dat; if (EXTRACT_32BITS(ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { ND_PRINT((ndo, "A")); @@ -355,7 +354,7 @@ l2tp_bearer_cap_print(netdissect_options *ndo, const u_char *dat) static void l2tp_q931_cc_print(netdissect_options *ndo, const u_char *dat, u_int length) { - print_16bits_val(ndo, (u_int16_t *)dat); + print_16bits_val(ndo, (const uint16_t *)dat); ND_PRINT((ndo, ", %02x", dat[2])); if (length > 3) { ND_PRINT((ndo, " ")); @@ -366,7 +365,7 @@ l2tp_q931_cc_print(netdissect_options *ndo, const u_char *dat, u_int length) static void l2tp_bearer_type_print(netdissect_options *ndo, const u_char *dat) { - u_int32_t *ptr = (u_int32_t *)dat; + const uint32_t *ptr = (const uint32_t *)dat; if (EXTRACT_32BITS(ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { ND_PRINT((ndo, "A")); @@ -379,7 +378,7 @@ l2tp_bearer_type_print(netdissect_options *ndo, const u_char *dat) static void l2tp_framing_type_print(netdissect_options *ndo, const u_char *dat) { - u_int32_t *ptr = (u_int32_t *)dat; + const uint32_t *ptr = (const uint32_t *)dat; if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { ND_PRINT((ndo, "A")); @@ -398,7 +397,7 @@ l2tp_packet_proc_delay_print(netdissect_options *ndo) static void l2tp_proxy_auth_type_print(netdissect_options *ndo, const u_char *dat) { - u_int16_t *ptr = (u_int16_t *)dat; + const uint16_t *ptr = (const uint16_t *)dat; ND_PRINT((ndo, "%s", tok2str(l2tp_authentype2str, "AuthType-#%u", EXTRACT_16BITS(ptr)))); @@ -407,7 +406,7 @@ l2tp_proxy_auth_type_print(netdissect_options *ndo, const u_char *dat) static void l2tp_proxy_auth_id_print(netdissect_options *ndo, const u_char *dat) { - u_int16_t *ptr = (u_int16_t *)dat; + const uint16_t *ptr = (const uint16_t *)dat; ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr) & L2TP_PROXY_AUTH_ID_MASK)); } @@ -415,8 +414,8 @@ l2tp_proxy_auth_id_print(netdissect_options *ndo, const u_char *dat) static void l2tp_call_errors_print(netdissect_options *ndo, const u_char *dat) { - u_int16_t *ptr = (u_int16_t *)dat; - u_int16_t val_h, val_l; + const uint16_t *ptr = (const uint16_t *)dat; + uint16_t val_h, val_l; ptr++; /* skip "Reserved" */ @@ -448,8 +447,8 @@ l2tp_call_errors_print(netdissect_options *ndo, const u_char *dat) static void l2tp_accm_print(netdissect_options *ndo, const u_char *dat) { - u_int16_t *ptr = (u_int16_t *)dat; - u_int16_t val_h, val_l; + const uint16_t *ptr = (const uint16_t *)dat; + uint16_t val_h, val_l; ptr++; /* skip "Reserved" */ @@ -465,12 +464,12 @@ l2tp_accm_print(netdissect_options *ndo, const u_char *dat) static void l2tp_ppp_discon_cc_print(netdissect_options *ndo, const u_char *dat, u_int length) { - u_int16_t *ptr = (u_int16_t *)dat; + const uint16_t *ptr = (const uint16_t *)dat; ND_PRINT((ndo, "%04x, ", EXTRACT_16BITS(ptr))); ptr++; /* Disconnect Code */ ND_PRINT((ndo, "%04x ", EXTRACT_16BITS(ptr))); ptr++; /* Control Protocol Number */ ND_PRINT((ndo, "%s", tok2str(l2tp_cc_direction2str, - "Direction-#%u", *((u_char *)ptr++)))); + "Direction-#%u", *((const u_char *)ptr++)))); if (length > 5) { ND_PRINT((ndo, " ")); @@ -482,8 +481,8 @@ static void l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) { u_int len; - const u_int16_t *ptr = (u_int16_t *)dat; - u_int16_t attr_type; + const uint16_t *ptr = (const uint16_t *)dat; + uint16_t attr_type; int hidden = FALSE; if (length <= 0) { @@ -523,7 +522,7 @@ l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) ND_PRINT((ndo, "VENDOR%04x:", EXTRACT_16BITS(ptr))); ptr++; ND_PRINT((ndo, "ATTR%04x", EXTRACT_16BITS(ptr))); ptr++; ND_PRINT((ndo, "(")); - print_octets(ndo, (u_char *)ptr, len-6); + print_octets(ndo, (const u_char *)ptr, len-6); ND_PRINT((ndo, ")")); } else { /* IETF-defined Attributes */ @@ -536,22 +535,22 @@ l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) } else { switch (attr_type) { case L2TP_AVP_MSGTYPE: - l2tp_msgtype_print(ndo, (u_char *)ptr); + l2tp_msgtype_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_RESULT_CODE: - l2tp_result_code_print(ndo, (u_char *)ptr, len-6); + l2tp_result_code_print(ndo, (const u_char *)ptr, len-6); break; case L2TP_AVP_PROTO_VER: l2tp_proto_ver_print(ndo, ptr); break; case L2TP_AVP_FRAMING_CAP: - l2tp_framing_cap_print(ndo, (u_char *)ptr); + l2tp_framing_cap_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_BEARER_CAP: - l2tp_bearer_cap_print(ndo, (u_char *)ptr); + l2tp_bearer_cap_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_TIE_BREAKER: - print_octets(ndo, (u_char *)ptr, 8); + print_octets(ndo, (const u_char *)ptr, 8); break; case L2TP_AVP_FIRM_VER: case L2TP_AVP_ASSND_TUN_ID: @@ -566,7 +565,7 @@ l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) case L2TP_AVP_SUB_ADDRESS: case L2TP_AVP_PROXY_AUTH_NAME: case L2TP_AVP_PRIVATE_GRP_ID: - print_string(ndo, (u_char *)ptr, len-6); + print_string(ndo, (const u_char *)ptr, len-6); break; case L2TP_AVP_CHALLENGE: case L2TP_AVP_INI_RECV_LCP: @@ -575,13 +574,13 @@ l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) case L2TP_AVP_PROXY_AUTH_CHAL: case L2TP_AVP_PROXY_AUTH_RESP: case L2TP_AVP_RANDOM_VECTOR: - print_octets(ndo, (u_char *)ptr, len-6); + print_octets(ndo, (const u_char *)ptr, len-6); break; case L2TP_AVP_Q931_CC: - l2tp_q931_cc_print(ndo, (u_char *)ptr, len-6); + l2tp_q931_cc_print(ndo, (const u_char *)ptr, len-6); break; case L2TP_AVP_CHALLENGE_RESP: - print_octets(ndo, (u_char *)ptr, 16); + print_octets(ndo, (const u_char *)ptr, 16); break; case L2TP_AVP_CALL_SER_NUM: case L2TP_AVP_MINIMUM_BPS: @@ -589,33 +588,33 @@ l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) case L2TP_AVP_TX_CONN_SPEED: case L2TP_AVP_PHY_CHANNEL_ID: case L2TP_AVP_RX_CONN_SPEED: - print_32bits_val(ndo, (u_int32_t *)ptr); + print_32bits_val(ndo, (const uint32_t *)ptr); break; case L2TP_AVP_BEARER_TYPE: - l2tp_bearer_type_print(ndo, (u_char *)ptr); + l2tp_bearer_type_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_FRAMING_TYPE: - l2tp_framing_type_print(ndo, (u_char *)ptr); + l2tp_framing_type_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_PACKET_PROC_DELAY: l2tp_packet_proc_delay_print(ndo); break; case L2TP_AVP_PROXY_AUTH_TYPE: - l2tp_proxy_auth_type_print(ndo, (u_char *)ptr); + l2tp_proxy_auth_type_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_PROXY_AUTH_ID: - l2tp_proxy_auth_id_print(ndo, (u_char *)ptr); + l2tp_proxy_auth_id_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_CALL_ERRORS: - l2tp_call_errors_print(ndo, (u_char *)ptr); + l2tp_call_errors_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_ACCM: - l2tp_accm_print(ndo, (u_char *)ptr); + l2tp_accm_print(ndo, (const u_char *)ptr); break; case L2TP_AVP_SEQ_REQUIRED: break; /* No Attribute Value */ case L2TP_AVP_PPP_DISCON_CC: - l2tp_ppp_discon_cc_print(ndo, (u_char *)ptr, len-6); + l2tp_ppp_discon_cc_print(ndo, (const u_char *)ptr, len-6); break; default: break; @@ -637,9 +636,9 @@ l2tp_print(netdissect_options *ndo, const u_char *dat, u_int length) { const u_char *ptr = dat; u_int cnt = 0; /* total octets consumed */ - u_int16_t pad; + uint16_t pad; int flag_t, flag_l, flag_s, flag_o; - u_int16_t l2tp_len; + uint16_t l2tp_len; flag_t = flag_l = flag_s = flag_o = FALSE; @@ -737,7 +736,7 @@ l2tp_print(netdissect_options *ndo, const u_char *dat, u_int length) } } else { ND_PRINT((ndo, " {")); - ppp_print(ptr, length - cnt); + ppp_print(ndo, ptr, length - cnt); ND_PRINT((ndo, "}")); }