1 /* 2 * Copyright (c) 1998-2007 The TCPDUMP project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that: (1) source code 6 * distributions retain the above copyright notice and this paragraph 7 * in its entirety, and (2) distributions including binary code include 8 * the above copyright notice and this paragraph in its entirety in 9 * the documentation or other materials provided with the distribution. 10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 * FOR A PARTICULAR PURPOSE. 14 * 15 * Dynamic Trunk Protocol (DTP) 16 * 17 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com> 18 */ 19 20 #ifdef HAVE_CONFIG_H 21 #include "config.h" 22 #endif 23 24 #include <tcpdump-stdinc.h> 25 26 #include <stdio.h> 27 #include <string.h> 28 29 #include "interface.h" 30 #include "addrtoname.h" 31 #include "extract.h" 32 #include "nlpid.h" 33 34 #define DTP_HEADER_LEN 1 35 #define DTP_DOMAIN_TLV 0x0001 36 #define DTP_STATUS_TLV 0x0002 37 #define DTP_DTP_TYPE_TLV 0x0003 38 #define DTP_NEIGHBOR_TLV 0x0004 39 40 static struct tok dtp_tlv_values[] = { 41 { DTP_DOMAIN_TLV, "Domain TLV"}, 42 { DTP_STATUS_TLV, "Status TLV"}, 43 { DTP_DTP_TYPE_TLV, "DTP type TLV"}, 44 { DTP_NEIGHBOR_TLV, "Neighbor TLV"}, 45 { 0, NULL} 46 }; 47 48 void 49 dtp_print (const u_char *pptr, u_int length) 50 { 51 int type, len; 52 const u_char *tptr; 53 54 if (length < DTP_HEADER_LEN) 55 goto trunc; 56 57 tptr = pptr; 58 59 if (!TTEST2(*tptr, DTP_HEADER_LEN)) 60 goto trunc; 61 62 printf("DTPv%u, length %u", 63 (*tptr), 64 length); 65 66 /* 67 * In non-verbose mode, just print version. 68 */ 69 if (vflag < 1) { 70 return; 71 } 72 73 tptr += DTP_HEADER_LEN; 74 75 while (tptr < (pptr+length)) { 76 77 if (!TTEST2(*tptr, 4)) 78 goto trunc; 79 80 type = EXTRACT_16BITS(tptr); 81 len = EXTRACT_16BITS(tptr+2); 82 83 /* infinite loop check */ 84 if (type == 0 || len == 0) { 85 return; 86 } 87 88 printf("\n\t%s (0x%04x) TLV, length %u", 89 tok2str(dtp_tlv_values, "Unknown", type), 90 type, len); 91 92 switch (type) { 93 case DTP_DOMAIN_TLV: 94 printf(", %s", tptr+4); 95 break; 96 97 case DTP_STATUS_TLV: 98 case DTP_DTP_TYPE_TLV: 99 printf(", 0x%x", *(tptr+4)); 100 break; 101 102 case DTP_NEIGHBOR_TLV: 103 printf(", %s", etheraddr_string(tptr+4)); 104 break; 105 106 default: 107 break; 108 } 109 tptr += len; 110 } 111 112 return; 113 114 trunc: 115 printf("[|dtp]"); 116 } 117 118 /* 119 * Local Variables: 120 * c-style: whitesmith 121 * c-basic-offset: 4 122 * End: 123 */ 124