/*
 *	PPPDUMP.C
 *
 *	12-89	-- Katie Stevens (dkstevens@ucdavis.edu)
 *		   UC Davis, Computing Services
 *	PPP.08	05-90	[ks] improve tracing reports
 *	PPP.09  05-90	[ks] add UPAP packet reporting
 *	PPP.14	08-90	[ks] change UPAP to PAP for consistency with RFC1172
 *	PPP.15	09-90	[ks] update to KA9Q NOS v900828
 */
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "proc.h"
#include "iface.h"
#include "internet.h"
#include "slcompre.h"
#include "slip.h"
#include "ppp.h"
#include "trace.h"

/* dump a PPP packet */
void
ppp_dump(fp,bpp,unused)
FILE *fp;
struct mbuf **bpp;
int unused;
{
	struct ppphdr phdr;
	struct mbuf *bp, *tbp;

	ntohppp(&phdr,bpp);
	fprintf(fp,"PPP: len %3u     ",(PPP_HDRLEN + len_p(*bpp)));
	if (phdr.addr != HDLC_ALL_ADDR)
		fprintf(fp,"!invalid addr field  ");
	if (phdr.control != HDLC_UI)
		fprintf(fp,"!invalid ctl field  ");

	switch(phdr.type){
		case PPP_IP_TYPE:
			fprintf(fp,"\t\tprotocol: IP\n");
			ip_dump(fp,bpp,1);
			break;
		case PPP_IPCP_TYPE:
			fprintf(fp,"\t\tprotocol: IPCP\n");
			break;
		case PPP_LCP_TYPE:
			fprintf(fp,"\t\tprotocol: LCP\n");
			break;
		case PPP_PAP_TYPE:
			fprintf(fp,"\t\tprotocol: PAP\n");
			break;
		case PPP_COMPR_TYPE:
			fprintf(fp,"\t\tprotocol: VJ Compr TCP/IP\n");
			vjcomp_dump(fp,bpp,0);
			break;
		case PPP_UNCOMP_TYPE:
			fprintf(fp,"\t\tprotocol: VJ Uncompr TCP/IP\n");
			fprintf(fp,"VJ Uncompr TCP/IP: connection 0x%02x\n",(*bpp)->data[9]);	/* FIX THIS! */
			/* Get our own copy so we can mess with the data */
			bp = *bpp;
			tbp = copy_p(bp, len_p(bp));
			free_p(bp);
			*bpp = NULLBUF;
			/* Restore the bytes used with Uncompressed TCP */
			tbp->data[9] = TCP_PTCL;	/* FIX THIS! */
			ip_dump(fp,&tbp,1);
			break;
		default:
			fprintf(fp,"  unknown protocol: 0x%04x\n",phdr.type);
			break;
	}
}
