]>
The Tcpdump Group git mirrors - tcpdump/blob - print-lldp.c
2 * Copyright (c) 1998-2007 The TCPDUMP project
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.
15 * support for the IEEE Link Discovery Protocol as per 802.1ab
17 * Original code by Hannes Gredler (hannes@juniper.net)
21 static const char rcsid
[] _U_
=
22 "@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.1 2007-08-03 11:03:19 hannes Exp $";
29 #include <tcpdump-stdinc.h>
35 #include "interface.h"
37 #include "addrtoname.h"
39 #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
40 #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
42 #define LLDP_END_TLV 0
43 #define LLDP_CHASSIS_ID_TLV 1
44 #define LLDP_PORT_ID_TLV 2
45 #define LLDP_TTL_TLV 3
46 #define LLDP_PORT_DESCR_TLV 4
47 #define LLDP_SYSTEM_NAME_TLV 5
48 #define LLDP_SYSTEM_DESCR_TLV 6
49 #define LLDP_SYSTEM_CAP_TLV 7
50 #define LLDP_MGMT_ADDR_TLV 8
51 #define LLDP_PRIVATE_TLV 127
54 static const struct tok lldp_tlv_values
[] = {
55 { LLDP_END_TLV
, "End" },
56 { LLDP_CHASSIS_ID_TLV
, "Chassis ID" },
57 { LLDP_PORT_ID_TLV
, "Port ID" },
58 { LLDP_TTL_TLV
, "Time to Live" },
59 { LLDP_PORT_DESCR_TLV
, "Port Description" },
60 { LLDP_SYSTEM_NAME_TLV
, "System Name" },
61 { LLDP_SYSTEM_DESCR_TLV
, "System Description" },
62 { LLDP_SYSTEM_CAP_TLV
, "System Capabilities" },
63 { LLDP_MGMT_ADDR_TLV
, "Management Address" },
64 { LLDP_PRIVATE_TLV
, "Organization specific" },
68 void lldp_print(register const u_char
*pptr
, register u_int len
) {
71 u_int tlen
, hexdump
, tlv_type
, tlv_len
;
77 printf("LLDP, length %u", len
);
83 while (tlen
>= sizeof(tlv
)) {
85 TCHECK2(*tptr
, sizeof(tlv
));
87 tlv
= EXTRACT_16BITS(tptr
);
89 tlv_type
= LLDP_EXTRACT_TYPE(tlv
);
90 tlv_len
= LLDP_EXTRACT_LEN(tlv
);
96 printf("\n\t%s TLV (%u), length %u",
97 tok2str(lldp_tlv_values
, "Unknown", tlv_type
),
100 /* infinite loop check */
101 if (!tlv_type
|| !tlv_len
) {
105 TCHECK2(*tptr
, tlv_len
);
109 printf(", TTL %us", EXTRACT_16BITS(tptr
));
112 case LLDP_SYSTEM_NAME_TLV
:
113 case LLDP_PORT_DESCR_TLV
:
115 safeputs((const char *)tptr
, tlv_len
);
118 case LLDP_SYSTEM_DESCR_TLV
:
120 safeputs((const char *)tptr
, tlv_len
);
127 /* do we also want to see a hex dump ? */
128 if (vflag
> 1 || hexdump
) {
129 print_unknown_data(tptr
,"\n\t ", tlv_len
);
137 printf("\n\t[|LLDP]");