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_vrrp.c
Go to the documentation of this file.
1 /*
2  * decode_vrrp.c
3  *
4  * Virtual Router Redundancy Protocol.
5  *
6  * Copyright (c) 2000 Eric Jackson <ericj@monkey.org>
7  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
8  *
9  * $Id: decode_vrrp.c,v 1.5 2001/03/15 08:33:03 dugsong Exp $
10  */
11 
12 #include "config.h"
13 
14 #include <sys/types.h>
15 
16 #include <stdio.h>
17 #include <string.h>
18 
19 #include "buf.h"
20 #include "decode.h"
21 
22 struct vrrp_header {
23  u_char vr_vers; /* Version */
24  u_char vr_vrid; /* Virtual Router ID */
25  u_char vr_prio; /* Router Priority */
26  u_char vr_naddr; /* # of addresses */
27  u_char vr_auth; /* Type of Authentication */
28  u_char vr_advr; /* ADVERTISEMENT Interval */
29  u_short vr_cksum; /* Checksum */
30  /* vr_naddr * 4 # of addresses */
31 };
32 #define VRRP_AUTH_NONE 0
33 #define VRRP_AUTH_SIMPLE 1
34 #define VRRP_AUTH_AH 2
35 
36 #define VRRP_AUTH_DATA_LEN 8
37 
38 int
39 decode_vrrp(u_char *buf, int len, u_char *obuf, int olen)
40 {
41  struct buf *b, inbuf, outbuf;
42  struct vrrp_header *vrrp;
43 
44  buf_init(&inbuf, buf, len);
45  buf_init(&outbuf, obuf, olen);
46 
47  vrrp = (struct vrrp_header *)buf_ptr(&inbuf);
48 
49  if (buf_len(&inbuf) < sizeof(*vrrp))
50  return (0);
51 
52  /* We only care about VRRP_AUTH_SIMPLE */
53  if (ntohs(vrrp->vr_auth) != VRRP_AUTH_SIMPLE)
54  return (0);
55 
56  /* XXX - probably want to verify checksum */
57 
58  /* Forward to Authentication Data */
59  buf_skip(&inbuf, sizeof(*vrrp) + 8 + (vrrp->vr_naddr * 4));
60 
61  if ((b = buf_tok(&inbuf, NULL, VRRP_AUTH_DATA_LEN)) == NULL)
62  return (0);
63 
64  buf_put(&outbuf, buf_ptr(b), buf_len(b));
65  buf_put(&outbuf, "\n", 1);
66  buf_end(&outbuf);
67 
68  return (buf_len(&outbuf));
69 }
vrrp_header::vr_vers
u_char vr_vers
Definition: decode_vrrp.c:23
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
buf_put
int buf_put(buf_t buf, void *src, int len)
Definition: buf.c:93
decode_vrrp
int decode_vrrp(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_vrrp.c:39
decode.h
buf.h
vrrp_header::vr_prio
u_char vr_prio
Definition: decode_vrrp.c:25
buf
Definition: buf.h:14
vrrp_header::vr_cksum
u_short vr_cksum
Definition: decode_vrrp.c:29
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
buf_ptr
#define buf_ptr(b)
Definition: buf.h:31
vrrp_header::vr_vrid
u_char vr_vrid
Definition: decode_vrrp.c:24
vrrp_header::vr_auth
u_char vr_auth
Definition: decode_vrrp.c:27
VRRP_AUTH_DATA_LEN
#define VRRP_AUTH_DATA_LEN
Definition: decode_vrrp.c:36
vrrp_header
Definition: decode_vrrp.c:22
vrrp_header::vr_naddr
u_char vr_naddr
Definition: decode_vrrp.c:26
buf_skip
#define buf_skip(b, l)
Definition: buf.h:47
config.h
VRRP_AUTH_SIMPLE
#define VRRP_AUTH_SIMPLE
Definition: decode_vrrp.c:33
obuf
static char obuf[4096]
Definition: trigger.c:43
vrrp_header::vr_advr
u_char vr_advr
Definition: decode_vrrp.c:28
buf_len
#define buf_len(b)
Definition: buf.h:34