Home | History | Annotate | Line # | Download | only in dist
print-enc.c revision 1.1
      1  1.1  christos /*	$OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that: (1) source code distributions
      9  1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
     10  1.1  christos  * distributions including binary code include the above copyright notice and
     11  1.1  christos  * this paragraph in its entirety in the documentation or other materials
     12  1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     13  1.1  christos  * features or use of this software display the following acknowledgement:
     14  1.1  christos  * ``This product includes software developed by the University of California,
     15  1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     16  1.1  christos  * the University nor the names of its contributors may be used to endorse
     17  1.1  christos  * or promote products derived from this software without specific prior
     18  1.1  christos  * written permission.
     19  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     20  1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     21  1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     22  1.1  christos  */
     23  1.1  christos 
     24  1.1  christos #ifndef lint
     25  1.1  christos static const char rcsid[] _U_ =
     26  1.1  christos     "@(#) Header: /tcpdump/master/tcpdump/print-enc.c,v 1.6 2008-11-18 07:35:32 guy Exp (LBL)";
     27  1.1  christos #endif
     28  1.1  christos 
     29  1.1  christos #ifdef HAVE_CONFIG_H
     30  1.1  christos #include "config.h"
     31  1.1  christos #endif
     32  1.1  christos 
     33  1.1  christos #include <tcpdump-stdinc.h>
     34  1.1  christos 
     35  1.1  christos #include <pcap.h>
     36  1.1  christos 
     37  1.1  christos #include "interface.h"
     38  1.1  christos #include "extract.h"
     39  1.1  christos #include "addrtoname.h"
     40  1.1  christos 
     41  1.1  christos #include "enc.h"
     42  1.1  christos 
     43  1.1  christos #define ENC_PRINT_TYPE(wh, xf, nam) \
     44  1.1  christos 	if ((wh) & (xf)) { \
     45  1.1  christos 		printf("%s%s", nam, (wh) == (xf) ? "): " : ","); \
     46  1.1  christos 		(wh) &= ~(xf); \
     47  1.1  christos 	}
     48  1.1  christos 
     49  1.1  christos u_int
     50  1.1  christos enc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
     51  1.1  christos {
     52  1.1  christos 	register u_int length = h->len;
     53  1.1  christos 	register u_int caplen = h->caplen;
     54  1.1  christos 	int flags;
     55  1.1  christos 	const struct enchdr *hdr;
     56  1.1  christos 
     57  1.1  christos 	if (caplen < ENC_HDRLEN) {
     58  1.1  christos 		printf("[|enc]");
     59  1.1  christos 		goto out;
     60  1.1  christos 	}
     61  1.1  christos 
     62  1.1  christos 	hdr = (struct enchdr *)p;
     63  1.1  christos 	flags = hdr->flags;
     64  1.1  christos 	if (flags == 0)
     65  1.1  christos 		printf("(unprotected): ");
     66  1.1  christos 	else
     67  1.1  christos 		printf("(");
     68  1.1  christos 	ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
     69  1.1  christos 	ENC_PRINT_TYPE(flags, M_CONF, "confidential");
     70  1.1  christos 	/* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
     71  1.1  christos 	printf("SPI 0x%08x: ", EXTRACT_32BITS(&hdr->spi));
     72  1.1  christos 
     73  1.1  christos 	length -= ENC_HDRLEN;
     74  1.1  christos 	caplen -= ENC_HDRLEN;
     75  1.1  christos 	p += ENC_HDRLEN;
     76  1.1  christos 
     77  1.1  christos 	switch (hdr->af) {
     78  1.1  christos 	case AF_INET:
     79  1.1  christos 		ip_print(gndo, p, length);
     80  1.1  christos 		break;
     81  1.1  christos #ifdef INET6
     82  1.1  christos 	case AF_INET6:
     83  1.1  christos 		ip6_print(p, length);
     84  1.1  christos 		break;
     85  1.1  christos #endif /*INET6*/
     86  1.1  christos 	}
     87  1.1  christos 
     88  1.1  christos out:
     89  1.1  christos 	return (ENC_HDRLEN);
     90  1.1  christos }
     91  1.1  christos 
     92  1.1  christos 
     93  1.1  christos /*
     94  1.1  christos  * Local Variables:
     95  1.1  christos  * c-style: whitesmith
     96  1.1  christos  * c-basic-offset: 8
     97  1.1  christos  * End:
     98  1.1  christos  */
     99