Changeset 15749d5 for lib/protocols_transport.c
- Timestamp:
- 09/27/10 14:01:58 (11 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:
- 7e8a25a
- Parents:
- 5d081ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/protocols_transport.c
rf6730d8 r15749d5 47 47 * ICMP 48 48 */ 49 50 /* Get the size of the payload as it was in the original packet, i.e. prior 51 * to any truncation. 52 * 53 * Basically, wire length minus the packet headers. 54 * 55 * Currently only supports IP (v4 and v6) and TCP, UDP and ICMP. Will return 56 * 0 if an unsupported protocol header is encountered, or if one of the 57 * headers is truncated. 58 */ 59 DLLEXPORT size_t trace_get_payload_length(const libtrace_packet_t *packet) { 60 61 void *layer; 62 uint16_t ethertype; 63 uint8_t proto; 64 uint32_t rem; 65 libtrace_ip_t *ip; 66 libtrace_ip6_t *ip6; 67 libtrace_tcp_t *tcp; 68 size_t len = 0; 69 70 layer = trace_get_layer3(packet, ðertype, &rem); 71 72 if (!layer) 73 return 0; 74 switch (ethertype) { 75 case TRACE_ETHERTYPE_IP: 76 ip = (libtrace_ip_t *)layer; 77 if (rem < sizeof(libtrace_ip_t)) 78 return 0; 79 len = ntohs(ip->ip_len) - (4 * ip->ip_hl); 80 break; 81 case TRACE_ETHERTYPE_IPV6: 82 ip6 = (libtrace_ip6_t *)layer; 83 if (rem < sizeof(libtrace_ip6_t)) 84 return 0; 85 len = ntohs(ip6->plen); 86 break; 87 default: 88 return 0; 89 } 90 91 layer = trace_get_transport(packet, &proto, &rem); 92 if (!layer) 93 return 0; 94 95 switch(proto) { 96 case TRACE_IPPROTO_TCP: 97 tcp = (libtrace_tcp_t *)layer; 98 len -= (4 * tcp->doff); 99 break; 100 case TRACE_IPPROTO_UDP: 101 len -= sizeof(libtrace_udp_t); 102 break; 103 case TRACE_IPPROTO_ICMP: 104 len -= sizeof(libtrace_icmp_t); 105 break; 106 default: 107 return 0; 108 } 109 110 return len; 111 112 } 49 113 50 114 DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet,
Note: See TracChangeset
for help on using the changeset viewer.