[comp.protocols.iso.dev-environ] Questions about ASN.1

kim@CS.COLUMBIA.EDU (Taeyon Kim) (05/10/91)

Hi,

I am a student in Columbia University doing a project in network management.
We are using ASN.1 in protocol specifications and I was having a problem.
We are using UDP socket to send a packet and string object Presentation
Stream.  I had a success with the full-duplex Presentation Stream object
with the TCP, but I found it a problem with UDP because UDP needs to specify
the sender's and receiver's address.  When I used dbx, the buffer was still
empty even after it was bound to PS.  

I will include my source code which contains the PEPY part in the following.
It might be a simple problem.  I will really appreciate your help.  Thank
you.


------------------------------- test.h ------------------------------------

typedef struct packetype {
     char *senderID;
     int packetID;
     int volume_num;
     int total_volume;
     int type;
     char *template_name;
     char *compileCmd;
     int length;
     char *body;
} Packet ;

-------------------- file test.py --------------------------------------------

MadPacket DEFINITIONS ::=

%{

#include "MAD_PT_defs.h"
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#define PEPYPARM Packet *

static char *myname = "MadPacket";
void adios ();

void packet_send();
int packet_receive();

void packet_send (socket, testpacket, receiver_addr, maxaddrlen)
int socket;
Packet *testpacket;
struct sockaddr receiver_addr;
int maxaddrlen;
{
	PE pe;
	PS ps;
	int stat;
	char buffer[2000];
	int nbytes;
	int i;

	if (build_MadPacket_PacketPDU (&pe, 1, NULL, NULLCP, testpacket) 
	    == NOTOK)
		adios (NULLCP, "encoder fails");

	bzero (buffer, 2000);

	if ( ( ps=ps_alloc(str_open)) == NULLPS )
		Error("PEPY: Allocating presentation stream");

	if ( (str_setup( ps, buffer, 2000 )) == NOTOK)
		Error("PEPY: Setting up full duplex file descriptor.");

	if ( pe2ps(ps,pe) == NOTOK )
		Error("PEPY: Converting PE to PS");   

/*	for (i=0; i < 2000; i++)
		mesg[i]=mesg[i]+10;
*/


	if (sendto(socket, buffer, 2000, 0, receiver_addr,
		maxaddrlen) != 	2000) 
	{
		Error("sendto");
		exit(-1);
	}

        ps_free(ps);
        pe_free(pe);
}


int packet_receive(socket, testpacket, sender_addr, maxaddrlen)
int socket;
Packet *testpacket;
struct sockaddr *sender_addr;
int maxaddrlen;
{
	PS ps2;
	PE pe2;
	int fromlen;
	int len;
	char buffer[2000];
	fd_set readset;
	int i;

	bzero(buffer, 2000);

	FD_ZERO (&readset);
	FD_SET (socket, &readset);
	select (FD_SETSIZE, &readset, (fd_set *)0, (fd_set *)0, NULL);
	if (FD_ISSET (socket, &readset))
	{

	fromlen = maxaddrlen;

	if ((len = recvfrom (socket, buffer, 2000, 0, sender_addr,
 		&fromlen)) < 0) 
	{
		Error("recvfrom");
		exit(-1);
	}

/*	for (i=0; i<len; i++)
		mesg[i] = mesg[i] - 10;
*/

	if ( ( ps2=ps_alloc(str_open)) == NULLPS )
		Error("PEPY: Allocating presentation stream");

	if ( (str_setup( ps2, NULLCP, len, 0)) == NOTOK)
		Error("PEPY: Setting up full duplex file descriptor.");

	pe2 = ps2pe(ps2);

	if (unbuild_MadPacket_PacketPDU(pe2, 1, NULLIP, NULLVP, testpacket)
	    ==	NOTOK) 
		adios (NULLCP, "decoder fails");

	ps_free(ps2);
	pe_free(pe2);
	return (DONE);	
	}

	ps_free(ps2);
	pe_free(pe2);
	return (NOT_READY);
}



%}

BEGIN

SECTIONS build unbuild none

PacketPDU ::=
	SEQUENCE {
	senderID
		IA5String [[s parm->senderID]],

	packetID
		INTEGER [[i parm->packetID]],

	volumenum
		INTEGER [[i parm->volume_num]],

	total
		INTEGER [[i parm->total_volume]],

	command
		INTEGER [[i parm->type]],

	templatename
		IA5String [[s parm->template_name]],

	compileCmd
		IA5String [[ s parm->compileCmd ]],

	length
		INTEGER [[ i parm->length]],

	body
		OCTET STRING [[o parm->body $ parm->length]]

}

	
END

%{

/* ERRORS */

#include <varargs.h>


#ifndef	lint
void	_advise ();


static void  adios (va_alist)
va_dcl
{
    va_list ap;

    va_start (ap);

    _advise (ap);

    va_end (ap);

    _exit (1);
}
#else
/* VARARGS */

static void  adios (what, fmt)
char   *what,
       *fmt;
{
    adios (what, fmt);
}
#endif


#ifndef	lint
static void  advise (va_alist)
va_dcl
{
    va_list ap;

    va_start (ap);

    _advise (ap);

    va_end (ap);
}


static void  _advise (ap)
va_list	ap;
{
    char    buffer[BUFSIZ];

    asprintf (buffer, ap);

    (void) fflush (stdout);

    fprintf (stderr, "%s: ", myname);
    (void) fputs (buffer, stderr);
    (void) fputc ('\n', stderr);

    (void) fflush (stderr);
}
#else
/* VARARGS */

static void  advise (what, fmt)
char   *what,
       *fmt;
{
    advise (what, fmt);
}
#endif

%}