Squelch a number of "-Wall" errors by:
[obnox/wireshark/wip.git] / packet-ospf.c
1 /* packet-ospf.c
2  * Routines for OSPF packet disassembly
3  * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
4  *
5  * $Id: packet-ospf.c,v 1.6 1998/10/13 07:03:34 guy Exp $
6  *
7  * At this time, this module is able to analyze OSPF
8  * packets as specified in RFC2328. MOSPF (RFC1584) and other
9  * OSPF Extensions which introduce new Packet types
10  * (e.g the External Atributes LSA) are not supported.
11  *
12  * TOS - support is not fully implemented
13  * 
14  * Ethereal - Network traffic analyzer
15  * By Gerald Combs <gerald@zing.org>
16  * Copyright 1998 Gerald Combs
17  * 
18  * 
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  * 
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  * 
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  */
33  
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <gtk/gtk.h>
39
40 #include <stdio.h>
41 #include <string.h>
42
43 #ifdef HAVE_SYS_TYPES_H
44 # include <sys/types.h>
45 #endif
46
47 #ifdef HAVE_NETINET_IN_H
48 # include <netinet/in.h>
49 #endif
50
51 #include "ethereal.h"
52 #include "packet.h"
53 #include "packet-ospf.h"
54
55
56 void 
57 dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
58     e_ospfhdr ospfh;
59
60     GtkWidget *ospf_tree = NULL, *ti; 
61     GtkWidget *ospf_header_tree;
62     char auth_data[9]="";
63     char *packet_type;
64
65     memcpy(&ospfh, &pd[offset], sizeof(e_ospfhdr));
66
67     switch(ospfh.packet_type) {
68         case OSPF_HELLO:
69             packet_type="Hello Packet";
70             break;
71         case OSPF_DB_DESC:
72             packet_type="DB Descr.";
73             break;
74         case OSPF_LS_REQ:
75             packet_type="LS Request";
76             break;
77         case OSPF_LS_UPD:
78             packet_type="LS Update";
79             break;
80         case OSPF_LS_ACK:
81             packet_type="LS Acknowledge";
82             break;
83        default:
84             /* XXX - set it to some string with the value of
85                "ospfh.packet_type"? */
86             break;
87     }
88     if (fd->win_info[COL_NUM]) {
89         strcpy(fd->win_info[COL_PROTOCOL], "OSPF");
90         sprintf(fd->win_info[COL_INFO], "%s", packet_type); 
91     }  
92
93     if (tree) {
94         ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(ospfh.length), "Open Shortest Path First"); 
95         ospf_tree = gtk_tree_new(); 
96         add_subtree(ti, ospf_tree, ETT_OSPF);
97
98         ti = add_item_to_tree(GTK_WIDGET(ospf_tree), offset, OSPF_HEADER_LENGTH, "OSPF Header"); 
99         ospf_header_tree = gtk_tree_new();
100         add_subtree(ti, ospf_header_tree, ETT_OSPF_HDR);
101
102         add_item_to_tree(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh.version);  
103         add_item_to_tree(ospf_header_tree, offset + 1 , 1, "OSPF Packet Type: %d (%s)", 
104                                                            ospfh.packet_type, packet_type);
105         add_item_to_tree(ospf_header_tree, offset + 2 , 2, "Packet Legth: %d", 
106                                                            ntohs(ospfh.length));
107         add_item_to_tree(ospf_header_tree, offset + 4 , 4, "Source OSPF Router ID: %s", 
108
109                                                            ip_to_str((guint8 *) &(ospfh.routerid)));
110         if (!(ospfh.area)) {
111            add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: Backbone");
112         } else {
113            add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: %s", ip_to_str((guint8 *) &(ospfh.area)));
114         }
115         add_item_to_tree(ospf_header_tree, offset + 12 , 2, "Packet Checksum");
116         switch( ntohs(ospfh.auth_type) ) {
117             case OSPF_AUTH_NONE:
118                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: none");
119                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (none)");
120                  break;
121             case OSPF_AUTH_SIMPLE:
122                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: simple");
123                  strncpy(auth_data, (char *) &ospfh.auth_data, 8);
124                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data: %s", auth_data);
125                  break;
126             case OSPF_AUTH_CRYPT:
127                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: crypt");
128                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (crypt)");
129                  break;
130             default:
131                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type (unknown)");
132                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (unknown)");
133         }
134
135     }
136
137     /*  Skip over header */
138     offset += OSPF_HEADER_LENGTH;
139     switch(ospfh.packet_type){
140         case OSPF_HELLO:
141             dissect_ospf_hello(pd, offset, fd, (GtkTree *) ospf_tree); 
142             break;
143         case OSPF_DB_DESC:
144             dissect_ospf_db_desc(pd, offset, fd, (GtkTree *) ospf_tree);   
145             break;
146         case OSPF_LS_REQ:
147             dissect_ospf_ls_req(pd, offset, fd, (GtkTree *) ospf_tree);   
148             break;
149         case OSPF_LS_UPD:
150             dissect_ospf_ls_upd(pd, offset, fd, (GtkTree *) ospf_tree);
151             break;
152         case OSPF_LS_ACK:
153             dissect_ospf_ls_ack(pd, offset, fd, (GtkTree *) ospf_tree);
154             break;
155         default:
156             dissect_data(pd, offset, fd, tree); 
157     }
158 }
159
160 void
161 dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
162     e_ospf_hello ospfhello;
163     guint32 *ospfneighbor;
164     char options[20]="";
165     int options_offset;
166
167     GtkWidget *ospf_hello_tree, *ti; 
168
169     memcpy(&ospfhello, &pd[offset], sizeof(e_ospf_hello));
170
171     if (tree) {
172         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF Hello Packet"); 
173         ospf_hello_tree = gtk_tree_new(); 
174         add_subtree(ti, ospf_hello_tree, ETT_OSPF_HELLO);
175
176
177         add_item_to_tree(ospf_hello_tree, offset , 4, "Network Mask: %s",  ip_to_str((guint8 *) &ospfhello.network_mask));
178         add_item_to_tree(ospf_hello_tree, offset + 4, 2, "Hello Intervall: %d seconds",  ntohs(ospfhello.hellointervall));
179
180         /* ATTENTION !!! no check for length of options string */
181         options_offset=0;
182         if(( ospfhello.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
183             strcpy( (char *)(options + options_offset), "E");
184             options_offset+=1;
185         }
186         if(( ospfhello.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
187             strcpy((char *) (options + options_offset), "/MC");
188             options_offset+=3;
189         }
190         if(( ospfhello.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
191             strcpy((char *) (options + options_offset), "/NP");
192             options_offset+=3;
193         }
194         if(( ospfhello.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
195             strcpy((char *) (options + options_offset) , "/EA");
196             options_offset+=3;
197         }
198         if(( ospfhello.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
199             strcpy((char *) (options + options_offset) , "/DC");
200             options_offset+=3;
201         }
202
203         add_item_to_tree(ospf_hello_tree, offset + 6, 1, "Options: %d (%s)",  ospfhello.options, options);
204         add_item_to_tree(ospf_hello_tree, offset + 7, 1, "Router Priority: %d",  ospfhello.priority);
205         add_item_to_tree(ospf_hello_tree, offset + 8, 4, "RouterDeadIntervall: %ld seconds",  (long)ntohl(ospfhello.dead_interval));
206         add_item_to_tree(ospf_hello_tree, offset + 12, 4, "Designated Router: %s",  ip_to_str((guint8 *) &ospfhello.drouter));
207         add_item_to_tree(ospf_hello_tree, offset + 16, 4, "Backup Designated Router: %s",  ip_to_str((guint8 *) &ospfhello.bdrouter));
208
209
210         offset+=20;
211         while(((int)(fd->cap_len - offset)) >= 4){
212             printf("%d", fd->cap_len - offset);
213             ospfneighbor=(guint32 *) &pd[offset];
214             add_item_to_tree(ospf_hello_tree, offset, 4, "Active Neighbor: %s",  ip_to_str((guint8 *) ospfneighbor));
215             offset+=4;
216         }
217     }
218 }
219
220 void
221 dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
222     e_ospf_dbd ospf_dbd;
223     char options[20]="";
224     int options_offset;
225     char flags[20]="";
226     int flags_offset;
227
228     GtkWidget *ospf_db_desc_tree=NULL, *ti; 
229
230     memcpy(&ospf_dbd, &pd[offset], sizeof(e_ospf_dbd));
231
232     if (tree) {
233         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF DB Description"); 
234         ospf_db_desc_tree = gtk_tree_new(); 
235         add_subtree(ti, ospf_db_desc_tree, ETT_OSPF_DESC);
236
237         add_item_to_tree(ospf_db_desc_tree, offset, 2, "Interface MTU: %d", ntohs(ospf_dbd.interface_mtu) );
238
239
240         options_offset=0;
241         if(( ospf_dbd.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
242             strcpy( (char *)(options + options_offset), "_E_");
243             options_offset+=1;
244         }
245         if(( ospf_dbd.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
246             strcpy((char *) (options + options_offset), "_MC_");
247             options_offset+=3;
248         }
249         if(( ospf_dbd.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
250             strcpy((char *) (options + options_offset), "_NP_");
251             options_offset+=3;
252         }
253         if(( ospf_dbd.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
254             strcpy((char *) (options + options_offset) , "_EA_");
255             options_offset+=3;
256         }
257         if(( ospf_dbd.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
258             strcpy((char *) (options + options_offset) , "_DC_");
259             options_offset+=3;
260         }
261
262         add_item_to_tree(ospf_db_desc_tree, offset + 2 , 1, "Options: %d (%s)", ospf_dbd.options, options );
263
264
265         flags_offset=0;
266         if(( ospf_dbd.flags & OSPF_DBD_FLAG_MS ) == OSPF_DBD_FLAG_MS){
267             strcpy( (char *)(flags + flags_offset), "_I_");
268             flags_offset+=1;
269         }
270         if(( ospf_dbd.flags & OSPF_DBD_FLAG_M ) == OSPF_DBD_FLAG_M){
271             strcpy((char *) (flags + flags_offset), "_M_");
272             flags_offset+=3;
273         }
274         if(( ospf_dbd.flags & OSPF_DBD_FLAG_I ) == OSPF_DBD_FLAG_I){
275             strcpy((char *) (flags + flags_offset), "_I_");
276             flags_offset+=3;
277         }
278
279         add_item_to_tree(ospf_db_desc_tree, offset + 3 , 1, "Flags: %d (%s)", ospf_dbd.flags, flags );
280         add_item_to_tree(ospf_db_desc_tree, offset + 4 , 4, "DD Sequence: %ld", (long)ntohl(ospf_dbd.dd_sequence) );
281     }
282     /* LS Headers will be processed here */
283     /* skip to the end of DB-Desc header */
284     offset+=8;
285     while( ((int) (fd->cap_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
286        dissect_ospf_lsa(pd, offset, fd, (GtkTree *) tree, FALSE);
287        offset+=OSPF_LSA_HEADER_LENGTH;
288     }
289 }
290
291 void
292 dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
293     e_ospf_ls_req ospf_lsr;
294
295     GtkWidget *ospf_lsr_tree, *ti; 
296
297
298     /* zero or more LS requests may be within a LS Request */
299     /* we place every request for a LSA in a single subtree */
300     if (tree) {
301         while( ((int) ( fd->cap_len - offset)) >= OSPF_LS_REQ_LENGTH ){
302              memcpy(&ospf_lsr, &pd[offset], sizeof(e_ospf_ls_req));
303              ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LS_REQ_LENGTH, "Link State Request"); 
304              ospf_lsr_tree = gtk_tree_new(); 
305              add_subtree(ti, ospf_lsr_tree, ETT_OSPF_LSR);
306
307              switch( ntohl( ospf_lsr.ls_type ) ){
308                  case OSPF_LSTYPE_ROUTER:
309                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Router-LSA (%ld)", 
310                                        (long)ntohl( ospf_lsr.ls_type ) );
311                      break;
312                  case OSPF_LSTYPE_NETWORK:
313                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Network-LSA (%ld)", 
314                                        (long)ntohl( ospf_lsr.ls_type ) );
315                      break;
316                  case OSPF_LSTYPE_SUMMERY:
317                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (IP network) (%ld)", 
318                                        (long)ntohl( ospf_lsr.ls_type ) );
319                      break;
320                  case OSPF_LSTYPE_ASBR:
321                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (ASBR) (%ld)", 
322                                        (long)ntohl( ospf_lsr.ls_type ) );
323                      break;
324                  case OSPF_LSTYPE_ASEXT:
325                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: AS-External-LSA (ASBR) (%ld)", 
326                                        (long)ntohl( ospf_lsr.ls_type ) );
327                      break;
328                  default:
329                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: %ld (unknown)", 
330                                        (long)ntohl( ospf_lsr.ls_type ) );
331              }
332
333              add_item_to_tree(ospf_lsr_tree, offset + 4, 4, "Link State ID : %s", 
334                                          ip_to_str((guint8 *) &(ospf_lsr.ls_id)));
335              add_item_to_tree(ospf_lsr_tree, offset + 8, 4, "Advertising Router : %s", 
336                                          ip_to_str((guint8 *) &(ospf_lsr.adv_router)));
337
338              offset+=12;
339         }
340     }
341 }
342 void
343 dissect_ospf_ls_upd(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
344     e_ospf_lsa_upd_hdr upd_hdr;
345     guint32 lsa_counter; 
346
347     GtkWidget *ospf_lsa_upd_tree=NULL, *ti; 
348
349     memcpy(&upd_hdr, &pd[offset], sizeof(e_ospf_lsa_upd_hdr));
350
351     if (tree) {
352         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "LS Update Packet"); 
353         ospf_lsa_upd_tree = gtk_tree_new(); 
354         add_subtree(ti, ospf_lsa_upd_tree, ETT_OSPF_LSA_UPD);
355
356         add_item_to_tree(ospf_lsa_upd_tree, offset, 4, "Nr oF LSAs: %ld", (long)ntohl(upd_hdr.lsa_nr) );
357     }
358     /* skip to the beginning of the first LSA */
359     offset+=4; /* the LS Upd PAcket contains only a 32 bit #LSAs field */
360     
361     lsa_counter = 0;
362     while(lsa_counter < ntohl(upd_hdr.lsa_nr)){
363         offset+=dissect_ospf_lsa(pd, offset, fd, (GtkTree *) ospf_lsa_upd_tree, TRUE);
364         lsa_counter += 1;
365     }
366 }
367
368 void
369 dissect_ospf_ls_ack(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
370
371     /* the body of a LS Ack packet simply contains zero or more LSA Headers */
372     while( ((int)(fd->cap_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
373        dissect_ospf_lsa(pd, offset, fd, (GtkTree *) tree, FALSE);
374        offset+=OSPF_LSA_HEADER_LENGTH;
375     }
376
377 }
378
379 int
380 dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, int disassemble_body) {
381     e_ospf_lsa_hdr       lsa_hdr;
382     char                *lsa_type;
383
384     /* data strutures for the router LSA */
385     e_ospf_router_lsa           router_lsa;
386     e_ospf_router_data          router_data;
387     e_ospf_router_metric        tos_data;
388     guint16                     link_counter;
389     guint8                      tos_counter;
390     char                        *link_type;
391     char                        *link_id;
392
393     /* data structures for the network lsa */
394     e_ospf_network_lsa  network_lsa;
395     guint32             *attached_router;
396
397     /* data structures for the summary and ASBR LSAs */
398     e_ospf_summary_lsa  summary_lsa;
399
400     /* data structures for the AS-External LSA */
401     e_ospf_asexternal_lsa       asext_lsa;
402     guint32                   asext_metric;
403
404     GtkWidget *ospf_lsa_tree, *ti; 
405
406     memcpy(&lsa_hdr, &pd[offset], sizeof(e_ospf_lsa_hdr));
407
408              
409
410     switch(lsa_hdr.ls_type) {
411         case OSPF_LSTYPE_ROUTER:
412             lsa_type="Router LSA";
413             break;
414         case OSPF_LSTYPE_NETWORK:
415             lsa_type="Network LSA";
416             break;
417         case OSPF_LSTYPE_SUMMERY:
418             lsa_type="Summery LSA";
419             break;
420         case OSPF_LSTYPE_ASBR:
421             lsa_type="ASBR LSA";
422             break;
423         case OSPF_LSTYPE_ASEXT:
424             lsa_type="AS-external-LSA";
425             break;
426         default:
427             lsa_type="unknown";
428     }
429
430     if (tree) {
431         if(disassemble_body){
432              ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(lsa_hdr.length), 
433                                                       "%s (Type: %d)", lsa_type, lsa_hdr.ls_type); 
434         } else {
435              ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LSA_HEADER_LENGTH, "LSA Header"); 
436         }
437         ospf_lsa_tree = gtk_tree_new(); 
438         add_subtree(ti, ospf_lsa_tree, ETT_OSPF_LSA);
439
440         
441         add_item_to_tree(ospf_lsa_tree, offset, 2, "LS Age: %d seconds", ntohs(lsa_hdr.ls_age));
442         add_item_to_tree(ospf_lsa_tree, offset + 2, 1, "Options: %d ", lsa_hdr.options);
443         add_item_to_tree(ospf_lsa_tree, offset + 3, 1, "LSA Type: %d (%s)", lsa_hdr.ls_type, lsa_type);
444
445         add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Linke State ID: %s ", 
446                                                      ip_to_str((guint8 *) &(lsa_hdr.ls_id)));
447
448         add_item_to_tree(ospf_lsa_tree, offset + 8, 4, "Advertising Router: %s ", 
449                                                      ip_to_str((guint8 *) &(lsa_hdr.adv_router)));
450         add_item_to_tree(ospf_lsa_tree, offset + 12, 4, "LS Sequence Number: 0x%04lx ", 
451                                                      (unsigned long)ntohl(lsa_hdr.ls_seq));
452         add_item_to_tree(ospf_lsa_tree, offset + 16, 2, "LS Checksum: %d ", ntohs(lsa_hdr.ls_checksum));
453
454         add_item_to_tree(ospf_lsa_tree, offset + 18, 2, "Length: %d ", ntohs(lsa_hdr.length));
455
456         if(!disassemble_body){
457            return OSPF_LSA_HEADER_LENGTH;
458         }
459
460         /* the LSA body starts afte 20 bytes of LSA Header */
461         offset+=20;
462
463         switch(lsa_hdr.ls_type){
464             case(OSPF_LSTYPE_ROUTER):
465                 memcpy(&router_lsa, &pd[offset], sizeof(e_ospf_router_lsa));
466
467                 /* again: flags should be secified in detail */
468                 add_item_to_tree(ospf_lsa_tree, offset, 1, "Flags: 0x%02x ", router_lsa.flags);
469                 add_item_to_tree(ospf_lsa_tree, offset + 2, 2, "Nr. of Links: %d ", 
470                                                                    ntohs(router_lsa.nr_links));
471                 offset += 4;
472                 /* router_lsa.nr_links links follow 
473                  * maybe we should put each of the links into its own subtree ???
474                  */
475                 for(link_counter = 1 ; link_counter <= ntohs(router_lsa.nr_links); link_counter++){
476
477                     memcpy(&router_data, &pd[offset], sizeof(e_ospf_router_data));
478                     /* check the Link Type and ID */
479                     switch(router_data.link_type) {
480                         case OSPF_LINK_PTP:
481                             link_type="Point-to-point connection to another router";
482                             link_id="Neighboring router's Router ID";
483                             break;
484                         case OSPF_LINK_TRANSIT:
485                             link_type="Connection to a transit network";
486                             link_id="IP address of Designated Router";
487                             break;
488                         case OSPF_LINK_STUB:
489                             link_type="Connection to a stub network";
490                             link_id="IP network/subnet number";
491                             break;
492                         case OSPF_LINK_VIRTUAL:
493                             link_type="Virtual link";
494                             link_id="Neighboring router's Router ID";
495                             break;
496                         default:
497                             link_type="unknown link type";
498                             link_id="unknown link id";
499                     }
500
501                     add_item_to_tree(ospf_lsa_tree, offset, 4, "%s: %s", link_id,
502                                                    ip_to_str((guint8 *) &(router_data.link_id)));
503
504                     /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
505                     add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Link Data: %s", 
506                                                    ip_to_str((guint8 *) &(router_data.link_data)));
507
508                     add_item_to_tree(ospf_lsa_tree, offset + 8, 1, "Link Type: %d - %s", 
509                                                               router_data.link_type, link_type);
510                     add_item_to_tree(ospf_lsa_tree, offset + 9, 1, "Nr. of TOS metrics: %d", router_data.nr_tos);
511                     add_item_to_tree(ospf_lsa_tree, offset + 10, 2, "TOS 0 metric: %d", ntohs( router_data.tos0_metric ));
512
513                     offset += 12;
514
515                     /* router_data.nr_tos metrics may follow each link 
516                      * ATTENTION: TOS metrics are not tested (I don't have TOS based routing)
517                      * please send me a mail if it is/isn't working
518                      */
519
520                     for(tos_counter = 1 ; link_counter <= ntohs(router_data.nr_tos); tos_counter++){
521                         memcpy(&tos_data, &pd[offset], sizeof(e_ospf_router_metric));
522                         add_item_to_tree(ospf_lsa_tree, offset, 1, "TOS: %d, Metric: %d", 
523                                                 tos_data.tos, ntohs(tos_data.metric));
524                         offset += 4;
525                     }
526                 }
527                 break;
528             case(OSPF_LSTYPE_NETWORK):
529                 memcpy(&network_lsa, &pd[offset], sizeof(e_ospf_network_lsa));
530                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
531                                                  ip_to_str((guint8 *) &(network_lsa.network_mask)));
532                 offset += 4;
533
534                 while( ((int) (fd->cap_len - offset)) >= 4){
535                     attached_router = (guint32 *) &pd[offset];
536                     add_item_to_tree(ospf_lsa_tree, offset, 4, "Attached Router: %s", 
537                                                  ip_to_str((guint8 *) attached_router));
538                     offset += 4;
539                 }
540                 break;
541             case(OSPF_LSTYPE_SUMMERY):
542                 /* Type 3 and 4 LSAs have the same format */
543             case(OSPF_LSTYPE_ASBR):
544                 memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa));
545                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
546                                                  ip_to_str((guint8 *) &(summary_lsa.network_mask)));
547                 /* returns only the TOS 0 metric (even if there are more TOS metrics) */
548                 break;
549             case(OSPF_LSTYPE_ASEXT):
550                 memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa));
551                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
552                                                   ip_to_str((guint8 *) &(summary_lsa.network_mask)));
553
554                 /* asext_lsa = (e_ospf_asexternal_lsa *) &pd[offset + 4]; */
555                 memcpy(&asext_lsa, &pd[offset + 4], sizeof(asext_lsa));
556                 if( (asext_lsa.options & 128) == 128 ) { /* check wether or not E bit is set */
557                    add_item_to_tree(ospf_lsa_tree, offset, 1, 
558                             "External Type: Type 2 (metric is larger than any other link state path)");
559                 } else {
560                    add_item_to_tree(ospf_lsa_tree, offset + 4, 1, 
561                             "External Type: Type 1 (metric is specified in the same units as interface cost)");
562                 }
563                 /* the metric field of a AS-external LAS is specified in 3 bytes -> not well aligned */
564                 /* this routine returns only the TOS 0 metric (even if there are more TOS metrics) */
565                 memcpy(&asext_metric, &pd[offset+4], 4); 
566                 
567                 /* erase the leading 8 bits (the dont belong to the metric */
568                 asext_metric = ntohl(asext_metric) & 0x00ffffff ;
569
570                 add_item_to_tree(ospf_lsa_tree, offset + 5,  3,"Metric: %d", asext_metric);
571                 add_item_to_tree(ospf_lsa_tree, offset + 8,  4,"Forwarding Address: %s", 
572                                                  ip_to_str((guint8 *) &(asext_lsa.gateway)));
573                 add_item_to_tree(ospf_lsa_tree, offset + 12, 4,"External Route Tag: %ld", (long)ntohl(asext_lsa.external_tag)); 
574                     
575                 break;
576             default:
577                /* unknown LSA type */
578                 add_item_to_tree(ospf_lsa_tree, offset, (fd->cap_len - offset), "Unknown LSA Type");
579         }
580     }
581     /* return the length of this LSA */
582     return ntohs(lsa_hdr.length);
583 }