/*
 *	Copyright (c) 1995, 1996, Sun Microsystems, Inc.
 *
 * This software is provided by Sun ``AS IS'' and any express or implied
 * warranties, including, but not limited to, the implied warranties of
 * merchantability and fitness for a particular purpose are disclaimed.
 * In no event shall Sun Microsystems be liable for any direct, indirect,
 * incidental, special, exemplary, or consequential damages.
 *
 * This software is not a product, and is provided for evaluation purposes
 * only.
 *
 * This software may not be resold without the express permission of
 * Sun Microsystems.
 *
 * Feedback on this tool may be sent to packet-shell-owner@sunroof.eng.sun.com.
 *
 * Packet Shell - Protocol interpreter template
 *
 */

#pragma ident	"@(#)skeleton.c	1.10	99/05/28 SMI"

#include <stdlib.h>
#include <strings.h>
#include <tcl.h>
#include <stdlib.h>
#include "psh.h"
#include "proto.h"

static char *proto_name;

/*
 * Ancilliary TCL commands, if any
 */
static int
some_function(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
	return (0);
}

/*
 * Initialization
 */
int
init(proto_tbl_t *prototbl, Tcl_Interp *interp)
{
	/*
	 * Register protocol specific ancilliary commands, if any
	 */
	(void) Tcl_CreateCommand(interp, "skeleton.foo", some_function,
	    NULL, NULL);

	/*
	 * Set the protocol's name.
	 */
	if ((proto_name = strdup(prototbl->proto_name)) == NULL) {
		Tcl_AppendResult(interp, "Internal Error: no space left.",
		    NULL);
		return (0);
	}
	return (1);
}

int
propen(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
	return (TCL_ERROR);
}

int
prclose(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
	return (TCL_ERROR);
}

/*
 * Create a "default" packet.
 */
int
pinit(ClientData clientData, Tcl_Interp *interp,
    struct packet *pckt, int argc, char *argv[])
{
	Tcl_ResetResult(interp);
	if (ptbl_update(pckt, 1, NULL, pckt->p_len) == 0) {
		return (TCL_ERROR);
	}
	return (TCL_OK);
}

/*
 * Free a packet.
 */
int
pfree(ClientData clientData, Tcl_Interp *interp,
    struct packet *pckt, int argc, char *argv[])
{
	free(pckt->p_buf);
	return (TCL_OK);
}



int
decode(struct packet *pkt, int element, char **name, int *next_offset)
{
	*name = "decoded protocol name goes here";
	/*
	 * XXX - change me.  The line below is necessarily incomplete.
	 * In general, next_offset is always this element's offset (shown below)
	 * plus the size of this protocol's header or block of information.
	 * The "+ sizeof (struct protocol_header)" is not shown.  When
	 * using this skeleton, make that change below and delete this comment.
	 */
	*next_offset = pkt->p_tbl[element].pt_offset;
	return (1);
}

/*
 * Get protocol fields.
 */
int
get(int element, ClientData clientData, Tcl_Interp *interp, struct packet *pckt,
    int argc, char *argv[])
{
	return (TCL_ERROR);
}

/*
 * Set a protocol element
 */
int
set(int element, ClientData clientData, Tcl_Interp *interp, struct packet *pckt,
    int argc, char *argv[])
{
	return (TCL_ERROR);
}

int
list(int element, ClientData clientData, Tcl_Interp *interp,
    struct packet *pckt, int argc, char *argv[])
{
	return (TCL_ERROR);
}
