File: ospf2_1.c

package info (click to toggle)
libtrace3 3.0.14-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,492 kB
  • sloc: ansic: 21,584; sh: 10,236; cpp: 1,765; makefile: 454; yacc: 96; lex: 50
file content (74 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <arpa/inet.h>
#include "libpacketdump.h"


DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) {

	libtrace_ospf_hello_v2_t *hello = (libtrace_ospf_hello_v2_t *)packet;
	struct in_addr *neigh;

	if (len < 4) 
		return;
	printf(" OSPF Hello: Network Mask %s\n", inet_ntoa(hello->mask));
	if (len < 6)
		return;

	printf(" OSPF Hello: Interval %u ", ntohs(hello->interval));

	if (len < 7) {
		printf("\n");
		return;
	}

	printf("Options ");

	if (hello->hello_options.e_bit)
		printf("E ");
	if (hello->hello_options.mc_bit)
		printf("MC ");
	if (hello->hello_options.np_bit)
		printf("N/P ");
	if (hello->hello_options.ea_bit)
		printf("EA ");
	if (hello->hello_options.dc_bit)
		printf("DC ");
	printf("\n");

	if (len < 8) 
		return;

	printf(" OSPF Hello: Priority %u ", hello->priority);
	
	if (len < 12) {
		printf("\n");
		return;
	}

	printf("Dead Interval %u\n", ntohl(hello->deadint));
	
	if (len < 16) 
		return;

	printf(" OSPF Hello: Designated Router %s\n", inet_ntoa(hello->designated));

	if (len < 20)
		return;

	printf(" OSPF Hello: Backup Designated Router %s\n", inet_ntoa(hello->backup));

	neigh = (struct in_addr *)(packet + sizeof(libtrace_ospf_hello_v2_t));
	len -= sizeof(libtrace_ospf_hello_v2_t);
	while (len >= 4) {
		printf(" OSPF Hello: Neighbour %s\n", inet_ntoa(*neigh));
		neigh++;
		len -= sizeof(struct in_addr);
	}



	return;
}