/*******************************************************************************
**
**	Diagnostic Output Code for RPC
**
**  This code is part of the RPC system from CERN DD/OC and collaborators.
**
**
**
**     Sep 90	Taken from rpc_eth_dummy.c
**
*/

#include <stdio.h>

#define TS			/* We want TS_layer visibility */
#define TCP
#define ETHERNET
#define V24			/* we want to see all transport types */   
 
#include "syspec.h"
#include "rpcrts.h"		/* RPC structures including TS layer */
#include "rpc_code.h"		/*Coding conventions and trace */

/*			UTILITY ROUTINES
**
**	Print out socket descriptor
**	---------------------------
**
**
*/
#ifdef __STDC__
dump_socket(socket_type soc)
#else
dump_socket(soc)
    socket_type soc;
#endif
{
  if (rpc_trace) {
    UTRACE(tfp,"    Socket at %lx:\n", (long int) soc);
    UTRACE(tfp,"        next @            %lx\n",   (long int)soc->soc_next);
    UTRACE(tfp,"        astadr =          %lx\n",   (long int)soc->soc_astadr);
    UTRACE(tfp,"        astprm =          %lx\n",   (long int)soc->soc_astprm);
/*
    UTRACE(tfp,"        last call sent @  %lx\n",   (long int)soc->soc_last_call_sent);
    UTRACE(tfp,"        last reply sent @ %lx\n",   (long int)soc->soc_last_reply_sent);
    UTRACE(tfp,"        event flag num =  %lx\n",   soc->soc_efn;
*/
    UTRACE(tfp,"        medium =          ");
    switch(soc->soc_medium) {

    case invalid_medium:
	UTRACE(tfp, "INVALID (ZERO)\n");
	break;
    case v24:
	UTRACE(tfp, "V24\n");
	break;
    case ether:
	UTRACE(tfp, "ETHERNET\n");

/* cut out for now
	UTRACE(tfp, "        Address filter: %2x_%2x_%2x_%2x_%2x_%2x %2x_%2x\n",
		    soc->mdp.soc_ether.soc_addr_filter[0],
		    soc->mdp.soc_ether.soc_addr_filter[1],
		    soc->mdp.soc_ether.soc_addr_filter[2],
		    soc->mdp.soc_ether.soc_addr_filter[3],
		    soc->mdp.soc_ether.soc_addr_filter[4],
		    soc->mdp.soc_ether.soc_addr_filter[5],
		    soc->mdp.soc_ether.soc_type_filter.h,
		    soc->mdp.soc_ether.soc_type_filter.l);
	UTRACE(tfp, "        Address mask:   %2x_%2x_%2x_%2x_%2x_%2x %2x_%2x\n",
		    soc->mdp.soc_ether.soc_addr_mask[0],
		    soc->mdp.soc_ether.soc_addr_mask[1],
		    soc->mdp.soc_ether.soc_addr_mask[2],
		    soc->mdp.soc_ether.soc_addr_mask[3],
		    soc->mdp.soc_ether.soc_addr_mask[4],
		    soc->mdp.soc_ether.soc_addr_mask[5],
		    soc->mdp.soc_ether.soc_type_mask.h,
		    soc->mdp.soc_ether.soc_type_mask.l);
	UTRACE(tfp, "        Header of last packet received on this socket:\n");
	UTRACE(tfp, "           To:     %2x_%2x_%2x_%2x_%2x_%2x\n",
		    soc->mdp.soc_ether.soc_rx_dest_addr[0],
		    soc->mdp.soc_ether.soc_rx_dest_addr[1],
		    soc->mdp.soc_ether.soc_rx_dest_addr[2],
		    soc->mdp.soc_ether.soc_rx_dest_addr[3],
		    soc->mdp.soc_ether.soc_rx_dest_addr[4],
		    soc->mdp.soc_ether.soc_rx_dest_addr[5]);
	UTRACE(tfp, "           From:   %2x_%2x_%2x_%2x_%2x_%2x\n",
		    soc->mdp.soc_ether.soc_rx_source_addr[0],
		    soc->mdp.soc_ether.soc_rx_source_addr[1],
		    soc->mdp.soc_ether.soc_rx_source_addr[2],
		    soc->mdp.soc_ether.soc_rx_source_addr[3],
		    soc->mdp.soc_ether.soc_rx_source_addr[4],
		    soc->mdp.soc_ether.soc_rx_source_addr[5]);
	UTRACE(tfp, "           Ptype:  %2x_%2x\n",
		    soc->mdp.soc_ether.soc_rx_protocol_type.h,
		    soc->mdp.soc_ether.soc_rx_protocol_type.l);
*/
	break;
    decnet:
	UTRACE(tfp, "DECNET\n");
	break;
    ieee:
	UTRACE(tfp, "IEEE\n");
	break;
    x25:
	UTRACE(tfp, "X25\n");
	break;
    drb:
	UTRACE(tfp, "DRB/CHI/HVIOR link\n");
	break;
    udp:
	UTRACE(tfp, "UDP/IP\n");
	break;
    tcp:
	UTRACE(tfp, "TCP/IP\n");
	break;
    default:
	UTRACE(tfp,"Junk: hex %x\n", (int)soc->soc_medium);
    } /*switch */

    UTRACE(tfp,"\n");
  } /* end if trace */
} /* dump socket */

/*	Dump RPC Message Internal bits			    dump_message()
**	------------------------------
**
*/
#ifdef __STDC__
void dump_message(rpc_message_pointer mes)
#else
void dump_message(mes)
    rpc_message_pointer mes;
#endif
{
  int	i;
  if (rpc_trace) {
    UTRACE(tfp, "    Message at %lx:\n", (long int)mes);
    UTRACE(tfp, "        Next at     %lx",	(long int)mes->m_next);
    UTRACE(tfp, "        Status is   %lx\n",	(long int)mes->m_status);
    UTRACE(tfp, "        Socket at   %lx",	(long int)mes->m_socket);
    UTRACE(tfp, "        Index is    %lx\n",	(long int)mes->m_index);
    UTRACE(tfp, "        Protocol header:\n");
    UTRACE(tfp, "            ");
    for(i=0; i<16; i++)
	UTRACE(tfp, "%2x ", (int)(((unsigned char*)(&mes->header))[i]));
    UTRACE(tfp, "\n");
    UTRACE(tfp, "\n");
  }
}

