[183] in Kerberos_V5_Development

home help back first fref pref prev next nref lref last post

[cpw%snow-white@LANL.GOV (C. Philip Wood): Re: Looking for the map of SNMP packet]

daemon@ATHENA.MIT.EDU (Jon A. Rochlis)
Mon Feb 12 20:15:18 1990

From: jon@MIT.EDU (Jon A. Rochlis)
To: krbdev@MIT.EDU
Cc: jis@MIT.EDU
Date: Mon, 12 Feb 90 20:14:28 EST

This is cute ... it might be useful for ASN.1 stuff, but seems like an
awful hack.

------- Forwarded Message

Received: by E40-PO.MIT.EDU (5.45/4.7) id AA24238; Mon, 12 Feb 90 19:35:27 EST
Received: from NISC.NYSER.NET by MIT.EDU with SMTP
	id AA22504; Mon, 12 Feb 90 19:35:08 EST
Received: by nisc.nyser.net (5.61/2.1-NYSERNet NISC)
	id AA14646; Mon, 12 Feb 90 19:16:05 -0500
Received: by nisc.nyser.net (5.61/2.1-NYSERNet NISC)
	id AA14636; Mon, 12 Feb 90 19:15:49 -0500
Received: from p.lanl.gov by nisc.nyser.net (5.61/2.1-NYSERNet NISC)
	id AA14632; Mon, 12 Feb 90 19:15:44 -0500
Received: by p.lanl.gov (5.54/1.14)
	id AA29102; Mon, 12 Feb 90 17:17:28 MST
Received: from sneezy.lanl.gov by snow-white.lanl.gov (4.1/SMI-4.0)
	id AA12561; Mon, 12 Feb 90 17:17:17 MST
Date: Mon, 12 Feb 90 17:17:17 MST
From: cpw%snow-white@LANL.GOV (C. Philip Wood)
Message-Id: <9002130017.AA12561@snow-white.lanl.gov>
To: JIAN@KUHUB.CC.UKANS.EDU
Subject: Re:  Looking for the map of SNMP packet
Cc: snmp@NISC.NYSER.NET

Jian,

This is probably not what you wanted to see, but it was fun? and maybe
you can use it.  It's an example and the required "code":

	1. A hex dump of an snmp packet
	2. An interpretation of the data portion
	3. The awk script used to create the interpretation	
	4. Changes to awk which provide xtoi and xtoa primitives.

Phil

HEX DUMP
                                            icmp type
 lnth proto         source     destination   src port   dst port
  453  udp sneezy.lanl.gov snow-white.lanl       1317       snmp
 08 00 20 00 d6 7a 08 00 20 00 cd 0c 08 00 45 00
 01 b7 d3 f8 00 00 1e 11 ad ee 80 a5 8c 03 80 a5
 8c 01 05 25 00 a1 01 a3 00 00 30 82 01 97 02 01
 00 04 04 6c 61 6e 6c a0 82 01 8a 02 04 25 d7 4f
 c1 02 01 00 02 01 00 30 82 01 7a 30 0c 06 08 2b
 06 01 02 01 01 03 00 05 00 30 0c 06 08 2b 06 01
 02 01 05 01 00 05 00 30 0c 06 08 2b 06 01 02 01
 05 02 00 05 00 30 0c 06 08 2b 06 01 02 01 05 03
 00 05 00 30 0c 06 08 2b 06 01 02 01 05 04 00 05
 00 30 0c 06 08 2b 06 01 02 01 05 05 00 05 00 30
 0c 06 08 2b 06 01 02 01 05 06 00 05 00 30 0c 06
 08 2b 06 01 02 01 05 07 00 05 00 30 0c 06 08 2b
 06 01 02 01 05 08 00 05 00 30 0c 06 08 2b 06 01
 02 01 05 09 00 05 00 30 0c 06 08 2b 06 01 02 01
 05 0a 00 05 00 30 0c 06 08 2b 06 01 02 01 05 0b
 00 05 00 30 0c 06 08 2b 06 01 02 01 05 0c 00 05
 00 30 0c 06 08 2b 06 01 02 01 05 0d 00 05 00 30
 0c 06 08 2b 06 01 02 01 05 0e 00 05 00 30 0c 06
 08 2b 06 01 02 01 05 0f 00 05 00 30 0c 06 08 2b
 06 01 02 01 05 10 00 05 00 30 0c 06 08 2b 06 01
 02 01 05 11 00 05 00 30 0c 06 08 2b 06 01 02 01
 05 12 00 05 00 30 0c 06 08 2b 06 01 02 01 05 13
 00 05 00 30 0c 06 08 2b 06 01 02 01 05 14 00 05
 00 30 0c 06 08 2b 06 01 02 01 05 15 00 05 00 30
 0c 06 08 2b 06 01 02 01 05 16 00 05 00 30 0c 06
 08 2b 06 01 02 01 05 17 00 05 00 30 0c 06 08 2b
 06 01 02 01 05 18 00 05 00 30 0c 06 08 2b 06 01
 02 01 05 19 00 05 00 30 0c 06 08 2b 06 01 02 01
 05 1a 00 05 00

THE INTERPRETATION

Sequence(407)
  Integer  : 0
  String   : lanl
  Get-Request(394)
    Integer  : 634867648
    Integer  : 0
    Integer  : 0
    Sequence(378)
      Sequence(12)
        Object   : 2b06010201010300
        Null     : 
      Sequence(12)
        Object   : 2b06010201050100
        Null     : 
      Sequence(12)
        Object   : 2b06010201050200
        Null     : 
      Sequence(12)
        Object   : 2b06010201050300
        Null     : 
      Sequence(12)
        Object   : 2b06010201050400
        Null     : 
      Sequence(12)
        Object   : 2b06010201050500
        Null     : 
      Sequence(12)
        Object   : 2b06010201050600
        Null     : 
      Sequence(12)
        Object   : 2b06010201050700
        Null     : 
      Sequence(12)
        Object   : 2b06010201050800
        Null     : 
      Sequence(12)
        Object   : 2b06010201050900
        Null     : 
      Sequence(12)
        Object   : 2b06010201050a00
        Null     : 
      Sequence(12)
        Object   : 2b06010201050b00
        Null     : 
      Sequence(12)
        Object   : 2b06010201050c00
        Null     : 
      Sequence(12)
        Object   : 2b06010201050d00
        Null     : 
      Sequence(12)
        Object   : 2b06010201050e00
        Null     : 
      Sequence(12)
        Object   : 2b06010201050f00
        Null     : 
      Sequence(12)
        Object   : 2b06010201051000
        Null     : 
      Sequence(12)
        Object   : 2b06010201051100
        Null     : 
      Sequence(12)
        Object   : 2b06010201051200
        Null     : 
      Sequence(12)
        Object   : 2b06010201051300
        Null     : 
      Sequence(12)
        Object   : 2b06010201051400
        Null     : 
      Sequence(12)
        Object   : 2b06010201051500
        Null     : 
      Sequence(12)
        Object   : 2b06010201051600
        Null     : 
      Sequence(12)
        Object   : 2b06010201051700
        Null     : 
      Sequence(12)
        Object   : 2b06010201051800
        Null     : 
      Sequence(12)
        Object   : 2b06010201051900
        Null     : 
      Sequence(12)
        Object   : 2b06010201051a00
        Null     : 

THE AWK SCRIPT

#! /usr/lanl/inet/diag/awk -f

#			Los Alamos National Laboratory
#
#	Copyright, 1990.  The Regents of the University of California.
#	This software was produced under a U.S. Government contract
#	(W-7405-ENG-36) by Los Alamos National Laboratory, which is
#	operated by the	University of California for the U.S. Department
#	of Energy.  The U.S. Government is licensed to use, reproduce,
#	and distribute this software.  Permission is granted to the
#	public to copy and use this software without charge, provided
#	that this Notice and any statement of authorship are reproduced
#	on all copies.  Neither the Government nor the University makes
#	any warranty, express or implied, or assumes any liability or
#	responsibility for the use of this software.
#
#	@(#)snmp.awk.x	1.1 (LANL) 1/15/90
#

# Assumes you have passed it an asn buffer whose first member is
# an asn object.  It can easily get hosed.
# The format should be either a string of hex or the output of etherfind(SUN)

BEGIN	{
	UNIVERSAL = 0
	APPLICATION = 1
	CONTEXT = 2
	STRING = 4
	INTEGER = 2
	IPADDR = 0
	Class[UNIVERSAL] = "Universal"
	Class[APPLICATION] = "Application"
	Class[CONTEXT] = "Context"
	Class[3] = "Private"
	Form[0] = "Primitive"
	Form[1] = "Constructed"
	Universal[0] = "UNKNOWN  :"
	Universal[1] = "Boolean  :"
	Universal[2] = "Integer  :"
	Universal[3] = "Bitstring:"
	Universal[4] = "String   :"
	Universal[5] = "Null     :"
	Universal[6] = "Object   :"
	Universal[7] = "Objectdes:"
	Universal[16] = "Sequence"
	Universal[17] = "Set"
	Application[0] = "IpAddress:"
	Application[1] = "Counter  :"
	Application[2] = "Gauge    :"
	Application[3] = "TimeTicks:"
	Application[4] = "Opaque   :"
	Context[0] = "Get-Request"
	Context[1] = "Get-Next-Request"
	Context[2] = "Get-Response"
	Context[3] = "Set-Request"
	Context[4] = "Trap"
	tab[0] = ""
	tab[1] = "  "
	tab[2] = "    "
	tab[3] = "      "
	tab[4] = "        "
	tab[5] = "          "
	indent = 0
	asndata = ""
	}
	{
	if ( NF > 0 ) {
		if ( NF == 1 ) {
			asndata = $1
		} else {
			n = split($0,nchunks," ")
			for (i=1; i<=n ;i++) asndata = asndata""nchunks[i]
			next
		}
	}
	}
END	{
	ptr = 1
	nbytes = length(asndata)
	printf("\n")
	while ( nbytes > 0 ) {
		bight=xtoi(substr(asndata,ptr,2))
		nbytes -= 2
		ptr += 2
		id = bight % 32
		cf = int(bight / 32)
		form = cf % 2
		class = int(cf / 2)
		if ( id > 30 ) {
			tagfield = substr(asndata,ptr,6)
			hdr = 4 
			nbytes -=6
			ptr += 6
		} else {
			hdr = 1
			tagfield = ""
		}
		count = xtoi(substr(asndata,ptr,2))
		nbytes -= 2
		ptr += 2
		hdr += 1
		if (count > 128) {
			noct = count % 128
			i = noct * 2
			count = xtoi(substr(asndata,ptr,i))
			nbytes -= i
			ptr += i
			hdr += noct
		}
		kruft = count * 2
		if      (class == UNIVERSAL) Foo = Universal[id]
		else if (class == APPLICATION) Foo = Application[id]
		else if (class == CONTEXT) Foo = Context[id]
		else Foo = "Private"
		printf("%s%s", tab[indent],Foo)
		if (form == PRIMITIVE) {
			data = substr(asndata,ptr, kruft)
			ptr += kruft
			nbytes -= kruft
			if (class == UNIVERSAL) {
				if (id == STRING)
				  printf(" %s\n",xtoa(data))
				else if( id == INTEGER)
				  printf(" %d\n",xtoi(data))
				else
				  printf(" %s\n", data)
			} else if(class == APPLICATION) {
				if (id == IPADDR) {
				  ip = " "
                		  for ( i=1;i<6; i += 2 )
                       		    ip = ip xtoi(substr(data,i,2)) "."
                		  ip = ip xtoi(substr(data,i,2))
                		  printf("%s\n",ip)
				} else
				  printf(" %s\n", data)
			} else
				printf(" %s\n", data)
			j = indent;
			for (i=0;i<indent;i++) {
				Kruft[i] -= hdr + count
				if (Kruft[i] <= 0) j -= 1 
			}
			indent = j;
		} else {
			if (Kruft[indent] < 0)
				indent -= 1
			printf("(%d)\n", count)
			Kruft[indent] = count
			indent += 1
		}
	}
	}


THE CHANGES TO AWK (This is Sun 4.0 awk):

- ------- awk.g.y -------
*** /tmp/da2859	Mon Feb 12 17:02:45 1990
- --- awk.g.y	Mon Aug 15 10:57:24 1988
***************
*** 20,24 ****
  %left	AND
  %left	NOT
! %left	NUMBER VAR ARRAY FNCN SUBSTR LSUBSTR INDEX
  %left	GETLINE
  %nonassoc RELOP MATCHOP
- --- 20,24 ----
  %left	AND
  %left	NOT
! %left	NUMBER VAR ARRAY FNCN SUBSTR LSUBSTR INDEX XTOI XTOA
  %left	GETLINE
  %nonassoc RELOP MATCHOP
***************
*** 126,129 ****
- --- 126,133 ----
  	| INDEX '(' expr ',' expr ')'
  			{ PUTS("index(e,e)"); $$ = op2(INDEX, $3, $5); }
+ 	| XTOI '(' expr ')'
+ 			{ PUTS("xtoi(e)"); $$ = op1(XTOI, $3); }
+ 	| XTOA '(' expr ')'
+ 			{ PUTS("xtoa(e)"); $$ = op1(XTOA, $3); }
  	| '(' expr ')'			{PUTS("(expr)");  $$ = $2; }
  	| term '+' term			{ PUTS("t+t"); $$ = op2(ADD, $1, $3); }

- ------- run.c -------
*** /tmp/da2862	Mon Feb 12 17:02:47 1990
- --- run.c	Mon Aug 15 11:49:28 1988
***************
*** 8,11 ****
- --- 8,12 ----
  #include "awk.h"
  #include "stdio.h"
+ #include "ctype.h"
  #define RECSIZE BUFSIZ
  
***************
*** 299,302 ****
- --- 300,358 ----
  }
  
+ obj xtoa(a, nnn) node **a;
+ {
+ 	char *s, *p1, *p2;
+ 	obj x;
+ 	int m, khar, c;
+ 
+ 	x = execute(a[0]);
+ 	s = getsval(x.optr);
+ 	tempfree(x);
+ 
+ 	x = gettemp();
+ 	setsval(x.optr, s );
+ 	s = getsval(x.optr);
+         for (p1 = s,p2 = s,khar=0,m=0; (c = *p1&0xff) != '\0'; p1++) {
+ 		if (isalpha(c)) {
+ 			if (isupper(c)) c = 10 + c - 'A';
+ 			else c = 10 + c - 'a';
+ 		} else
+ 			c = c - '0';
+ 		khar = (khar * 16) + c;
+ 		if (m&1) {
+ 			*p2++ = khar;
+ 			khar = 0;
+ 		}
+ 		m++;
+ 	}
+ /* garbage in garbage out */
+ 	*p2++ = khar;
+ 	*p2 = '\0';
+ 	return(x);
+ }
+ 
+ obj xtoi(a, nnn) node **a;
+ {
+         obj x;
+         char *s1, *p1, *q;
+ 	int	c;
+ 	int	n = 0;
+  
+         x = execute(a[0]);
+         s1 = getsval(x.optr);
+         tempfree(x);
+ 
+         x = gettemp();
+         for (p1 = s1; (c = *p1&0xff) != '\0'; p1++) {
+ 		if (isalpha(c)) {
+ 			if (isupper(c)) c = 10 + c - 'A';
+ 			else c = 10 + c - 'a';
+ 		} else
+ 			c = c - '0';
+ 		n = ( n * 16 ) + c;
+         }
+         setfval(x.optr, (awkfloat) (n));
+         return(x);
+ }
  obj sindex(a, nnn) node **a;
  {

- ------- awk.lx.l -------
*** /tmp/da2865	Mon Feb 12 17:02:49 1990
- --- awk.lx.l	Mon Aug 15 10:57:39 1988
***************
*** 93,96 ****
- --- 93,98 ----
  <A>substr	RETURN(SUBSTR);
  <A>index	RETURN(INDEX);
+ <A>xtoi		RETURN(XTOI);
+ <A>xtoa		RETURN(XTOA);
  <A>in		RETURN(IN);
  <A>getline	RETURN(GETLINE);

- ------- proc.c -------
*** /tmp/da2868	Mon Feb 12 17:02:49 1990
- --- proc.c	Mon Jan 15 15:37:52 1990
***************
*** 1,5 ****
  #ifndef lint
  static char sccsid[] = "@(#)proc.c	4.3 8/11/83";
! static char SccsId[] = "@(#)proc.c	1.1 (LANL) 8/15/88";
  #endif
  
- --- 1,5 ----
  #ifndef lint
  static char sccsid[] = "@(#)proc.c	4.3 8/11/83";
! static char SccsId[] = "%W% (LANL) %G%";
  #endif
  
***************
*** 25,28 ****
- --- 25,30 ----
  	{ SUBSTR, "substr", "substr"},
  	{ INDEX, "sindex", "sindex"},
+ 	{ XTOI, "xtoi","xtoi"},
+ 	{ XTOA, "xtoa","xtoa"},
  	{ SPRINTF, "asprintf", "sprintf "},
  	{ ADD, "arith", " + "},



THE AWK SCRIPT:


------- End of Forwarded Message


home help back first fref pref prev next nref lref last post