Ignore:
Timestamp:
01/21/10 10:10:46 (3 years ago)
Author:
salcock
Message:
  • Adjusted the "shortcut" protocol access functions to return NULL if a full header (minus options) is not present.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/protocols_transport.c

    r1436 r1491  
    4646DLLEXPORT libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet) { 
    4747        uint8_t proto; 
     48        uint32_t rem = 0; 
    4849        libtrace_tcp_t *tcp; 
    4950 
    50         tcp=(libtrace_tcp_t*)trace_get_transport(packet,&proto,NULL); 
     51        tcp=(libtrace_tcp_t*)trace_get_transport(packet,&proto,&rem); 
    5152 
    5253        if (!tcp || proto != TRACE_IPPROTO_TCP) 
     54                return NULL; 
     55 
     56        /* We should return NULL if there isn't a full TCP header, because the 
     57         * caller has no way of telling how much of a TCP header we have 
     58         * returned - use trace_get_transport() if you want to deal with 
     59         * partial headers  
     60         * 
     61         * NOTE: We're not going to insist that all the TCP options are present 
     62         * as well, because lots of traces are snapped after 20 bytes of TCP 
     63         * header and I don't really want to break libtrace programs that 
     64         * use this function to process those traces */ 
     65 
     66        if (rem < sizeof(libtrace_tcp_t)) 
    5367                return NULL; 
    5468 
     
    7084DLLEXPORT libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet) { 
    7185        uint8_t proto; 
     86        uint32_t rem = 0; 
    7287        libtrace_udp_t *udp; 
    7388 
    74         udp=(libtrace_udp_t*)trace_get_transport(packet,&proto,NULL); 
     89        udp=(libtrace_udp_t*)trace_get_transport(packet,&proto,&rem); 
    7590 
    7691        if (!udp || proto != TRACE_IPPROTO_UDP) 
     92                return NULL; 
     93 
     94        /* Make sure we return a full UDP header as the caller has no way of 
     95         * telling how much of the packet is remaining */ 
     96        if (rem < sizeof(libtrace_udp_t)) 
    7797                return NULL; 
    7898 
     
    94114DLLEXPORT libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet) { 
    95115        uint8_t proto; 
     116        uint32_t rem = 0; 
    96117        libtrace_icmp_t *icmp; 
    97118 
    98         icmp=(libtrace_icmp_t*)trace_get_transport(packet,&proto,NULL); 
     119        icmp=(libtrace_icmp_t*)trace_get_transport(packet,&proto,&rem); 
    99120 
    100121        if (!icmp || proto != TRACE_IPPROTO_ICMP) 
     122                return NULL; 
     123 
     124        /* Make sure we return a full ICMP header as the caller has no way of 
     125         * telling how much of the packet is remaining */ 
     126        if (rem < sizeof(libtrace_icmp_t)) 
    101127                return NULL; 
    102128 
Note: See TracChangeset for help on using the changeset viewer.