File: decode_snmp.c

package info (click to toggle)
dsniff 2.4b1%2Bdebian-30
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,080 kB
  • sloc: ansic: 10,803; sh: 152; makefile: 127
file content (55 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * decode_snmp.c
 *
 * Simple Network Management Protocol.
 *
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_snmp.c,v 1.6 2001/03/15 08:33:02 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "buf.h"
#include "asn1.h"
#include "decode.h"

int
decode_snmp(u_char *buf, int len, u_char *obuf, int olen)
{
	struct buf *b, inbuf, outbuf;
	u_char *p, vers;
	int i;

	buf_init(&inbuf, buf, len);
	buf_init(&outbuf, obuf, olen);
	
	if (asn1_type(&inbuf) != ASN1_SEQUENCE)
		return (0);
	asn1_len(&inbuf);		/* XXX - skip sequence length */
	
	if (asn1_type(&inbuf) != ASN1_INTEGER)
		return (0);
	if (asn1_len(&inbuf) != 1)	/* XXX - check version length */
		return (0);
	buf_get(&inbuf, &vers, sizeof(vers));
	
	if (asn1_type(&inbuf) != ASN1_STRING)
		return (0);
	i = asn1_len(&inbuf);
	b = buf_tok(&inbuf, NULL, i);
	p = buf_strdup(b);
	
	buf_putf(&outbuf, "[version %d]\n%s\n", vers + 1, p);
	free(p);
	buf_end(&outbuf);
		
	return (buf_len(&outbuf));
}