xref: /dragonfly/contrib/tcpdump/print-mobile.c (revision ed775ee7)
141c99275SPeter Avalos /*	$NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */
241c99275SPeter Avalos 
341c99275SPeter Avalos /*
441c99275SPeter Avalos  * (c) 1998 The NetBSD Foundation, Inc.
541c99275SPeter Avalos  * All rights reserved.
641c99275SPeter Avalos  *
741c99275SPeter Avalos  * This code is derived from software contributed to The NetBSD Foundation
841c99275SPeter Avalos  * by Heiko W.Rupp <hwr@pilhuhn.de>
941c99275SPeter Avalos  *
1041c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
1141c99275SPeter Avalos  * modification, are permitted provided that the following conditions
1241c99275SPeter Avalos  * are met:
1341c99275SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
1441c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1541c99275SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1641c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1741c99275SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1841c99275SPeter Avalos  * 3. All advertising materials mentioning features or use of this software
1941c99275SPeter Avalos  *    must display the following acknowledgement:
2041c99275SPeter Avalos  *        This product includes software developed by the NetBSD
2141c99275SPeter Avalos  *        Foundation, Inc. and its contributors.
2241c99275SPeter Avalos  * 4. Neither the name of The NetBSD Foundation nor the names of its
2341c99275SPeter Avalos  *    contributors may be used to endorse or promote products derived
2441c99275SPeter Avalos  *    from this software without specific prior written permission.
2541c99275SPeter Avalos  *
2641c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2741c99275SPeter Avalos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2841c99275SPeter Avalos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2941c99275SPeter Avalos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3041c99275SPeter Avalos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3141c99275SPeter Avalos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3241c99275SPeter Avalos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3341c99275SPeter Avalos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3441c99275SPeter Avalos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3541c99275SPeter Avalos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3641c99275SPeter Avalos  * POSSIBILITY OF SUCH DAMAGE.
3741c99275SPeter Avalos  */
3841c99275SPeter Avalos 
39411677aeSAaron LI /* \summary: IPv4 mobility printer */
40411677aeSAaron LI 
4141c99275SPeter Avalos #ifdef HAVE_CONFIG_H
42*ed775ee7SAntonio Huete Jimenez #include <config.h>
4341c99275SPeter Avalos #endif
4441c99275SPeter Avalos 
45*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4641c99275SPeter Avalos 
47411677aeSAaron LI #include "netdissect.h"
4841c99275SPeter Avalos #include "addrtoname.h"
49411677aeSAaron LI #include "extract.h"
5041c99275SPeter Avalos 
5141c99275SPeter Avalos #define MOBILE_SIZE (8)
5241c99275SPeter Avalos 
5341c99275SPeter Avalos struct mobile_ip {
54*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t proto;
55*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t hcheck;
56*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t odst;
57*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t osrc;
5841c99275SPeter Avalos };
5941c99275SPeter Avalos 
6041c99275SPeter Avalos #define OSRC_PRES	0x0080	/* old source is present */
6141c99275SPeter Avalos 
6241c99275SPeter Avalos /*
6341c99275SPeter Avalos  * Deencapsulate and print a mobile-tunneled IP datagram
6441c99275SPeter Avalos  */
6541c99275SPeter Avalos void
mobile_print(netdissect_options * ndo,const u_char * bp,u_int length)66411677aeSAaron LI mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
6741c99275SPeter Avalos {
6841c99275SPeter Avalos 	const struct mobile_ip *mob;
6927bfbee1SPeter Avalos 	struct cksum_vec vec[1];
7041c99275SPeter Avalos 	u_short proto,crc;
7141c99275SPeter Avalos 	u_char osp =0;			/* old source address present */
7241c99275SPeter Avalos 
73*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "mobile";
7441c99275SPeter Avalos 	mob = (const struct mobile_ip *)bp;
7541c99275SPeter Avalos 
76*ed775ee7SAntonio Huete Jimenez 	if (length < MOBILE_SIZE || !ND_TTEST_SIZE(mob)) {
77*ed775ee7SAntonio Huete Jimenez 		nd_print_trunc(ndo);
7841c99275SPeter Avalos 		return;
7941c99275SPeter Avalos 	}
80*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("mobile: ");
8141c99275SPeter Avalos 
82*ed775ee7SAntonio Huete Jimenez 	proto = GET_BE_U_2(mob->proto);
83*ed775ee7SAntonio Huete Jimenez 	crc =  GET_BE_U_2(mob->hcheck);
8441c99275SPeter Avalos 	if (proto & OSRC_PRES) {
8541c99275SPeter Avalos 		osp=1;
8641c99275SPeter Avalos 	}
8741c99275SPeter Avalos 
8841c99275SPeter Avalos 	if (osp)  {
89*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[S] ");
90411677aeSAaron LI 		if (ndo->ndo_vflag)
91*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s ", GET_IPADDR_STRING(mob->osrc));
9241c99275SPeter Avalos 	} else {
93*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[] ");
9441c99275SPeter Avalos 	}
95411677aeSAaron LI 	if (ndo->ndo_vflag) {
96*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("> %s ", GET_IPADDR_STRING(mob->odst));
97*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(oproto=%u)", proto>>8);
9841c99275SPeter Avalos 	}
99411677aeSAaron LI 	vec[0].ptr = (const uint8_t *)(const void *)mob;
10027bfbee1SPeter Avalos 	vec[0].len = osp ? 12 : 8;
10127bfbee1SPeter Avalos 	if (in_cksum(vec, 1)!=0) {
102*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" (bad checksum %u)", crc);
10341c99275SPeter Avalos 	}
10441c99275SPeter Avalos }
105