ospf endianless bug

Valerio 'click' Genovese <[email protected]> Tue, 11 May 2004 22:48:27 +0200
Newsgroups gmane.comp.security.libnet
Message-ID <[email protected]>
hu?
it seems to be a bug in libnet_build_ospf.c , htonl() in s.addr field
are wrong, or not?
If I sniff packets generated with ospf_hello and ospf_lsa samples IP
adresses are printed (using ethereal and tcpdump) with wrong endianless

let me know

libnet 1.1.2.1
linux kernel 2.6.5

regards
Valerio 'click' Genovese
libnet_build_ospf_patch.diff (text/plain, 3.6 KB)
--- /home/click/devel/libnet/src/libnet_build_ospf.c	2004-03-01 21:26:12.000000000 +0100
+++ libnet_build_ospf.c	2004-05-11 20:54:22.000000000 +0200
@@ -73,8 +73,8 @@
     ospf_hdr.ospf_v               = 2;              /* OSPF version 2 */
     ospf_hdr.ospf_type            = type;           /* Type of pkt */
     ospf_hdr.ospf_len             = htons(h);       /* Pkt len */
-    ospf_hdr.ospf_rtr_id.s_addr   = htonl(rtr_id);  /* Router ID */
-    ospf_hdr.ospf_area_id.s_addr  = htonl(area_id); /* Area ID */
+    ospf_hdr.ospf_rtr_id.s_addr   = rtr_id;  /* Router ID */
+    ospf_hdr.ospf_area_id.s_addr  = area_id; /* Area ID */
     ospf_hdr.ospf_sum             = (sum ? htons(sum) : 0);
     ospf_hdr.ospf_auth_type       = htons(autype);  /* Type of auth */
 
@@ -145,14 +145,14 @@
     }
     
     memset(&hello_hdr, 0, sizeof(hello_hdr));
-    hello_hdr.hello_nmask.s_addr    = htonl(netmask);  /* Netmask */
+    hello_hdr.hello_nmask.s_addr    = netmask;  /* Netmask */
     hello_hdr.hello_intrvl          = htons(interval);	/* # seconds since last packet sent */
     hello_hdr.hello_opts            = opts;     /* OSPF_* options */
     hello_hdr.hello_rtr_pri         = priority; /* If 0, can't be backup */
     hello_hdr.hello_dead_intvl      = htonl(dead_int); /* Time til router is deemed down */
-    hello_hdr.hello_des_rtr.s_addr  = htonl(des_rtr);	/* Networks designated router */
-    hello_hdr.hello_bkup_rtr.s_addr = htonl(bkup_rtr); /* Networks backup router */
-    hello_hdr.hello_nbr.s_addr      = htonl(neighbor);
+    hello_hdr.hello_des_rtr.s_addr  = des_rtr;	/* Networks designated router */
+    hello_hdr.hello_bkup_rtr.s_addr = bkup_rtr; /* Networks backup router */
+    hello_hdr.hello_nbr.s_addr      = neighbor;
 
     n = libnet_pblock_append(l, p, (u_int8_t *)&hello_hdr, LIBNET_OSPF_HELLO_H);
     if (n == -1)
@@ -276,7 +276,7 @@
     memset(&lsr_hdr, 0, sizeof(lsr_hdr));
     lsr_hdr.lsr_type         = htonl(type);     /* Type of LS being requested */
     lsr_hdr.lsr_lsid	     = htonl(lsid);     /* Link State ID */
-    lsr_hdr.lsr_adrtr.s_addr = htonl(advrtr);   /* Advertising router */
+    lsr_hdr.lsr_adrtr.s_addr = advrtr;   /* Advertising router */
 
     n = libnet_pblock_append(l, p, (u_int8_t *)&lsr_hdr, LIBNET_OSPF_LSR_H);
     if (n == -1)
@@ -399,7 +399,7 @@
     lsa_hdr.lsa_opts        = opts;
     lsa_hdr.lsa_type        = type;
     lsa_hdr.lsa_id          = htonl(lsid);
-    lsa_hdr.lsa_adv.s_addr  = htonl(advrtr);
+    lsa_hdr.lsa_adv.s_addr  = advrtr;
     lsa_hdr.lsa_seq         = htonl(seqnum);
     lsa_hdr.lsa_sum         = (sum ? htons(sum) : 0);
     lsa_hdr.lsa_len         = htons(h);
@@ -537,7 +537,7 @@
     }
 
     memset(&net_lsa_hdr, 0, sizeof(net_lsa_hdr));
-    net_lsa_hdr.net_nmask.s_addr    = htonl(nmask);
+    net_lsa_hdr.net_nmask.s_addr    = nmask;
     net_lsa_hdr.net_rtr_id          = htonl(rtrid);
 
     n = libnet_pblock_append(l, p, (u_int8_t *)&net_lsa_hdr,
@@ -598,7 +598,7 @@
     }
 
     memset(&sum_lsa_hdr, 0, sizeof(sum_lsa_hdr));
-    sum_lsa_hdr.sum_nmask.s_addr    = htonl(nmask);
+    sum_lsa_hdr.sum_nmask.s_addr    = nmask;
     sum_lsa_hdr.sum_metric          = htonl(metric);
     sum_lsa_hdr.sum_tos_metric      = htonl(tos);
 
@@ -661,9 +661,9 @@
     }
 
     memset(&as_lsa_hdr, 0, sizeof(as_lsa_hdr));
-    as_lsa_hdr.as_nmask.s_addr      = htonl(nmask);
+    as_lsa_hdr.as_nmask.s_addr      = nmask;
     as_lsa_hdr.as_metric            = htonl(metric);
-    as_lsa_hdr.as_fwd_addr.s_addr   = htonl(fwdaddr);
+    as_lsa_hdr.as_fwd_addr.s_addr   = fwdaddr;
     as_lsa_hdr.as_rte_tag           = htonl(tag);
 
     n = libnet_pblock_append(l, p, (u_int8_t *)&as_lsa_hdr,