print-null.c revision 17681
1232633Smp/*
259243Sobrien * Copyright (c) 1991, 1993, 1994, 1995, 1996
359243Sobrien *	The Regents of the University of California.  All rights reserved.
459243Sobrien *
559243Sobrien * Redistribution and use in source and binary forms, with or without
659243Sobrien * modification, are permitted provided that: (1) source code distributions
759243Sobrien * retain the above copyright notice and this paragraph in its entirety, (2)
859243Sobrien * distributions including binary code include the above copyright notice and
959243Sobrien * this paragraph in its entirety in the documentation or other materials
1059243Sobrien * provided with the distribution, and (3) all advertising materials mentioning
1159243Sobrien * features or use of this software display the following acknowledgement:
1259243Sobrien * ``This product includes software developed by the University of California,
1359243Sobrien * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1459243Sobrien * the University nor the names of its contributors may be used to endorse
1559243Sobrien * or promote products derived from this software without specific prior
1659243Sobrien * written permission.
17100616Smp * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1859243Sobrien * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1959243Sobrien * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2059243Sobrien */
2159243Sobrien
2259243Sobrien#ifndef lint
2359243Sobrienstatic char rcsid[] =
2459243Sobrien    "@(#)$Header: print-null.c,v 1.19 96/07/14 19:39:02 leres Exp $ (LBL)";
2559243Sobrien#endif
2659243Sobrien
2759243Sobrien#include <sys/param.h>
2859243Sobrien#include <sys/time.h>
2959243Sobrien#include <sys/socket.h>
3059243Sobrien#include <sys/file.h>
3159243Sobrien#include <sys/ioctl.h>
3259243Sobrien
3359243Sobrien#if __STDC__
3459243Sobrienstruct mbuf;
3559243Sobrienstruct rtentry;
3659243Sobrien#endif
3759243Sobrien#include <net/if.h>
3859243Sobrien
3959243Sobrien#include <netinet/in.h>
4059243Sobrien#include <netinet/in_systm.h>
4159243Sobrien#include <netinet/ip.h>
4259243Sobrien#include <netinet/if_ether.h>
4359243Sobrien#include <netinet/ip_var.h>
4459243Sobrien#include <netinet/udp.h>
4559243Sobrien#include <netinet/udp_var.h>
4659243Sobrien#include <netinet/tcp.h>
4759243Sobrien#include <netinet/tcpip.h>
4859243Sobrien
4959243Sobrien#include <stdio.h>
5059243Sobrien#include <string.h>
5159243Sobrien
5259243Sobrien#include "interface.h"
5359243Sobrien#include "addrtoname.h"
54232633Smp#include "pcap.h"
5559243Sobrien
5659243Sobrien#define	NULL_HDRLEN 4
5759243Sobrien
5859243Sobrienstatic void
5959243Sobriennull_print(const u_char *p, const struct ip *ip, u_int length)
6059243Sobrien{
6159243Sobrien	u_int family;
6259243Sobrien
6359243Sobrien	memcpy((char *)&family, (char *)p, sizeof(family));
6459243Sobrien
6559243Sobrien	if (nflag) {
6659243Sobrien		/* XXX just dump the header */
6759243Sobrien		return;
6859243Sobrien	}
6959243Sobrien	switch (family) {
7059243Sobrien
7159243Sobrien	case AF_INET:
7259243Sobrien		printf("ip: ");
7359243Sobrien		break;
7459243Sobrien
7559243Sobrien	case AF_NS:
7659243Sobrien		printf("ns: ");
7759243Sobrien		break;
7859243Sobrien
7959243Sobrien	default:
8059243Sobrien		printf("AF %d: ", family);
81195609Smp		break;
8259243Sobrien	}
8359243Sobrien}
8459243Sobrien
8559243Sobrienvoid
8659243Sobriennull_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
8759243Sobrien{
8859243Sobrien	u_int length = h->len;
8959243Sobrien	u_int caplen = h->caplen;
9059243Sobrien	const struct ip *ip;
9159243Sobrien
9259243Sobrien	ts_print(&h->ts);
9359243Sobrien
9459243Sobrien	/*
9559243Sobrien	 * Some printers want to get back at the link level addresses,
9659243Sobrien	 * and/or check that they're not walking off the end of the packet.
9759243Sobrien	 * Rather than pass them all the way down, we set these globals.
9859243Sobrien	 */
9959243Sobrien	packetp = p;
10059243Sobrien	snapend = p + caplen;
10159243Sobrien
10259243Sobrien	length -= NULL_HDRLEN;
10359243Sobrien
10459243Sobrien	ip = (struct ip *)(p + NULL_HDRLEN);
10559243Sobrien
106232633Smp	if (eflag)
10759243Sobrien		null_print(p, ip, length);
10859243Sobrien
10959243Sobrien	ip_print((const u_char *)ip, length);
11059243Sobrien
11159243Sobrien	if (xflag)
11259243Sobrien		default_print((const u_char *)ip, caplen - NULL_HDRLEN);
11359243Sobrien	putchar('\n');
11459243Sobrien}
11559243Sobrien
11659243Sobrien