]>
The Tcpdump Group git mirrors - tcpdump/blob - print-loopback.c
2 * Copyright (c) 2014 The TCPDUMP project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 /* \summary: Loopback Protocol printer */
31 * originally defined as the Ethernet Configuration Testing Protocol.
32 * specification: http://www.mit.edu/people/jhawk/ctp.pdf
39 #include <netdissect-stdinc.h>
41 #include "netdissect.h"
44 #include "addrtoname.h"
46 static const char tstr
[] = " [|loopback]";
48 #define LOOPBACK_REPLY 1
49 #define LOOPBACK_FWDDATA 2
51 static const struct tok fcode_str
[] = {
52 { LOOPBACK_REPLY
, "Reply" },
53 { LOOPBACK_FWDDATA
, "Forward Data" },
58 loopback_message_print(netdissect_options
*ndo
, const u_char
*cp
, const u_int len
)
60 const u_char
*ep
= cp
+ len
;
67 function
= EXTRACT_LE_U_2(cp
);
69 ND_PRINT((ndo
, ", %s", tok2str(fcode_str
, " invalid (%u)", function
)));
77 ND_PRINT((ndo
, ", receipt number %u", EXTRACT_LE_U_2(cp
)));
80 ND_PRINT((ndo
, ", data (%u octets)", len
- 4));
81 ND_TCHECK2(*cp
, len
- 4);
83 case LOOPBACK_FWDDATA
:
86 /* forwarding address */
87 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
88 ND_PRINT((ndo
, ", forwarding address %s", etheraddr_string(ndo
, cp
)));
91 ND_PRINT((ndo
, ", data (%u octets)", len
- 8));
92 ND_TCHECK2(*cp
, len
- 8);
95 ND_TCHECK2(*cp
, len
- 2);
101 ND_PRINT((ndo
, "%s", istr
));
102 ND_TCHECK2(*cp
, ep
- cp
);
105 ND_PRINT((ndo
, "%s", tstr
));
109 loopback_print(netdissect_options
*ndo
, const u_char
*cp
, const u_int len
)
111 const u_char
*ep
= cp
+ len
;
114 ND_PRINT((ndo
, "Loopback"));
119 skipCount
= EXTRACT_LE_U_2(cp
);
121 ND_PRINT((ndo
, ", skipCount %u", skipCount
));
123 ND_PRINT((ndo
, " (bogus)"));
124 if (skipCount
> len
- 2)
126 loopback_message_print(ndo
, cp
+ skipCount
, len
- 2 - skipCount
);
130 ND_PRINT((ndo
, "%s", istr
));
131 ND_TCHECK2(*cp
, ep
- cp
);
134 ND_PRINT((ndo
, "%s", tstr
));