156893Sfenner/* $NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */ 256893Sfenner 356893Sfenner/* 456893Sfenner * (c) 1998 The NetBSD Foundation, Inc. 556893Sfenner * All rights reserved. 656893Sfenner * 756893Sfenner * This code is derived from software contributed to The NetBSD Foundation 856893Sfenner * by Heiko W.Rupp <hwr@pilhuhn.de> 956893Sfenner * 1056893Sfenner * Redistribution and use in source and binary forms, with or without 1156893Sfenner * modification, are permitted provided that the following conditions 1256893Sfenner * are met: 1356893Sfenner * 1. Redistributions of source code must retain the above copyright 1456893Sfenner * notice, this list of conditions and the following disclaimer. 1556893Sfenner * 2. Redistributions in binary form must reproduce the above copyright 1656893Sfenner * notice, this list of conditions and the following disclaimer in the 1756893Sfenner * documentation and/or other materials provided with the distribution. 1856893Sfenner * 3. All advertising materials mentioning features or use of this software 1956893Sfenner * must display the following acknowledgement: 2056893Sfenner * This product includes software developed by the NetBSD 2156893Sfenner * Foundation, Inc. and its contributors. 2256893Sfenner * 4. Neither the name of The NetBSD Foundation nor the names of its 2356893Sfenner * contributors may be used to endorse or promote products derived 2456893Sfenner * from this software without specific prior written permission. 2556893Sfenner * 2656893Sfenner * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2756893Sfenner * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2856893Sfenner * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2956893Sfenner * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3056893Sfenner * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3156893Sfenner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3256893Sfenner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3356893Sfenner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3456893Sfenner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3556893Sfenner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3656893Sfenner * POSSIBILITY OF SUCH DAMAGE. 3756893Sfenner */ 3856893Sfenner 3956893Sfenner#ifdef HAVE_CONFIG_H 4056893Sfenner#include "config.h" 4156893Sfenner#endif 4256893Sfenner 4356893Sfenner#ifndef lint 44127668Sbmsstatic const char rcsid[] _U_ = 45190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.15 2004-03-24 01:58:14 guy Exp $"; 4656893Sfenner#endif 4756893Sfenner 48127668Sbms#include <tcpdump-stdinc.h> 4956893Sfenner 5056893Sfenner#include <stdio.h> 5156893Sfenner 5256893Sfenner#include "interface.h" 5356893Sfenner#include "addrtoname.h" 5456893Sfenner#include "extract.h" /* must come after interface.h */ 5556893Sfenner 5656893Sfenner#define MOBILE_SIZE (8) 5756893Sfenner 5856893Sfennerstruct mobile_ip { 5956893Sfenner u_int16_t proto; 6056893Sfenner u_int16_t hcheck; 6156893Sfenner u_int32_t odst; 6256893Sfenner u_int32_t osrc; 6356893Sfenner}; 6456893Sfenner 6556893Sfenner#define OSRC_PRES 0x0080 /* old source is present */ 6656893Sfenner 6756893Sfenner/* 6856893Sfenner * Deencapsulate and print a mobile-tunneled IP datagram 6956893Sfenner */ 7056893Sfennervoid 7156893Sfennermobile_print(const u_char *bp, u_int length) 7256893Sfenner{ 7356893Sfenner const u_char *cp = bp +8 ; 7456893Sfenner const struct mobile_ip *mob; 75235530Sdelphij struct cksum_vec vec[1]; 7656893Sfenner u_short proto,crc; 7756893Sfenner u_char osp =0; /* old source address present */ 7856893Sfenner 7956893Sfenner mob = (const struct mobile_ip *)bp; 8056893Sfenner 81146773Ssam if (length < MOBILE_SIZE || !TTEST(*mob)) { 8256893Sfenner fputs("[|mobile]", stdout); 8356893Sfenner return; 8456893Sfenner } 8598524Sfenner fputs("mobile: ", stdout); 8656893Sfenner 8756893Sfenner proto = EXTRACT_16BITS(&mob->proto); 8856893Sfenner crc = EXTRACT_16BITS(&mob->hcheck); 8956893Sfenner if (proto & OSRC_PRES) { 9056893Sfenner osp=1; 9156893Sfenner cp +=4 ; 9256893Sfenner } 93127668Sbms 9456893Sfenner if (osp) { 9556893Sfenner fputs("[S] ",stdout); 9656893Sfenner if (vflag) 9756893Sfenner (void)printf("%s ",ipaddr_string(&mob->osrc)); 9856893Sfenner } else { 9956893Sfenner fputs("[] ",stdout); 10056893Sfenner } 10156893Sfenner if (vflag) { 10256893Sfenner (void)printf("> %s ",ipaddr_string(&mob->odst)); 10356893Sfenner (void)printf("(oproto=%d)",proto>>8); 10456893Sfenner } 105235530Sdelphij vec[0].ptr = (const u_int8_t *)(void *)mob; 106235530Sdelphij vec[0].len = osp ? 12 : 8; 107235530Sdelphij if (in_cksum(vec, 1)!=0) { 10856893Sfenner (void)printf(" (bad checksum %d)",crc); 10956893Sfenner } 11056893Sfenner 11156893Sfenner return; 11256893Sfenner} 113