2 * This module implements decoding of the Loopback Protocol, originally
3 * defined as the Configuration Testing Protocol. It is based on the following
5 * http://www.mit.edu/people/jhawk/ctp.pdf
7 * Copyright (c) 2014 The TCPDUMP project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: print-loopback.c,v 1.2 2014/11/20 03:05:03 christos Exp $");
38 #define NETDISSECT_REWORKED
43 #include <tcpdump-stdinc.h>
45 #include "interface.h"
48 #include "addrtoname.h"
50 static const char tstr
[] = " [|loopback]";
51 static const char cstr
[] = " (corrupt)";
53 #define LOOPBACK_REPLY 1
54 #define LOOPBACK_FWDDATA 2
56 static const struct tok fcode_str
[] = {
57 { LOOPBACK_REPLY
, "Reply" },
58 { LOOPBACK_FWDDATA
, "Forward Data" },
63 loopback_message_print(netdissect_options
*ndo
, const u_char
*cp
, const u_int len
)
65 const u_char
*ep
= cp
+ len
;
72 function
= EXTRACT_LE_16BITS(cp
);
74 ND_PRINT((ndo
, ", %s", tok2str(fcode_str
, " invalid (%u)", function
)));
82 ND_PRINT((ndo
, ", receipt number %u", EXTRACT_LE_16BITS(cp
)));
85 ND_PRINT((ndo
, ", data (%u octets)", len
- 4));
86 ND_TCHECK2(*cp
, len
- 4);
88 case LOOPBACK_FWDDATA
:
91 /* forwarding address */
92 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
93 ND_PRINT((ndo
, ", forwarding address %s", etheraddr_string(ndo
, cp
)));
96 ND_PRINT((ndo
, ", data (%u octets)", len
- 8));
97 ND_TCHECK2(*cp
, len
- 8);
100 ND_TCHECK2(*cp
, len
- 2);
106 ND_PRINT((ndo
, "%s", cstr
));
107 ND_TCHECK2(*cp
, ep
- cp
);
110 ND_PRINT((ndo
, "%s", tstr
));
114 loopback_print(netdissect_options
*ndo
, const u_char
*cp
, const u_int len
)
116 const u_char
*ep
= cp
+ len
;
119 ND_PRINT((ndo
, "Loopback"));
124 skipCount
= EXTRACT_LE_16BITS(cp
);
126 ND_PRINT((ndo
, ", skipCount %u", skipCount
));
128 ND_PRINT((ndo
, " (bogus)"));
129 if (skipCount
> len
- 2)
131 loopback_message_print(ndo
, cp
+ skipCount
, len
- 2 - skipCount
);
135 ND_PRINT((ndo
, "%s", cstr
));
136 ND_TCHECK2(*cp
, ep
- cp
);
139 ND_PRINT((ndo
, "%s", tstr
));