Plan 9 from Bell Labs’s /usr/web/sources/contrib/lucio/asn1/devel/mcsfs.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
*/

/*
*/
#include <u.h>
#include <libc.h>
#include "ber.h"

#define		MCS_TAG_DOMAIN_PARAMS	(12)
#define		MCS_CONNECT_INITIAL		(11)

/* Prepare a DOMAIN_PARAMS structure */
static BerObj *
mcs_domprms (int max_channels, int max_users, int max_tokens, int max_pdusize)
{
	BerObj *o = ber_init (MCS_TAG_DOMAIN_PARAMS);

	if (!o)
		return nil;
	ber_attach (o, ber_int2 (max_channels));
	ber_attach (o, ber_int2 (max_users));
	ber_attach (o, ber_int2 (max_tokens));
	ber_attach (o, ber_int2 (1));	/* num_priorities */
	ber_attach (o, ber_int2 (0));	/* min_throughput */
	ber_attach (o, ber_int2 (1));	/* max_height */
	ber_attach (o, ber_int2 (max_pdusize));
	ber_attach (o, ber_int2 (2));	/* ver_protocol */
	ber_seal (o);
	return o;
}

/* Prepare an MCS_CONNECT_INITIAL message */
static BerObj *
mcs_conninit (char *data, int len)
{
	BerObj *o = ber_init (MCS_CONNECT_INITIAL);

	if (!o)
		return nil;
	ber_attach (o, ber_ostr (nil, 0));	/* calling domain */
	ber_attach (o, ber_ostr (nil, 0));	/* called domain */
	ber_attach (o, ber_bool (BER_FALSE));
	ber_attach (o, mcs_domprms (2, 2, 0, 0xffff));					/* target params */
	ber_attach (o, mcs_domprms (1, 1, 1, 0x420));					/* min params */
	ber_attach (o, mcs_domprms (0xffff, 0xfc17, 0xffff, 0xffff));	/* max params */
	ber_attach (o, ber_ostr (data, len));
	ber_seal (o);
	return o;
}


int
main (int argc, char *argv[])
{
	BerObj *o, *o1, *o2, *o3, *o4;
	int s;

	// o1 = mcs_domprms (4, 3, 2, 1);
	o1 = mcs_conninit ("this is a message", 17);
	o2 = ber_parse (o1->buf);
	ber_print (o2, 1);
	
	return 0;
}

void none (void) {
/*
	o1 = ber_init (12);
		o2 = ber_init (14);
		ber_append (o2, ber_simple (201, "tessiexcnfkfjdgdfkghkdfghkdahakfhaksfhsafhasfhsakfhsakfhksfhaksjhfksajfhksajhfksajhdfjksfhjksfhjksafhjksafhjkshfjkshdfjksfhksfhjksfhjksfhksfhjksfhklsfhfhlsakfhkshjdfhdsfhjdsflfhksfhfhkshjdfklhnx,cmbvnx,zbvnx,zbvnx,znv.,nflkhjdsflakfh", 201));
			o4 = ber_simple (8, "test", 4);
		ber_append (o2, o4);
		ber_seal (o2);
	ber_append (o1, o2);
		o3 = ber_simple (16, "sample", 6);
	ber_append (o1, o3);
	ber_seal (o1);

	print ("BER:");
	for (s = 0; s < o1->len; s++)
		print (" %#x", o1->buf[s] & 0xFF);
	print ("\n");

	o = ber_parse (o1->buf, o1->len);
	print ("BER: tag = %d - len = %d - size = %d ", o->tag, o->len, o->size);
	for (s = 0; s < o->len; s++)
		print (" %#x", o->buf[s] & 0xFF);
	print ("\n");
	o2 = ber_parse (o->buf, o->len);
	print ("BER: tag = %d - len = %d - size = %d ", o2->tag, o2->len, o2->size);
	for (s = 0; s < o2->len; s++)
		print (" %#x", o2->buf[s] & 0xFF);
	print ("\n");

		o2 = ber_init (14);
		ber_attach (o2, ber_simple (201, "tessiexcnfkfjdgdfkghkdfghkdahakfhaksfhsafhasfhsakfhsakfhksfhaksjhfksajfhksajhfksajhdfjksfhjksfhjksafhjksafhjkshfjkshdfjksfhksfhjksfhjksfhksfhjksfhklsfhfhlsakfhkshjdfhdsfhjdsflfhksfhfhkshjdfklhnx,cmbvnx,zbvnx,zbvnx,znv.,nflkhjdsflakfh", 201));
		print ("BOB: tag = %d - len = %d - size = %d ", o2->tag, o2->len, o2->size);
		for (s = 0; s < o2->len; s++)
			print (" %#x", o2->buf[s] & 0xFF);
		print ("\n");
			o3 = ber_init (99);
				ber_attach (o3, ber_simple (5, "this is a dummy", 15));
				o1 = ber_init (87);
					ber_attach (o1, ber_simple (12, "nothing at all", 15));
					ber_attach (o1, ber_simple (17, "and mor of it", 13));
				ber_attach (o3, o1);
			ber_seal (o3);
			ber_attach (o2, o3);
			o4 = ber_simple (8, "test", 4);
print ("PTR: o4 = %ld - len = %d\n", (long)(void *)o4, o4->len);
print ("PTRs(1): down = %ld - next = %ld\n", (long)(void *)o4->down, (long)(void *)o4->next);
		print ("BOB: tag = %d - len = %d - size = %d ", o4->tag, o4->len, o4->size);
		for (s = 0; s < o4->len; s++)
			print (" %#x", o4->buf[s] & 0xFF);
		print ("\n");
		ber_attach (o2, o4);
print ("PTR: o4 = %ld - len = %d\n", (long)(void *)o4, o4->len);
print ("PTRs(1): down = %ld - next = %ld\n", (long)(void *)o4->down, (long)(void *)o4->next);
		print ("BOB: tag = %d - len = %d - size = %d ", o2->tag, o2->len, o2->size);
		for (s = 0; s < o2->len; s++)
			print (" %#x", o2->buf[s] & 0xFF);
		print ("\n");
		ber_attach (o2, ber_simple (16, "sample", 6));
		ber_seal (o2);
		print ("FULL: tag = %d - len = %d - size = %d ", o2->tag, o2->len, o2->size);
		for (s = 0; s < o2->len; s++)
			print (" %#x", o2->buf[s] & 0xFF);
		print ("\n");
	o = ber_parse (o2->buf);
	print ("FINAL: tag = %d - len = %d - size = %d ", o->tag, o->len, o->size);
	for (s = 0; s < o->size; s++)
		print (" %#x", o->buf[s] & 0xFF);
	print ("\n");
	ber_print (o, 1);
#ifdef	FIXED_SEAL
	ber_seal (o);
	o2 = ber_parse (o->buf);
	print ("FINAL: tag = %d - len = %d - size = %d ", o2->tag, o2->len, o2->size);
	for (s = 0; s < o2->size; s++)
		print (" %#x", o2->buf[s] & 0xFF);
	print ("\n");
	ber_print (o2, 1);
#endif
*/
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.