print-ipcomp.c revision 146774
1254721Semaste/*
2254721Semaste * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3254721Semaste *	The Regents of the University of California.  All rights reserved.
4254721Semaste *
5254721Semaste * Redistribution and use in source and binary forms, with or without
6254721Semaste * modification, are permitted provided that: (1) source code distributions
7254721Semaste * retain the above copyright notice and this paragraph in its entirety, (2)
8254721Semaste * distributions including binary code include the above copyright notice and
9254721Semaste * this paragraph in its entirety in the documentation or other materials
10254721Semaste * provided with the distribution, and (3) all advertising materials mentioning
11254721Semaste * features or use of this software display the following acknowledgement:
12254721Semaste * ``This product includes software developed by the University of California,
13314564Sdim * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14314564Sdim * the University nor the names of its contributors may be used to endorse
15254721Semaste * or promote products derived from this software without specific prior
16254721Semaste * written permission.
17314564Sdim * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18296417Sdim * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19309124Sdim * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20296417Sdim */
21254721Semaste
22254721Semaste#ifndef lint
23254721Semastestatic const char rcsid[] _U_ =
24254721Semaste    "@(#) $Header: /tcpdump/master/tcpdump/print-ipcomp.c,v 1.20 2003/11/19 00:36:08 guy Exp $";
25254721Semaste#endif
26288943Sdim
27254721Semaste#ifdef HAVE_CONFIG_H
28254721Semaste#include "config.h"
29314564Sdim#endif
30254721Semaste
31288943Sdim#include <string.h>
32288943Sdim#include <tcpdump-stdinc.h>
33254721Semaste
34314564Sdim#include <stdio.h>
35254721Semaste
36314564Sdimstruct ipcomp {
37254721Semaste	u_int8_t comp_nxt;	/* Next Header */
38314564Sdim	u_int8_t comp_flags;	/* Length of data, in 32bit */
39254721Semaste	u_int16_t comp_cpi;	/* Compression parameter index */
40314564Sdim};
41314564Sdim
42314564Sdim#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
43314564Sdim#include <zlib.h>
44314564Sdim#endif
45254721Semaste
46314564Sdim#include "interface.h"
47314564Sdim#include "addrtoname.h"
48314564Sdim#include "extract.h"
49314564Sdim
50314564Sdimint
51314564Sdimipcomp_print(register const u_char *bp, int *nhdr _U_)
52314564Sdim{
53314564Sdim	register const struct ipcomp *ipcomp;
54314564Sdim	register const u_char *ep;
55314564Sdim	u_int16_t cpi;
56314564Sdim#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
57314564Sdim	int advance;
58314564Sdim#endif
59314564Sdim
60314564Sdim	ipcomp = (struct ipcomp *)bp;
61314564Sdim	cpi = EXTRACT_16BITS(&ipcomp->comp_cpi);
62314564Sdim
63314564Sdim	/* 'ep' points to the end of available data. */
64314564Sdim	ep = snapend;
65314564Sdim
66254721Semaste	if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) {
67314564Sdim		fputs("[|IPCOMP]", stdout);
68254721Semaste		goto fail;
69314564Sdim	}
70314564Sdim	printf("IPComp(cpi=0x%04x)", cpi);
71314564Sdim
72314564Sdim#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
73314564Sdim	if (1)
74314564Sdim		goto fail;
75314564Sdim
76262528Semaste	/*
77314564Sdim	 * We may want to decompress the packet here.  Packet buffer
78296417Sdim	 * management is a headache (if we decompress, packet will become
79314564Sdim	 * larger).
80254721Semaste	 */
81314564Sdim	if (nhdr)
82254721Semaste		*nhdr = ipcomp->comp_nxt;
83314564Sdim	advance = sizeof(struct ipcomp);
84314564Sdim
85254721Semaste	printf(": ");
86314564Sdim	return advance;
87314564Sdim
88254721Semaste#endif
89314564Sdimfail:
90254721Semaste	return -1;
91314564Sdim}
92314564Sdim