X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/70fbff8d347609250fae0846cff0f412bc9005bd..f243e70b91b9a25a4cda052f37f48fb5aa49bf39:/print-l2tp.c?ds=sidebyside diff --git a/print-l2tp.c b/print-l2tp.c index 3b47b1aa..29f1b30e 100644 --- a/print-l2tp.c +++ b/print-l2tp.c @@ -18,14 +18,19 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) + * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net) */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.2 1999-10-30 23:45:51 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.8 2000-08-18 07:44:46 itojun Exp $"; #endif +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include #include #include #include @@ -44,7 +49,7 @@ static char tstr[] = " [|l2tp]"; #define FALSE 0 #endif -static u_char *l2tp_message_type_string[] = { +static char *l2tp_message_type_string[] = { "RESERVED_0", /* 0 Reserved */ "SCCRQ", /* 1 Start-Control-Connection-Request */ "SCCRP", /* 2 Start-Control-Connection-Reply */ @@ -151,6 +156,7 @@ static struct l2tp_avp_vec l2tp_avp[] = { #define L2TP_MAX_AVP_INDEX 40 }; +#if 0 static char *l2tp_result_code_StopCCN[] = { "Reserved", "General request to clear control connection", @@ -162,7 +168,9 @@ static char *l2tp_result_code_StopCCN[] = { "Finite State Machine error" #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8 }; +#endif +#if 0 static char *l2tp_result_code_CDN[] = { "Reserved", "Call disconnected due to loss of carrier", @@ -180,7 +188,9 @@ static char *l2tp_result_code_CDN[] = { "Call was connected but no appropriate framing was detected" #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12 }; +#endif +#if 0 static char *l2tp_error_code_general[] = { "No general error", "No control connection exists yet for this LAC-LNS pair", @@ -193,6 +203,7 @@ static char *l2tp_error_code_general[] = { "Try another" #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8 }; +#endif /******************************/ /* generic print out routines */ @@ -218,13 +229,13 @@ print_octets(const u_char *dat, u_int length) static void print_short(const u_short *dat) { - printf("%d", ntohs(*dat)); + printf("%u", ntohs(*dat)); } static void print_int(const u_int *dat) { - printf("%d", ntohl(*dat)); + printf("%lu", (u_long)ntohl(*dat)); } /**********************************/ @@ -247,11 +258,11 @@ l2tp_result_code_print(const u_char *dat, u_int length) u_short *ptr = (u_short *)dat; if (length == 2) { /* result code */ - printf("%d", ntohs(*ptr)); + printf("%u", ntohs(*ptr)); } else if (length == 4) { /* result & error code */ - printf("%d/%d", ntohs(*ptr), ntohs(*(ptr+1))); + printf("%u/%u", ntohs(*ptr), ntohs(*(ptr+1))); } else if (length > 4) { /* result & error code & msg */ - printf("%d/%d %s", ntohs(*ptr), ntohs(*(ptr+1))); + printf("%u/%u ", ntohs(*ptr), ntohs(*(ptr+1))); print_string((u_char *)(ptr+2), length - 4); } } @@ -292,7 +303,7 @@ l2tp_bearer_cap_print(const u_char *dat, u_int length) static void l2tp_tie_breaker_print(const u_char *dat, u_int length) { - printf("%lx", *(u_long *)dat); /* XXX */ + print_octets(dat, 8); /* Tie Break Value is 64bits long */ } static void @@ -335,7 +346,7 @@ static void l2tp_q931_cc_print(const u_char *dat, u_int length) { print_short((u_short *)dat); - printf(",%02x", dat+2); + printf(", %02x", dat[2]); if (length > 3) { printf(" "); print_string(dat+3, length-3); @@ -498,7 +509,7 @@ l2tp_proxy_auth_id_print(const u_char *dat, u_int length) { u_short *ptr = (u_short *)dat; - printf("%d", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); + printf("%u", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); } static void @@ -581,23 +592,30 @@ l2tp_avp_print(const u_char *dat, u_int length) } ptr++; - if (ntohs(*ptr)) { /* IETF == 0 */ - printf("vendor=%04x", ntohs(*ptr)); - } - ptr++; - - if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) { - printf("%s", l2tp_avp[ntohs(*ptr)].name); + if (ntohs(*ptr)) { + /* Vendor Specific Attribute */ + printf("VENDOR%04x:", ntohs(*ptr)); + ptr++; + printf("ATTR%04x", ntohs(*ptr)); printf("("); - if (!hidden) { - (l2tp_avp[ntohs(*ptr)].print) - ((u_char *)ptr+2, len-6); - } else { - printf("???"); - } + print_octets((u_char *)ptr+2, len-6); printf(")"); } else { - printf(" invalid AVP %s", ntohs(*ptr)); + /* IETF-defined Attribute */ + ptr++; + if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) { + printf("%s", l2tp_avp[ntohs(*ptr)].name); + printf("("); + if (!hidden) { + (l2tp_avp[ntohs(*ptr)].print) + ((u_char *)ptr+2, len-6); + } else { + printf("???"); + } + printf(")"); + } else { + printf(" invalid AVP %u", ntohs(*ptr)); + } } l2tp_avp_print(dat + len, length - len); @@ -671,19 +689,19 @@ l2tp_print(const u_char *dat, u_int length) l2tp_len = 0; } - printf("(%d/", ntohs(*ptr++)); /* Tunnel ID */ - printf("%d)", ntohs(*ptr++)); /* Session ID */ + printf("(%u/", ntohs(*ptr++)); /* Tunnel ID */ + printf("%u)", ntohs(*ptr++)); /* Session ID */ cnt += 4; if (flag_s) { - printf("Ns=%d,", ntohs(*ptr++)); - printf("Nr=%d", ntohs(*ptr++)); + printf("Ns=%u,", ntohs(*ptr++)); + printf("Nr=%u", ntohs(*ptr++)); cnt += 4; } if (flag_o) { pad = ntohs(*ptr++); - (u_char *)ptr += pad; + ptr += pad / sizeof(*ptr); cnt += (2 + pad); } @@ -694,12 +712,8 @@ l2tp_print(const u_char *dat, u_int length) l2tp_avp_print((u_char *)ptr, length - cnt); } } else { -#if 0 printf(" {"); - ppp_hdlc_print((u_char *)ptr, length - cnt); + ppp_print((u_char *)ptr, length - cnt); printf("}"); -#else - printf("[hdlc|]"); -#endif } }