/*
 * TCPVIEW
 *
 * Author:	Martin Hunt
 *		Networks and Distributed Computing
 *		Computing & Communications
 *		University of Washington
 *		Administration Building, AG-44
 *		Seattle, WA  98195
 *		Internet: martinh@cac.washington.edu
 *
 *
 * Copyright 1992 by the University of Washington
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appears in all copies and that both the
 * above copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the University of Washington not be
 * used in advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  This software is made
 * available "as is", and
 * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
 * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
 * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifndef lint
static char rcsid[] =
    "@(#) $Header: /usr/staff/martinh/tcpview/RCS/detail-ether.c,v 1.2 1993/04/22 20:16:01 martinh Exp $ (UW)";
#endif

#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h> 
#include <netinet/if_ether.h>

#include "tcpview.h"
#include "addrtoname.h"

void detail_ip();
void detail_arp();

void detail_ether( p )
u_char *p;
{
  struct ether_header *ep;
  int i;
  char *str1, *str2;
  int thiszone = 0;
  struct timeval *tvp;

  ep = (struct ether_header *)p;
  tvp = &Phdr->ts;
  Offset = 0;

  printf("----- DLC header -----\n\nFrame arrived at ");
  i = (tvp->tv_sec + thiszone) % 86400;
  printf("%02d:%02d:%02d.%04d ",i / 3600, (i % 3600) / 60, 
		i % 60,tvp->tv_usec/100);
  printf("  Frame size is %d (%d captured) bytes\n",Phdr->len,Phdr->caplen);
  str1 = etheraddr_str(EDST(ep),ADDR_NUMERICAL);
  str2 = etheraddr_str(EDST(ep),0);
  if (*str1==*str2) str2="";
  printf("Destination =   %s  %s\n",str1,str2);
  str1 = etheraddr_str(ESRC(ep),ADDR_NUMERICAL);
  str2 = etheraddr_str(ESRC(ep),0);
  if (*str1==*str2) str2="";
  printf("Source      =   %s  %s\n",str1,str2);
  printf("Ethertype   =   %4s (%s)\n",
	etherproto_str(ep->ether_type,ADDR_NUMERICAL),
	etherproto_str(ep->ether_type,0));
  printf("\n");

  ep = (struct ether_header *)p;
  p += sizeof(struct ether_header);

  hex_reset();				/* start of a new frame */
  hex(0,sizeof(struct ether_header)-1);	/* header */
  hex(-1,-1);				/* blank line */
  hex(-1,-1);				/* frame time and size */
  hex(0,5);				/* destination */
  hex(6,11);				/* source */
  hex(12,13);				/* ethertype */
  hex(-1,-1);				/* blank line */

  Offset = sizeof(struct ether_header);

  switch (ntohs(ep->ether_type)) {
  case ETHERTYPE_IP:
    detail_ip(p); 
    break;    
  case ETHERTYPE_ARP:
  case ETHERTYPE_REVARP:
    detail_arp(p);
    break;    
  default:
    break;
  }
}



syntax highlighted by Code2HTML, v. 0.9.1