1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <stdio.h>
5 #include <arpa/inet.h>
6 #include "libpacketdump.h"
7 
8 
decode(int link_type UNUSED,const char * packet,unsigned len)9 DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) {
10 	libtrace_ospf_ls_update_t *update = (libtrace_ospf_ls_update_t *)packet;
11 	unsigned char *lsa_ptr;
12 	uint8_t lsa_type;
13 	libtrace_ospf_lsa_v2_t *lsa_hdr;
14 	unsigned char *lsa_body;
15 	int i = 0;
16 	int max_lsas = 0;
17 	uint32_t rem = len;
18 	uint16_t lsa_length;
19 
20 
21 	if (len < 4)
22 		return;
23 	max_lsas = ntohl(update->ls_num_adv);
24 	printf(" OSPF LS Update: LSAs %u\n", max_lsas);
25 
26 
27 	lsa_ptr = trace_get_first_ospf_lsa_from_update_v2(update, &rem);
28 
29 	if (lsa_ptr == NULL || rem == 0)
30 		return;
31 
32 	while (trace_get_next_ospf_lsa_v2(&lsa_ptr, &lsa_hdr, &lsa_body,
33 			&rem, &lsa_type, &lsa_length) > 0) {
34 
35 		i ++;
36 		if (lsa_hdr) {
37 
38 			decode_next((char *)lsa_hdr, lsa_length, "ospf2", 1000);
39 		}
40 
41 		if (lsa_body) {
42 			decode_next((char *)lsa_body, lsa_length -
43 					sizeof(libtrace_ospf_lsa_v2_t),
44 					"ospf2",
45 					1000 + lsa_type);
46 		}
47 
48 		if (i == max_lsas)
49 			break;
50 
51 
52 	}
53 }
54