Changeset 994


Ignore:
Timestamp:
09/17/06 18:36:13 (7 years ago)
Author:
smr26
Message:

Fix get_payload_from_link for prism and radiotap.
Make sure to use bswap when looking at radiotap length.
Tidy up exported API, don't export get_payload_from_prism or _from_radiotap.

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/libtrace.h.in

    r983 r994  
    495495 * specified in the it_present bitmask. If bit 31 of it_present is set, then 
    496496 * another bitmask follows. 
    497  * NB: All of the radiotap data fields are in little-endian byte-order. 
     497 * @note All of the radiotap data fields are in little-endian byte-order. 
    498498 */ 
    499499typedef struct libtrace_radiotap_t { 
     
    851851DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto, 
    852852                uint32_t *remaining); 
    853  
    854  
    855 /** Gets a pointer to the payload given a pointer to the Radiotap header 
    856  * @param link a pointer to the Radiotap header 
    857  * @param[out] type     An output variable of the ethernet type 
    858  * @param[in,out] remaining Updated with the number of bytes remaining 
    859  * 
    860  * @return a pointer to the 802.11 header, or NULL if header isn't 
    861  * present. 
    862  * 
    863  * Remaining may be NULL.  If Remaining is not NULL it must point to the number 
    864  * of bytes captured of the linklayer and beyond.  It will be updated after 
    865  * this function to the number of bytes remaining after the Radiotap header has been  
    866  * removed. 
    867  * 
    868  * type may be NULL if not needed. 
    869  */ 
    870 DLLEXPORT void *trace_get_payload_from_radiotap(void *link, 
    871                 uint16_t *type, uint32_t *remaining); 
    872  
    873  
    874 /** Gets a pointer to the payload given a pointer to the Prism monitoring header 
    875  * @param link a pointer to the Prism monitoring header 
    876  * @param[out] type     An output variable of the ethernet type 
    877  * @param[in,out] remaining Updated with the number of bytes remaining 
    878  * 
    879  * @return a pointer to the 802.11 header, or NULL if header isn't 
    880  * present. 
    881  * 
    882  * Remaining may be NULL.  If Remaining is not NULL it must point to the number 
    883  * of bytes captured of the linklayer and beyond.  It will be updated after 
    884  * this function to the number of bytes remaining after the Radiotap header has been  
    885  * removed. 
    886  * 
    887  * type may be NULL if not needed. 
    888  */ 
    889 DLLEXPORT void *trace_get_payload_from_prism(void *link, 
    890                 uint16_t *type, uint32_t *remaining); 
    891  
    892853 
    893854/** Gets a pointer to the payload given a pointer to the link header 
  • trunk/lib/link_wireless.c

    r985 r994  
    4848 * @note Radiotap fields are always little-endian 
    4949 */ 
    50 DLLEXPORT void *trace_get_radiotap_field(void *link, libtrace_radiotap_field_t field) 
     50static void *trace_get_radiotap_field(void *link, libtrace_radiotap_field_t field) 
    5151{ 
    5252    struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t *)link; 
  • trunk/lib/protocols.c

    r982 r994  
    190190/* Returns the 'payload' of the prism header, which is the 802.11 frame */ 
    191191static void *trace_get_payload_from_prism (void *link, 
    192         uint16_t *type, uint32_t *remaining) 
    193 { 
    194     if (remaining) { 
    195         if (*remaining<144)  
    196             return NULL; 
    197         *remaining-=144; 
    198     } 
    199  
    200     if (type) *type = 0; 
    201  
    202     return (void *) ((char*)link+144); 
     192                uint16_t *type, uint32_t *remaining) 
     193{ 
     194        if (remaining) { 
     195                if (*remaining<144)  
     196                        return NULL; 
     197                *remaining-=144; 
     198        } 
     199 
     200        if (type) *type = 0; 
     201 
     202        return (void *) ((char*)link+144); 
    203203} 
    204204 
    205205/* Returns the 'payload' of the radiotap header, which is the 802.11 frame */ 
    206206static void *trace_get_payload_from_radiotap (void *link,  
    207         uint16_t *type, uint32_t *remaining) 
    208 { 
    209     struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t*)link; 
    210     if (remaining) { 
    211                 if (*remaining<rtap->it_len)  
    212                         return NULL; 
    213                 *remaining-=rtap->it_len; 
     207                uint16_t *type, uint32_t *remaining) 
     208{ 
     209        struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t*)link; 
     210        uint16_t rtaplen = bswap_le_to_host16(rtap->it_len); 
     211        if (remaining) { 
     212                if (*remaining < rtaplen) 
     213                        return NULL; 
     214                *remaining -= rtaplen; 
    214215        } 
    215216 
    216217        if (type) *type = 0; 
    217      
    218         return (void*) ((char*)link + rtap->it_len); 
    219 } 
    220          
     218 
     219        return (void*) ((char*)link + rtaplen); 
     220} 
     221 
    221222void *trace_get_payload_from_link(void *link, libtrace_linktype_t linktype,  
    222223                uint16_t *type, uint32_t *remaining) 
    223224{ 
    224     void *l; 
    225      
     225        void *l = NULL; 
     226 
    226227        switch(linktype) { 
    227228                case TRACE_TYPE_80211_PRISM: 
    228             l = trace_get_payload_from_prism(link,type,remaining); 
    229             l ? trace_get_payload_from_80211(l,type,remaining) : NULL; 
    230         case TRACE_TYPE_80211_RADIO: 
    231             l = trace_get_payload_from_radiotap(link,type,remaining); 
    232             l ? trace_get_payload_from_80211(l,type,remaining) : NULL ; 
     229                        l = trace_get_payload_from_prism(link,type,remaining); 
     230                        return(l ? trace_get_payload_from_80211(l,type,remaining) : NULL); 
     231                case TRACE_TYPE_80211_RADIO: 
     232                        l = trace_get_payload_from_radiotap(link,type,remaining); 
     233                        return(l ? trace_get_payload_from_80211(l,type,remaining) : NULL); 
    233234                case TRACE_TYPE_80211: 
    234235                        return trace_get_payload_from_80211(link,type,remaining); 
Note: See TracChangeset for help on using the changeset viewer.