156893Sfenner/* 256893Sfenner * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 356893Sfenner * The Regents of the University of California. All rights reserved. 456893Sfenner * 556893Sfenner * Redistribution and use in source and binary forms, with or without 656893Sfenner * modification, are permitted provided that: (1) source code distributions 756893Sfenner * retain the above copyright notice and this paragraph in its entirety, (2) 856893Sfenner * distributions including binary code include the above copyright notice and 956893Sfenner * this paragraph in its entirety in the documentation or other materials 1056893Sfenner * provided with the distribution, and (3) all advertising materials mentioning 1156893Sfenner * features or use of this software display the following acknowledgement: 1256893Sfenner * ``This product includes software developed by the University of California, 1356893Sfenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1456893Sfenner * the University nor the names of its contributors may be used to endorse 1556893Sfenner * or promote products derived from this software without specific prior 1656893Sfenner * written permission. 1756893Sfenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1856893Sfenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1956893Sfenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2056893Sfenner */ 2156893Sfenner 2256893Sfenner#ifndef lint 23127668Sbmsstatic const char rcsid[] _U_ = 24190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-ipcomp.c,v 1.20 2003-11-19 00:36:08 guy Exp $"; 2556893Sfenner#endif 2656893Sfenner 2756893Sfenner#ifdef HAVE_CONFIG_H 2856893Sfenner#include "config.h" 2956893Sfenner#endif 3056893Sfenner 3156893Sfenner#include <string.h> 32127668Sbms#include <tcpdump-stdinc.h> 3356893Sfenner 3456893Sfenner#include <stdio.h> 3556893Sfenner 3656893Sfennerstruct ipcomp { 3756893Sfenner u_int8_t comp_nxt; /* Next Header */ 3856893Sfenner u_int8_t comp_flags; /* Length of data, in 32bit */ 3956893Sfenner u_int16_t comp_cpi; /* Compression parameter index */ 4056893Sfenner}; 4156893Sfenner 4256893Sfenner#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) 4356893Sfenner#include <zlib.h> 4456893Sfenner#endif 4556893Sfenner 4656893Sfenner#include "interface.h" 4756893Sfenner#include "addrtoname.h" 48127668Sbms#include "extract.h" 4956893Sfenner 5056893Sfennerint 51127668Sbmsipcomp_print(register const u_char *bp, int *nhdr _U_) 5256893Sfenner{ 5356893Sfenner register const struct ipcomp *ipcomp; 5456893Sfenner register const u_char *ep; 5556893Sfenner u_int16_t cpi; 5656893Sfenner#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) 5756893Sfenner int advance; 5856893Sfenner#endif 5956893Sfenner 6056893Sfenner ipcomp = (struct ipcomp *)bp; 61127668Sbms cpi = EXTRACT_16BITS(&ipcomp->comp_cpi); 6256893Sfenner 6375115Sfenner /* 'ep' points to the end of available data. */ 6456893Sfenner ep = snapend; 6556893Sfenner 6656893Sfenner if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) { 6756893Sfenner fputs("[|IPCOMP]", stdout); 6856893Sfenner goto fail; 6956893Sfenner } 7075115Sfenner printf("IPComp(cpi=0x%04x)", cpi); 7156893Sfenner 7256893Sfenner#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) 7356893Sfenner if (1) 7456893Sfenner goto fail; 7556893Sfenner 7656893Sfenner /* 7756893Sfenner * We may want to decompress the packet here. Packet buffer 7856893Sfenner * management is a headache (if we decompress, packet will become 7956893Sfenner * larger). 8056893Sfenner */ 8156893Sfenner if (nhdr) 8256893Sfenner *nhdr = ipcomp->comp_nxt; 8356893Sfenner advance = sizeof(struct ipcomp); 8456893Sfenner 8556893Sfenner printf(": "); 8656893Sfenner return advance; 8756893Sfenner 8856893Sfenner#endif 8956893Sfennerfail: 90127668Sbms return -1; 9156893Sfenner} 92