print-enc.c revision 190221
137535Sdes/*	$OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $	*/
263012Sdes
337535Sdes/*
437535Sdes * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
537535Sdes *	The Regents of the University of California.  All rights reserved.
637535Sdes *
737535Sdes * Redistribution and use in source and binary forms, with or without
837535Sdes * modification, are permitted provided that: (1) source code distributions
937535Sdes * retain the above copyright notice and this paragraph in its entirety, (2)
1037535Sdes * distributions including binary code include the above copyright notice and
1137535Sdes * this paragraph in its entirety in the documentation or other materials
1237535Sdes * provided with the distribution, and (3) all advertising materials mentioning
1337535Sdes * features or use of this software display the following acknowledgement:
1437535Sdes * ``This product includes software developed by the University of California,
1563012Sdes * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1637535Sdes * the University nor the names of its contributors may be used to endorse
1737535Sdes * or promote products derived from this software without specific prior
1837535Sdes * written permission.
1937535Sdes * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
2037535Sdes * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
2137535Sdes * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2237535Sdes */
2337535Sdes
2437535Sdes#ifndef lint
2537535Sdesstatic const char rcsid[] _U_ =
2637535Sdes    "@(#) $Header: /tcpdump/master/tcpdump/print-enc.c,v 1.4.4.1 2008-02-06 10:34:15 guy Exp $ (LBL)";
2737535Sdes#endif
2863012Sdes
2937535Sdes#ifdef HAVE_CONFIG_H
3037535Sdes#include "config.h"
3137535Sdes#endif
3260737Sume
3337535Sdes#include <tcpdump-stdinc.h>
3463012Sdes
3537535Sdes#include <pcap.h>
3663012Sdes
3760376Sdes#include "interface.h"
3860189Sdes#include "addrtoname.h"
3937608Sdes
4037535Sdes#include "enc.h"
4137535Sdes
4237535Sdes#define ENC_PRINT_TYPE(wh, xf, nam) \
4360376Sdes	if ((wh) & (xf)) { \
4437535Sdes		printf("%s%s", nam, (wh) == (xf) ? "): " : ","); \
4537535Sdes		(wh) &= ~(xf); \
4637535Sdes	}
4740939Sdes
4841862Sdesu_int
4937535Sdesenc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
5063012Sdes{
5137535Sdes	register u_int length = h->len;
5263012Sdes	register u_int caplen = h->caplen;
5363012Sdes	int flags;
5437535Sdes	const struct enchdr *hdr;
5563012Sdes
5663012Sdes	if (caplen < ENC_HDRLEN) {
5763012Sdes		printf("[|enc]");
5863012Sdes		goto out;
5963012Sdes	}
6063012Sdes
6163012Sdes	hdr = (struct enchdr *)p;
6263012Sdes	flags = hdr->flags;
6363012Sdes	if (flags == 0)
6460196Sdes		printf("(unprotected): ");
6563012Sdes	else
6663012Sdes		printf("(");
6763012Sdes	ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
6863012Sdes	ENC_PRINT_TYPE(flags, M_CONF, "confidential");
6963012Sdes	/* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
7063012Sdes	printf("SPI 0x%08x: ", (u_int32_t)ntohl(hdr->spi));
7163012Sdes
7263012Sdes	length -= ENC_HDRLEN;
7363012Sdes	caplen -= ENC_HDRLEN;
7463012Sdes	p += ENC_HDRLEN;
7537535Sdes
7637535Sdes	switch (hdr->af) {
7763012Sdes	case AF_INET:
7863012Sdes		ip_print(gndo, p, length);
7963012Sdes		break;
8063012Sdes#ifdef INET6
8163012Sdes	case AF_INET6:
8263012Sdes		ip6_print(p, length);
8363012Sdes		break;
8463012Sdes#endif
8563012Sdes	}
8663012Sdes
8763012Sdesout:
8837535Sdes	return (ENC_HDRLEN);
8937535Sdes}
9037608Sdes
9163012Sdes
9237608Sdes/*
9337608Sdes * Local Variables:
9463012Sdes * c-style: whitesmith
9537608Sdes * c-basic-offset: 8
9663012Sdes * End:
9737608Sdes */
9863012Sdes