diff options
Diffstat (limited to 'packet-ospf.c')
-rw-r--r-- | packet-ospf.c | 201 |
1 files changed, 101 insertions, 100 deletions
diff --git a/packet-ospf.c b/packet-ospf.c index 60675579b9..73469fd021 100644 --- a/packet-ospf.c +++ b/packet-ospf.c @@ -2,7 +2,7 @@ * Routines for OSPF packet disassembly * (c) Copyright Hannes R. Boehm <hannes@boehm.org> * - * $Id: packet-ospf.c,v 1.4 1998/09/29 21:34:44 hannes Exp $ + * $Id: packet-ospf.c,v 1.5 1998/10/10 03:32:13 gerald Exp $ * * At this time, this module is able to analyze OSPF * packets as specified in RFC2328. MOSPF (RFC1584) and other @@ -38,6 +38,7 @@ #include <gtk/gtk.h> #include <stdio.h> +#include <string.h> #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> @@ -54,16 +55,16 @@ void dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { - e_ospfhdr *ospfh; + e_ospfhdr ospfh; GtkWidget *ospf_tree = NULL, *ti; GtkWidget *ospf_header_tree; char auth_data[9]=""; char *packet_type; - ospfh = (e_ospfhdr *) &pd[offset]; + memcpy(&ospfh, &pd[offset], sizeof(e_ospfhdr)); - switch(ospfh->packet_type) { + switch(ospfh.packet_type) { case OSPF_HELLO: packet_type="Hello Packet"; break; @@ -81,7 +82,7 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { break; default: /* XXX - set it to some string with the value of - "ospfh->packet_type"? */ + "ospfh.packet_type"? */ break; } if (fd->win_info[COL_NUM]) { @@ -90,7 +91,7 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { } if (tree) { - ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(ospfh->length), "Open Shortest Path First"); + ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(ospfh.length), "Open Shortest Path First"); ospf_tree = gtk_tree_new(); add_subtree(ti, ospf_tree, ETT_OSPF); @@ -98,28 +99,28 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { ospf_header_tree = gtk_tree_new(); add_subtree(ti, ospf_header_tree, ETT_OSPF_HDR); - add_item_to_tree(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh->version); + add_item_to_tree(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh.version); add_item_to_tree(ospf_header_tree, offset + 1 , 1, "OSPF Packet Type: %d (%s)", - ospfh->packet_type, packet_type); + ospfh.packet_type, packet_type); add_item_to_tree(ospf_header_tree, offset + 2 , 2, "Packet Legth: %d", - ntohs(ospfh->length)); + ntohs(ospfh.length)); add_item_to_tree(ospf_header_tree, offset + 4 , 4, "Source OSPF Router ID: %s", - ip_to_str((guint8 *) &(ospfh->routerid))); - if (!(ospfh->area)) { + ip_to_str((guint8 *) &(ospfh.routerid))); + if (!(ospfh.area)) { add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: Backbone"); } else { - add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: %s", ip_to_str((guint8 *) &(ospfh->area))); + add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: %s", ip_to_str((guint8 *) &(ospfh.area))); } add_item_to_tree(ospf_header_tree, offset + 12 , 2, "Packet Checksum"); - switch( ntohs(ospfh->auth_type) ) { + switch( ntohs(ospfh.auth_type) ) { case OSPF_AUTH_NONE: add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: none"); add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (none)"); break; case OSPF_AUTH_SIMPLE: add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: simple"); - strncpy(auth_data, &(ospfh->auth_data), 8); + strncpy(auth_data, (char *) &ospfh.auth_data, 8); add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data: %s", auth_data); break; case OSPF_AUTH_CRYPT: @@ -135,7 +136,7 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { /* Skip over header */ offset += OSPF_HEADER_LENGTH; - switch(ospfh->packet_type){ + switch(ospfh.packet_type){ case OSPF_HELLO: dissect_ospf_hello(pd, offset, fd, (GtkTree *) ospf_tree); break; @@ -158,14 +159,14 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { void dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { - e_ospf_hello *ospfhello; + e_ospf_hello ospfhello; guint32 *ospfneighbor; char options[20]=""; int options_offset; GtkWidget *ospf_hello_tree, *ti; - ospfhello = (e_ospf_hello *) &pd[offset]; + memcpy(&ospfhello, &pd[offset], sizeof(e_ospf_hello)); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF Hello Packet"); @@ -173,37 +174,37 @@ dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) add_subtree(ti, ospf_hello_tree, ETT_OSPF_HELLO); - add_item_to_tree(ospf_hello_tree, offset , 4, "Network Mask: %s", ip_to_str((guint8 *) &ospfhello->network_mask)); - add_item_to_tree(ospf_hello_tree, offset + 4, 2, "Hello Intervall: %d seconds", ntohs(ospfhello->hellointervall)); + add_item_to_tree(ospf_hello_tree, offset , 4, "Network Mask: %s", ip_to_str((guint8 *) &ospfhello.network_mask)); + add_item_to_tree(ospf_hello_tree, offset + 4, 2, "Hello Intervall: %d seconds", ntohs(ospfhello.hellointervall)); /* ATTENTION !!! no check for length of options string */ options_offset=0; - if(( ospfhello->options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){ + if(( ospfhello.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){ strcpy( (char *)(options + options_offset), "E"); options_offset+=1; } - if(( ospfhello->options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){ + if(( ospfhello.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){ strcpy((char *) (options + options_offset), "/MC"); options_offset+=3; } - if(( ospfhello->options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){ + if(( ospfhello.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){ strcpy((char *) (options + options_offset), "/NP"); options_offset+=3; } - if(( ospfhello->options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){ + if(( ospfhello.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){ strcpy((char *) (options + options_offset) , "/EA"); options_offset+=3; } - if(( ospfhello->options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){ + if(( ospfhello.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){ strcpy((char *) (options + options_offset) , "/DC"); options_offset+=3; } - add_item_to_tree(ospf_hello_tree, offset + 6, 1, "Options: %d (%s)", ospfhello->options, options); - add_item_to_tree(ospf_hello_tree, offset + 7, 1, "Router Priority: %d", ospfhello->priority); - add_item_to_tree(ospf_hello_tree, offset + 8, 4, "RouterDeadIntervall: %ld seconds", (long)ntohl(ospfhello->dead_interval)); - add_item_to_tree(ospf_hello_tree, offset + 12, 4, "Designated Router: %s", ip_to_str((guint8 *) &ospfhello->drouter)); - add_item_to_tree(ospf_hello_tree, offset + 16, 4, "Backup Designated Router: %s", ip_to_str((guint8 *) &ospfhello->bdrouter)); + add_item_to_tree(ospf_hello_tree, offset + 6, 1, "Options: %d (%s)", ospfhello.options, options); + add_item_to_tree(ospf_hello_tree, offset + 7, 1, "Router Priority: %d", ospfhello.priority); + add_item_to_tree(ospf_hello_tree, offset + 8, 4, "RouterDeadIntervall: %ld seconds", (long)ntohl(ospfhello.dead_interval)); + add_item_to_tree(ospf_hello_tree, offset + 12, 4, "Designated Router: %s", ip_to_str((guint8 *) &ospfhello.drouter)); + add_item_to_tree(ospf_hello_tree, offset + 16, 4, "Backup Designated Router: %s", ip_to_str((guint8 *) &ospfhello.bdrouter)); offset+=20; @@ -218,7 +219,7 @@ dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) void dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { - e_ospf_dbd *ospf_dbd; + e_ospf_dbd ospf_dbd; char options[20]=""; int options_offset; char flags[20]=""; @@ -226,57 +227,57 @@ dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree GtkWidget *ospf_db_desc_tree=NULL, *ti; - ospf_dbd = (e_ospf_dbd *) &pd[offset]; + memcpy(&ospf_dbd, &pd[offset], sizeof(e_ospf_dbd)); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF DB Description"); ospf_db_desc_tree = gtk_tree_new(); add_subtree(ti, ospf_db_desc_tree, ETT_OSPF_DESC); - add_item_to_tree(ospf_db_desc_tree, offset, 2, "Interface MTU: %d", ntohs(ospf_dbd->interface_mtu) ); + add_item_to_tree(ospf_db_desc_tree, offset, 2, "Interface MTU: %d", ntohs(ospf_dbd.interface_mtu) ); options_offset=0; - if(( ospf_dbd->options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){ + if(( ospf_dbd.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){ strcpy( (char *)(options + options_offset), "_E_"); options_offset+=1; } - if(( ospf_dbd->options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){ + if(( ospf_dbd.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){ strcpy((char *) (options + options_offset), "_MC_"); options_offset+=3; } - if(( ospf_dbd->options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){ + if(( ospf_dbd.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){ strcpy((char *) (options + options_offset), "_NP_"); options_offset+=3; } - if(( ospf_dbd->options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){ + if(( ospf_dbd.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){ strcpy((char *) (options + options_offset) , "_EA_"); options_offset+=3; } - if(( ospf_dbd->options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){ + if(( ospf_dbd.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){ strcpy((char *) (options + options_offset) , "_DC_"); options_offset+=3; } - add_item_to_tree(ospf_db_desc_tree, offset + 2 , 1, "Options: %d (%s)", ospf_dbd->options, options ); + add_item_to_tree(ospf_db_desc_tree, offset + 2 , 1, "Options: %d (%s)", ospf_dbd.options, options ); flags_offset=0; - if(( ospf_dbd->flags & OSPF_DBD_FLAG_MS ) == OSPF_DBD_FLAG_MS){ + if(( ospf_dbd.flags & OSPF_DBD_FLAG_MS ) == OSPF_DBD_FLAG_MS){ strcpy( (char *)(flags + flags_offset), "_I_"); flags_offset+=1; } - if(( ospf_dbd->flags & OSPF_DBD_FLAG_M ) == OSPF_DBD_FLAG_M){ + if(( ospf_dbd.flags & OSPF_DBD_FLAG_M ) == OSPF_DBD_FLAG_M){ strcpy((char *) (flags + flags_offset), "_M_"); flags_offset+=3; } - if(( ospf_dbd->flags & OSPF_DBD_FLAG_I ) == OSPF_DBD_FLAG_I){ + if(( ospf_dbd.flags & OSPF_DBD_FLAG_I ) == OSPF_DBD_FLAG_I){ strcpy((char *) (flags + flags_offset), "_I_"); flags_offset+=3; } - add_item_to_tree(ospf_db_desc_tree, offset + 3 , 1, "Flags: %d (%s)", ospf_dbd->flags, flags ); - add_item_to_tree(ospf_db_desc_tree, offset + 4 , 4, "DD Sequence: %ld", (long)ntohl(ospf_dbd->dd_sequence) ); + add_item_to_tree(ospf_db_desc_tree, offset + 3 , 1, "Flags: %d (%s)", ospf_dbd.flags, flags ); + add_item_to_tree(ospf_db_desc_tree, offset + 4 , 4, "DD Sequence: %ld", (long)ntohl(ospf_dbd.dd_sequence) ); } /* LS Headers will be processed here */ /* skip to the end of DB-Desc header */ @@ -289,7 +290,7 @@ dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree void dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { - e_ospf_ls_req *ospf_lsr; + e_ospf_ls_req ospf_lsr; GtkWidget *ospf_lsr_tree, *ti; @@ -298,41 +299,41 @@ dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) /* we place every request for a LSA in a single subtree */ if (tree) { while( ((int) ( fd->cap_len - offset)) >= OSPF_LS_REQ_LENGTH ){ - ospf_lsr = (e_ospf_ls_req *) &pd[offset]; + memcpy(&ospf_lsr, &pd[offset], sizeof(e_ospf_ls_req)); ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LS_REQ_LENGTH, "Link State Request"); ospf_lsr_tree = gtk_tree_new(); add_subtree(ti, ospf_lsr_tree, ETT_OSPF_LSR); - switch( ntohl( ospf_lsr->ls_type ) ){ + switch( ntohl( ospf_lsr.ls_type ) ){ case OSPF_LSTYPE_ROUTER: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Router-LSA (%ld)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); break; case OSPF_LSTYPE_NETWORK: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Network-LSA (%ld)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); break; case OSPF_LSTYPE_SUMMERY: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (IP network) (%ld)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); break; case OSPF_LSTYPE_ASBR: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (ASBR) (%ld)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); break; case OSPF_LSTYPE_ASEXT: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: AS-External-LSA (ASBR) (%ld)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); break; default: add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: %ld (unknown)", - (long)ntohl( ospf_lsr->ls_type ) ); + (long)ntohl( ospf_lsr.ls_type ) ); } add_item_to_tree(ospf_lsr_tree, offset + 4, 4, "Link State ID : %s", - ip_to_str((guint8 *) &(ospf_lsr->ls_id))); + ip_to_str((guint8 *) &(ospf_lsr.ls_id))); add_item_to_tree(ospf_lsr_tree, offset + 8, 4, "Advertising Router : %s", - ip_to_str((guint8 *) &(ospf_lsr->adv_router))); + ip_to_str((guint8 *) &(ospf_lsr.adv_router))); offset+=12; } @@ -340,25 +341,25 @@ dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) } void dissect_ospf_ls_upd(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) { - e_ospf_lsa_upd_hdr *upd_hdr; + e_ospf_lsa_upd_hdr upd_hdr; guint32 lsa_counter; GtkWidget *ospf_lsa_upd_tree=NULL, *ti; - upd_hdr = (e_ospf_lsa_upd_hdr *) &pd[offset]; + memcpy(&upd_hdr, &pd[offset], sizeof(e_ospf_lsa_upd_hdr)); if (tree) { ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "LS Update Packet"); ospf_lsa_upd_tree = gtk_tree_new(); add_subtree(ti, ospf_lsa_upd_tree, ETT_OSPF_LSA_UPD); - add_item_to_tree(ospf_lsa_upd_tree, offset, 4, "Nr oF LSAs: %ld", (long)ntohl(upd_hdr->lsa_nr) ); + add_item_to_tree(ospf_lsa_upd_tree, offset, 4, "Nr oF LSAs: %ld", (long)ntohl(upd_hdr.lsa_nr) ); } /* skip to the beginning of the first LSA */ offset+=4; /* the LS Upd PAcket contains only a 32 bit #LSAs field */ lsa_counter = 0; - while(lsa_counter < ntohl(upd_hdr->lsa_nr)){ + while(lsa_counter < ntohl(upd_hdr.lsa_nr)){ offset+=dissect_ospf_lsa(pd, offset, fd, (GtkTree *) ospf_lsa_upd_tree, TRUE); lsa_counter += 1; } @@ -377,24 +378,24 @@ dissect_ospf_ls_ack(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) int dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, int disassemble_body) { - e_ospf_lsa_hdr *lsa_hdr; + e_ospf_lsa_hdr lsa_hdr; char *lsa_type; /* data strutures for the router LSA */ - e_ospf_router_lsa *router_lsa; - e_ospf_router_data *router_data; - e_ospf_router_metric *tos_data; + e_ospf_router_lsa router_lsa; + e_ospf_router_data router_data; + e_ospf_router_metric tos_data; guint16 link_counter; guint8 tos_counter; char *link_type; char *link_id; /* data structures for the network lsa */ - e_ospf_network_lsa *network_lsa; + e_ospf_network_lsa network_lsa; guint32 *attached_router; /* data structures for the summary and ASBR LSAs */ - e_ospf_summary_lsa *summary_lsa; + e_ospf_summary_lsa summary_lsa; /* data structures for the AS-External LSA */ e_ospf_asexternal_lsa asext_lsa; @@ -402,11 +403,11 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in GtkWidget *ospf_lsa_tree, *ti; - lsa_hdr = (e_ospf_lsa_hdr *) &pd[offset]; + memcpy(&lsa_hdr, &pd[offset], sizeof(e_ospf_lsa_hdr)); - switch(lsa_hdr->ls_type) { + switch(lsa_hdr.ls_type) { case OSPF_LSTYPE_ROUTER: lsa_type="Router LSA"; break; @@ -428,8 +429,8 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in if (tree) { if(disassemble_body){ - ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(lsa_hdr->length), - "%s (Type: %d)", lsa_type, lsa_hdr->ls_type); + ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(lsa_hdr.length), + "%s (Type: %d)", lsa_type, lsa_hdr.ls_type); } else { ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LSA_HEADER_LENGTH, "LSA Header"); } @@ -437,20 +438,20 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in add_subtree(ti, ospf_lsa_tree, ETT_OSPF_LSA); - add_item_to_tree(ospf_lsa_tree, offset, 2, "LS Age: %d seconds", ntohs(lsa_hdr->ls_age)); - add_item_to_tree(ospf_lsa_tree, offset + 2, 1, "Options: %d ", lsa_hdr->options); - add_item_to_tree(ospf_lsa_tree, offset + 3, 1, "LSA Type: %d (%s)", lsa_hdr->ls_type, lsa_type); + add_item_to_tree(ospf_lsa_tree, offset, 2, "LS Age: %d seconds", ntohs(lsa_hdr.ls_age)); + add_item_to_tree(ospf_lsa_tree, offset + 2, 1, "Options: %d ", lsa_hdr.options); + add_item_to_tree(ospf_lsa_tree, offset + 3, 1, "LSA Type: %d (%s)", lsa_hdr.ls_type, lsa_type); add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Linke State ID: %s ", - ip_to_str((guint8 *) &(lsa_hdr->ls_id))); + ip_to_str((guint8 *) &(lsa_hdr.ls_id))); add_item_to_tree(ospf_lsa_tree, offset + 8, 4, "Advertising Router: %s ", - ip_to_str((guint8 *) &(lsa_hdr->adv_router))); + ip_to_str((guint8 *) &(lsa_hdr.adv_router))); add_item_to_tree(ospf_lsa_tree, offset + 12, 4, "LS Sequence Number: 0x%04lx ", - (unsigned long)ntohl(lsa_hdr->ls_seq)); - add_item_to_tree(ospf_lsa_tree, offset + 16, 2, "LS Checksum: %d ", ntohs(lsa_hdr->ls_checksum)); + (unsigned long)ntohl(lsa_hdr.ls_seq)); + add_item_to_tree(ospf_lsa_tree, offset + 16, 2, "LS Checksum: %d ", ntohs(lsa_hdr.ls_checksum)); - add_item_to_tree(ospf_lsa_tree, offset + 18, 2, "Length: %d ", ntohs(lsa_hdr->length)); + add_item_to_tree(ospf_lsa_tree, offset + 18, 2, "Length: %d ", ntohs(lsa_hdr.length)); if(!disassemble_body){ return OSPF_LSA_HEADER_LENGTH; @@ -459,23 +460,23 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in /* the LSA body starts afte 20 bytes of LSA Header */ offset+=20; - switch(lsa_hdr->ls_type){ + switch(lsa_hdr.ls_type){ case(OSPF_LSTYPE_ROUTER): - router_lsa = (e_ospf_router_lsa *) &pd[offset]; + memcpy(&router_lsa, &pd[offset], sizeof(e_ospf_router_lsa)); /* again: flags should be secified in detail */ - add_item_to_tree(ospf_lsa_tree, offset, 1, "Flags: 0x%02x ", router_lsa->flags); + add_item_to_tree(ospf_lsa_tree, offset, 1, "Flags: 0x%02x ", router_lsa.flags); add_item_to_tree(ospf_lsa_tree, offset + 2, 2, "Nr. of Links: %d ", - ntohs(router_lsa->nr_links)); + ntohs(router_lsa.nr_links)); offset += 4; - /* router_lsa->nr_links links follow + /* router_lsa.nr_links links follow * maybe we should put each of the links into its own subtree ??? */ - for(link_counter = 1 ; link_counter <= ntohs(router_lsa->nr_links); link_counter++){ + for(link_counter = 1 ; link_counter <= ntohs(router_lsa.nr_links); link_counter++){ - router_data = (e_ospf_router_data *) &pd[offset]; + memcpy(&router_data, &pd[offset], sizeof(e_ospf_router_data)); /* check the Link Type and ID */ - switch(router_data->link_type) { + switch(router_data.link_type) { case OSPF_LINK_PTP: link_type="Point-to-point connection to another router"; link_id="Neighboring router's Router ID"; @@ -498,36 +499,36 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in } add_item_to_tree(ospf_lsa_tree, offset, 4, "%s: %s", link_id, - ip_to_str((guint8 *) &(router_data->link_id))); + ip_to_str((guint8 *) &(router_data.link_id))); /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/ add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Link Data: %s", - ip_to_str((guint8 *) &(router_data->link_data))); + ip_to_str((guint8 *) &(router_data.link_data))); add_item_to_tree(ospf_lsa_tree, offset + 8, 1, "Link Type: %d - %s", - router_data->link_type, link_type); - add_item_to_tree(ospf_lsa_tree, offset + 9, 1, "Nr. of TOS metrics: %d", router_data->nr_tos); - add_item_to_tree(ospf_lsa_tree, offset + 10, 2, "TOS 0 metric: %d", ntohs( router_data->tos0_metric )); + router_data.link_type, link_type); + add_item_to_tree(ospf_lsa_tree, offset + 9, 1, "Nr. of TOS metrics: %d", router_data.nr_tos); + add_item_to_tree(ospf_lsa_tree, offset + 10, 2, "TOS 0 metric: %d", ntohs( router_data.tos0_metric )); offset += 12; - /* router_data->nr_tos metrics may follow each link + /* router_data.nr_tos metrics may follow each link * ATTENTION: TOS metrics are not tested (I don't have TOS based routing) * please send me a mail if it is/isn't working */ - for(tos_counter = 1 ; link_counter <= ntohs(router_data->nr_tos); tos_counter++){ - tos_data = (e_ospf_router_metric *) &pd[offset]; + for(tos_counter = 1 ; link_counter <= ntohs(router_data.nr_tos); tos_counter++){ + memcpy(&tos_data, &pd[offset], sizeof(e_ospf_router_metric)); add_item_to_tree(ospf_lsa_tree, offset, 1, "TOS: %d, Metric: %d", - tos_data->tos, ntohs(tos_data->metric)); + tos_data.tos, ntohs(tos_data.metric)); offset += 4; } } break; case(OSPF_LSTYPE_NETWORK): - network_lsa = (e_ospf_network_lsa *) &pd[offset]; + memcpy(&network_lsa, &pd[offset], sizeof(e_ospf_network_lsa)); add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", - ip_to_str((guint8 *) &(network_lsa->network_mask))); + ip_to_str((guint8 *) &(network_lsa.network_mask))); offset += 4; while( ((int) (fd->cap_len - offset)) >= 4){ @@ -540,15 +541,15 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in case(OSPF_LSTYPE_SUMMERY): /* Type 3 and 4 LSAs have the same format */ case(OSPF_LSTYPE_ASBR): - summary_lsa = (e_ospf_summary_lsa *) &pd[offset]; + memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa)); add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", - ip_to_str((guint8 *) &(summary_lsa->network_mask))); + ip_to_str((guint8 *) &(summary_lsa.network_mask))); /* returns only the TOS 0 metric (even if there are more TOS metrics) */ break; case(OSPF_LSTYPE_ASEXT): - summary_lsa = (e_ospf_summary_lsa *) &pd[offset]; + memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa)); add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", - ip_to_str((guint8 *) &(summary_lsa->network_mask))); + ip_to_str((guint8 *) &(summary_lsa.network_mask))); /* asext_lsa = (e_ospf_asexternal_lsa *) &pd[offset + 4]; */ memcpy(&asext_lsa, &pd[offset + 4], sizeof(asext_lsa)); @@ -578,5 +579,5 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in } } /* return the length of this LSA */ - return ntohs(lsa_hdr->length); + return ntohs(lsa_hdr.length); } |