tcpdump mailing list archives

patch: Fix a couple of endianess problems in pcap-dag.c


From: Jesper Peterson <jesper () endace com>
Date: Fri, 30 Jan 2004 11:13:25 +1300


--
Jesper Peterson, Senior Software Developer
http://www.endace.com, +64 7 839 0540
Index: pcap-dag.c
===================================================================
RCS file: /tcpdump/master/libpcap/pcap-dag.c,v
retrieving revision 1.16
diff -u -r1.16 pcap-dag.c
--- pcap-dag.c  5 Jan 2004 18:18:54 -0000       1.16
+++ pcap-dag.c  29 Jan 2004 22:15:03 -0000
@@ -211,7 +211,7 @@
                        }
 
                        p->md.dag_mem_top = dag_offset(p->fd, &(p->md.dag_mem_bottom), flags);
-                       if ((p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size) && nonblocking)
+                       if (nonblocking && (p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size))
                        {
                                /* Pcap is configured to process only available packets, and there aren't any. */
                                return 0;
@@ -274,8 +274,8 @@
                                        }
                                        sunatm->vpi = (rawatm >> 20) & 0x00ff;
                                        sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) | 
-                                               ((sunatm->vpi == 0 && sunatm->vci == 5) ? 6 :
-                                               ((sunatm->vpi == 0 && sunatm->vci == 16) ? 5 : 
+                                               ((sunatm->vpi == 0 && sunatm->vci == htons(5)) ? 6 :
+                                               ((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 : 
                                                ((dp[ATM_HDR_SIZE] == 0xaa &&
                                                        dp[ATM_HDR_SIZE+1] == 0xaa &&
                                                        dp[ATM_HDR_SIZE+2] == 0x03) ? 2 : 1)));
@@ -320,10 +320,10 @@
 
                        /* Count lost packets. */
                        if (header->lctr) {
-                               if (p->md.stat.ps_drop > (UINT_MAX - header->lctr)) {
+                               if (p->md.stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
                                        p->md.stat.ps_drop = UINT_MAX;
                                } else {
-                                       p->md.stat.ps_drop += header->lctr;
+                                       p->md.stat.ps_drop += ntohs(header->lctr);
                                }
                        }
 

Current thread: