dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

decode_snmp.c
Go to the documentation of this file.
1 /*
2  * decode_snmp.c
3  *
4  * Simple Network Management Protocol.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_snmp.c,v 1.6 2001/03/15 08:33:02 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include "buf.h"
20 #include "asn1.h"
21 #include "decode.h"
22 
23 int
24 decode_snmp(u_char *buf, int len, u_char *obuf, int olen)
25 {
26  struct buf *b, inbuf, outbuf;
27  u_char *p, vers;
28  int i;
29 
30  buf_init(&inbuf, buf, len);
31  buf_init(&outbuf, obuf, olen);
32 
33  if (asn1_type(&inbuf) != ASN1_SEQUENCE)
34  return (0);
35  asn1_len(&inbuf); /* XXX - skip sequence length */
36 
37  if (asn1_type(&inbuf) != ASN1_INTEGER)
38  return (0);
39  if (asn1_len(&inbuf) != 1) /* XXX - check version length */
40  return (0);
41  buf_get(&inbuf, &vers, sizeof(vers));
42 
43  if (asn1_type(&inbuf) != ASN1_STRING)
44  return (0);
45  i = asn1_len(&inbuf);
46  b = buf_tok(&inbuf, NULL, i);
47  p = buf_strdup(b);
48 
49  buf_putf(&outbuf, "[version %d]\n%s\n", vers + 1, p);
50  free(p);
51  buf_end(&outbuf);
52 
53  return (buf_len(&outbuf));
54 }
55 
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
ASN1_STRING
#define ASN1_STRING
Definition: asn1.h:15
decode_snmp
int decode_snmp(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_snmp.c:24
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
decode.h
buf.h
buf_strdup
char * buf_strdup(buf_t buf)
Definition: buf.c:235
ASN1_INTEGER
#define ASN1_INTEGER
Definition: asn1.h:14
asn1_len
int asn1_len(buf_t buf)
Definition: asn1.c:31
buf
Definition: buf.h:14
buf_get
int buf_get(buf_t buf, void *dst, int len)
Definition: buf.c:74
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
asn1_type
int asn1_type(buf_t buf)
Definition: asn1.c:20
ASN1_SEQUENCE
#define ASN1_SEQUENCE
Definition: asn1.h:16
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
buf_len
#define buf_len(b)
Definition: buf.h:34
asn1.h