Changeset 8b49230
- Timestamp:
- 08/30/13 13:30:41 (8 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- bf1029a
- Parents:
- 8780774
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
rc04929c r8b49230 44 44 format_duck.c format_tsh.c $(NATIVEFORMATS) $(BPFFORMATS) \ 45 45 format_atmhdr.c \ 46 libtrace_int.h lt_inttypes.h \47 linktypes.c link_wireless.c \46 libtrace_int.h lt_inttypes.h lt_bswap.h \ 47 linktypes.c link_wireless.c byteswap.c \ 48 48 checksum.c checksum.h \ 49 49 protocols_pktmeta.c protocols_l2.c protocols_l3.c \ -
lib/format_helper.c
rd57ae6f r8b49230 320 320 va_end(va); 321 321 } 322 323 /* Byte swapping functions for various inttypes */324 uint64_t byteswap64(uint64_t num)325 {326 return (byteswap32((num&0xFFFFFFFF00000000ULL)>>32))327 |((uint64_t)byteswap32(num&0x00000000FFFFFFFFULL)<<32);328 }329 330 uint32_t byteswap32(uint32_t num)331 {332 return ((num&0x000000FFU)<<24)333 | ((num&0x0000FF00U)<<8)334 | ((num&0x00FF0000U)>>8)335 | ((num&0xFF000000U)>>24);336 }337 338 uint16_t byteswap16(uint16_t num)339 {340 return ((num<<8)&0xFF00)|((num>>8)&0x00FF);341 }342 -
lib/libtrace_int.h
r3799f51 r8b49230 59 59 #include "libtrace.h" 60 60 #include "wandio.h" 61 #include "lt_bswap.h" 61 62 62 63 #ifdef _MSC_VER … … 900 901 uint32_t *remaining); 901 902 902 /** Byteswaps a 64-bit value.903 *904 * @param num The value to be byteswapped.905 * @return The byteswapped 64-bit number906 *907 */908 uint64_t byteswap64(uint64_t num);909 910 /** Byteswaps a 32-bit value.911 *912 * @param num The value to be byteswapped.913 * @return The byteswapped 32-bit number914 *915 */916 uint32_t byteswap32(uint32_t num);917 918 /** Byteswaps a 16-bit value.919 *920 * @param num The value to be byteswapped.921 * @return The byteswapped 16-bit number922 *923 */924 uint16_t byteswap16(uint16_t num);925 926 /** @name Byte ordering927 * Macros that define how to convert a value into a particular byte-order928 *929 * @{930 */931 #if __BYTE_ORDER == __BIG_ENDIAN932 #define bswap_host_to_be64(num) ((uint64_t)(num))933 #define bswap_host_to_le64(num) byteswap64(num)934 #define bswap_host_to_be32(num) ((uint32_t)(num))935 #define bswap_host_to_le32(num) byteswap32(num)936 #define bswap_host_to_be16(num) ((uint16_t)(num))937 #define bswap_host_to_le16(num) byteswap16(num)938 939 #define bswap_be_to_host64(num) ((uint64_t)(num))940 #define bswap_le_to_host64(num) byteswap64(num)941 #define bswap_be_to_host32(num) ((uint32_t)(num))942 #define bswap_le_to_host32(num) byteswap32(num)943 #define bswap_be_to_host16(num) ((uint16_t)(num))944 #define bswap_le_to_host16(num) byteswap16(num)945 946 /* We use ntoh*() here, because the compiler may947 * attempt to optimise it948 */949 #elif __BYTE_ORDER == __LITTLE_ENDIAN950 #define bswap_host_to_be64(num) (byteswap64(num))951 #define bswap_host_to_le64(num) ((uint64_t)(num))952 #define bswap_host_to_be32(num) (htonl(num))953 #define bswap_host_to_le32(num) ((uint32_t)(num))954 #define bswap_host_to_be16(num) (htons(num))955 #define bswap_host_to_le16(num) ((uint16_t)(num))956 957 #define bswap_be_to_host64(num) (byteswap64(num))958 #define bswap_le_to_host64(num) ((uint64_t)(num))959 #define bswap_be_to_host32(num) (ntohl(num))960 #define bswap_le_to_host32(num) ((uint32_t)(num))961 #define bswap_be_to_host16(num) (ntohs(num))962 #define bswap_le_to_host16(num) ((uint16_t)(num))963 964 #else965 #error "Unknown byte order"966 #endif967 /** @} */968 903 969 904 #ifdef HAVE_BPF -
libpacketdump/Makefile.am
rb471b67 r8b49230 166 166 ospf2_1005_la_LDFLAGS=$(modflags) 167 167 168 libpacketdump_la_SOURCES = libpacketdump.cc \168 libpacketdump_la_SOURCES = libpacketdump.cc ../lib/byteswap.c \ 169 169 lexer.l parser.y bitbuffer.c bitbuffer.h grammar.h 170 170 -
libpacketdump/libpacketdump.cc
rc7f8451 r8b49230 4 4 #include <time.h> 5 5 #include "libpacketdump.h" 6 #include "lt_bswap.h" 6 7 #include <stdio.h> 7 8 #include <netdb.h> … … 303 304 }; 304 305 } 306 -
libpacketdump/link_15.c
ref07202 r8b49230 2 2 * libpacketdump decoder for Radiotap 3 3 */ 4 #include "libtrace_int.h" /* bswaps */5 4 #include <sys/types.h> 6 5 #include <netinet/in.h> … … 10 9 #include "libtrace.h" 11 10 #include "libpacketdump.h" 11 #include "lt_bswap.h" 12 12 13 13 #define ALIGN_NATURAL_32(_p,_s,_c) \ … … 23 23 struct libtrace_radiotap_t *rtap; 24 24 uint16_t rtap_len; 25 uint32_t rtap_pres; 25 26 uint16_t rtap_real_len; /* to make sure length in header matches fields present */ 26 27 rtap = (libtrace_radiotap_t *)packet; … … 35 36 rtap_real_len = sizeof(struct libtrace_radiotap_t); 36 37 rtap_len = bswap_le_to_host16(rtap->it_len); 38 rtap_pres = bswap_le_to_host32(rtap->it_present); 37 39 38 40 printf(" version: %u, length: %u, fields: %#08x\n", rtap->it_version, 39 rtap_len, rtap ->it_present);41 rtap_len, rtap_pres); 40 42 41 43 /* Check for extended bitmasks */ 42 44 ptr = (uint32_t *) &(rtap->it_present); 43 45 44 if ( ( *ptr) & (1 << TRACE_RADIOTAP_EXT) )46 if ( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) ) 45 47 printf(" extended fields:"); 46 48 47 while( ( *ptr) & (1 << TRACE_RADIOTAP_EXT) ) {49 while( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) ) { 48 50 rtap_real_len += sizeof (uint32_t); 49 printf(" %#08x", *(++ptr)); 51 ptr++; 52 printf(" %#08x", bswap_le_to_host32(*ptr)); 50 53 } 51 54 … … 54 57 s = p = (uint8_t *) ++ptr; 55 58 56 if (rtap ->it_present& (1 << TRACE_RADIOTAP_TSFT)) {59 if (rtap_pres & (1 << TRACE_RADIOTAP_TSFT)) { 57 60 printf(" Radiotap: TSFT = %" PRIu64 " microseconds\n", bswap_le_to_host64(*((uint64_t *)p))); 58 61 p += sizeof (uint64_t); … … 60 63 } 61 64 62 if (rtap ->it_present& (1 << TRACE_RADIOTAP_FLAGS)) {65 if (rtap_pres & (1 << TRACE_RADIOTAP_FLAGS)) { 63 66 printf(" Radiotap: Flags = 0x%02x\n", *p); 64 67 p += sizeof (uint8_t); … … 67 70 68 71 69 if (rtap ->it_present& (1 << TRACE_RADIOTAP_RATE)) {72 if (rtap_pres & (1 << TRACE_RADIOTAP_RATE)) { 70 73 printf(" Radiotap: Rate = %u kbps\n", (*p) * 500); 71 74 p += sizeof (uint8_t); … … 73 76 } 74 77 75 if (rtap ->it_present& (1 << TRACE_RADIOTAP_CHANNEL)) {78 if (rtap_pres & (1 << TRACE_RADIOTAP_CHANNEL)) { 76 79 ALIGN_NATURAL_16(p,s,rtap_real_len); 77 80 printf(" Radiotap: Freq = %u MHz, ChanFlags: 0x%04x\n", bswap_le_to_host16(*((uint16_t *)p)), … … 81 84 } 82 85 83 if (rtap ->it_present& (1 << TRACE_RADIOTAP_FHSS)) {86 if (rtap_pres & (1 << TRACE_RADIOTAP_FHSS)) { 84 87 ALIGN_NATURAL_16(p,s, rtap_real_len); 85 88 printf(" Radiotap: FHSS HopSet = %u , HopPattern: %u\n", *p, *(p+1)); … … 89 92 90 93 91 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL)) {94 if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL)) { 92 95 printf(" Radiotap: Signal = %i dBm\n", (int8_t) *p) ; 93 96 p += sizeof (uint8_t); … … 96 99 97 100 98 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DBM_ANTNOISE)) {101 if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTNOISE)) { 99 102 printf(" Radiotap: Noise = %i dBm\n", (int8_t) *p); 100 103 p += sizeof (uint8_t); … … 103 106 104 107 105 if (rtap ->it_present& (1 << TRACE_RADIOTAP_LOCK_QUALITY)) {108 if (rtap_pres & (1 << TRACE_RADIOTAP_LOCK_QUALITY)) { 106 109 ALIGN_NATURAL_16(p,s, rtap_real_len); 107 110 printf(" Radiotap: Barker Code Lock Quality = %u\n", bswap_le_to_host16(*((uint16_t *)p))); … … 111 114 112 115 113 if (rtap ->it_present& (1 << TRACE_RADIOTAP_TX_ATTENUATION)) {116 if (rtap_pres & (1 << TRACE_RADIOTAP_TX_ATTENUATION)) { 114 117 ALIGN_NATURAL_16(p,s, rtap_real_len); 115 118 printf(" Radiotap: TX Attenuation = %u\n", bswap_le_to_host16(*((uint16_t *)p))); … … 118 121 } 119 122 120 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION)) {123 if (rtap_pres & (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION)) { 121 124 ALIGN_NATURAL_16(p,s,rtap_real_len); 122 125 printf(" Radiotap: TX Attenuation = %u dB\n", bswap_le_to_host16(*((uint16_t *)p))); … … 125 128 } 126 129 127 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DBM_TX_POWER)) {130 if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_TX_POWER)) { 128 131 printf(" Radiotap: TX Power = %i dBm\n", *p); 129 132 p += sizeof (uint8_t); … … 131 134 } 132 135 133 if (rtap ->it_present& (1 << TRACE_RADIOTAP_ANTENNA)) {136 if (rtap_pres & (1 << TRACE_RADIOTAP_ANTENNA)) { 134 137 printf(" Radiotap: Antenna = %u\n", *p); 135 138 p += sizeof (uint8_t); … … 137 140 } 138 141 139 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DB_ANTSIGNAL)) {142 if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTSIGNAL)) { 140 143 printf(" Radiotap: Signal = %u dB\n", *p); 141 144 p += sizeof (uint8_t); … … 143 146 } 144 147 145 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DB_ANTNOISE)) {148 if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTNOISE)) { 146 149 printf(" Radiotap: Noise = %u dB\n", *p); 147 150 p += sizeof (uint8_t); … … 149 152 } 150 153 151 if (rtap ->it_present& (1 << TRACE_RADIOTAP_RX_FLAGS)) {154 if (rtap_pres & (1 << TRACE_RADIOTAP_RX_FLAGS)) { 152 155 ALIGN_NATURAL_16(p,s,rtap_real_len); 153 156 printf(" Radiotap: RX Flags = 0x%04x\n", *((uint16_t *)p)); … … 156 159 } 157 160 158 if (rtap ->it_present& (1 << TRACE_RADIOTAP_TX_FLAGS)) {161 if (rtap_pres & (1 << TRACE_RADIOTAP_TX_FLAGS)) { 159 162 ALIGN_NATURAL_16(p,s,rtap_real_len); 160 163 printf(" Radiotap: TX Flags = 0x%04x\n", *((uint16_t *)p)); … … 163 166 } 164 167 165 if (rtap ->it_present& (1 << TRACE_RADIOTAP_RTS_RETRIES)) {168 if (rtap_pres & (1 << TRACE_RADIOTAP_RTS_RETRIES)) { 166 169 printf(" Radiotap: RTS Retries = %u\n", *p); 167 170 p += sizeof (uint8_t); … … 169 172 } 170 173 171 if (rtap ->it_present& (1 << TRACE_RADIOTAP_DATA_RETRIES)) {174 if (rtap_pres & (1 << TRACE_RADIOTAP_DATA_RETRIES)) { 172 175 printf(" Radiotap: Data Retries = %u\n", *p); 173 176 p += sizeof (uint8_t);
Note: See TracChangeset
for help on using the changeset viewer.