1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | #include <sys/types.h> |
---|
27 | #include <sys/socket.h> |
---|
28 | #include <netinet/in.h> |
---|
29 | #include <stdio.h> |
---|
30 | #include <arpa/inet.h> |
---|
31 | #include "libpacketdump.h" |
---|
32 | |
---|
33 | /* Decoder for an LSA header */ |
---|
34 | |
---|
35 | DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) { |
---|
36 | |
---|
37 | libtrace_ospf_lsa_v2_t *lsa = (libtrace_ospf_lsa_v2_t *)packet; |
---|
38 | |
---|
39 | if (len < 2) |
---|
40 | return; |
---|
41 | printf(" OSPF LSA: Age %u ", ntohs(lsa->age)); |
---|
42 | |
---|
43 | if (len < 3) |
---|
44 | return; |
---|
45 | printf("Options "); |
---|
46 | |
---|
47 | if (lsa->lsa_options.e_bit) |
---|
48 | printf("E "); |
---|
49 | if (lsa->lsa_options.mc_bit) |
---|
50 | printf("MC "); |
---|
51 | if (lsa->lsa_options.np_bit) |
---|
52 | printf("N/P "); |
---|
53 | if (lsa->lsa_options.ea_bit) |
---|
54 | printf("EA "); |
---|
55 | if (lsa->lsa_options.dc_bit) |
---|
56 | printf("DC "); |
---|
57 | printf("\n"); |
---|
58 | |
---|
59 | if (len < 4) |
---|
60 | return; |
---|
61 | printf(" OSPF LSA: LS Type %u ", lsa->lsa_type); |
---|
62 | switch(lsa->lsa_type) { |
---|
63 | case 1: |
---|
64 | printf("(Router LSA)\n"); |
---|
65 | break; |
---|
66 | case 2: |
---|
67 | printf("(Network LSA)\n"); |
---|
68 | break; |
---|
69 | case 3: |
---|
70 | printf("(Summary LSA - IP)\n"); |
---|
71 | break; |
---|
72 | case 4: |
---|
73 | printf("(Summary LSA - ASBR)\n"); |
---|
74 | break; |
---|
75 | case 5: |
---|
76 | printf("(AS External LSA)\n"); |
---|
77 | break; |
---|
78 | default: |
---|
79 | printf("(Unknown)\n"); |
---|
80 | } |
---|
81 | |
---|
82 | if (len < 8) |
---|
83 | return; |
---|
84 | |
---|
85 | printf(" OSPF LSA: Link State ID %s ", inet_ntoa(lsa->ls_id)); |
---|
86 | |
---|
87 | if (len < 12) { |
---|
88 | printf("\n"); |
---|
89 | return; |
---|
90 | } |
---|
91 | |
---|
92 | printf("Advertising Router %s\n", inet_ntoa(lsa->adv_router)); |
---|
93 | |
---|
94 | if (len < 16) |
---|
95 | return; |
---|
96 | |
---|
97 | printf(" OSPF LSA: Seq %u ", ntohl(lsa->seq)); |
---|
98 | |
---|
99 | if (len < 18) { |
---|
100 | printf("\n"); |
---|
101 | return; |
---|
102 | } |
---|
103 | |
---|
104 | printf("Checksum %u ", ntohs(lsa->checksum)); |
---|
105 | |
---|
106 | if (len < 20) { |
---|
107 | printf("\n"); |
---|
108 | return; |
---|
109 | } |
---|
110 | |
---|
111 | printf("Length %u \n", ntohs(lsa->length)); |
---|
112 | } |
---|