Changeset 707


Ignore:
Timestamp:
04/11/06 14:52:58 (7 years ago)
Author:
perry
Message:

Fix various bugs in protocols.c
Move trace_get_next_option from trace.c to protocols.c

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/protocols.c

    r680 r707  
    5454        } 
    5555 
    56         return NULL; 
     56        return ethernet; 
    5757} 
    5858 
     
    193193{ 
    194194        uint16_t type; 
    195         void *ret=trace_get_payload_from_link( 
    196                         trace_get_link(packet), 
     195        void *link = trace_get_link(packet); 
     196        void *ret; 
     197 
     198        if (!link) 
     199                return NULL; 
     200         
     201        ret=trace_get_payload_from_link( 
     202                        link, 
    197203                        trace_get_link_type(packet), 
    198204                        &type, NULL); 
     
    212218{ 
    213219        uint16_t type; 
    214         void *ret=trace_get_payload_from_link( 
    215                         trace_get_link(packet), 
     220        void *link=trace_get_link(packet); 
     221        void *ret; 
     222         
     223        if (!link) 
     224                return NULL; 
     225 
     226        ret=trace_get_payload_from_link( 
     227                        link, 
    216228                        trace_get_link_type(packet), 
    217229                        &type,NULL); 
     
    303315        uint8_t dummy; 
    304316        uint16_t ethertype; 
     317        void *link; 
    305318 
    306319        if (!proto) proto=&dummy; 
     
    309322                *remaining = trace_get_capture_length(packet); 
    310323 
     324        link=trace_get_link(packet); 
     325 
     326        if (!link) 
     327                return NULL; 
     328 
    311329        transport = trace_get_payload_from_link( 
    312                         trace_get_link(packet), 
     330                        link, 
    313331                        trace_get_link_type(packet), 
    314332                        &ethertype, 
     
    325343                return NULL; 
    326344 
    327         switch (*proto) { 
     345        switch (ethertype) { 
    328346                case 0x0800: /* IPv4 */ 
    329347                        transport=trace_get_payload_from_ip( 
     
    351369        tcp=(libtrace_tcp_t*)trace_get_transport(packet,&proto,NULL); 
    352370 
    353         if (proto != 6) 
     371        if (!tcp && proto != 6) 
    354372                return NULL; 
    355373 
     
    646664} 
    647665 
     666/* parse an ip or tcp option 
     667 * @param[in,out] ptr   the pointer to the current option 
     668 * @param[in,out] len   the length of the remaining buffer 
     669 * @param[out] type     the type of the option 
     670 * @param[out] optlen   the length of the option 
     671 * @param[out] data     the data of the option 
     672 * 
     673 * @returns bool true if there is another option (and the fields are filled in) 
     674 *               or false if this was the last option. 
     675 * 
     676 * This updates ptr to point to the next option after this one, and updates 
     677 * len to be the number of bytes remaining in the options area.  Type is updated 
     678 * to be the code of this option, and data points to the data of this option, 
     679 * with optlen saying how many bytes there are. 
     680 * 
     681 * @note Beware of fragmented packets. 
     682 * @author Perry Lorier 
     683 */ 
     684int trace_get_next_option(unsigned char **ptr,int *len, 
     685                        unsigned char *type, 
     686                        unsigned char *optlen, 
     687                        unsigned char **data) 
     688{ 
     689        if (*len<=0) 
     690                return 0; 
     691        *type=**ptr; 
     692        switch(*type) { 
     693                case 0: /* End of options */ 
     694                        return 0; 
     695                case 1: /* Pad */ 
     696                        (*ptr)++; 
     697                        (*len)--; 
     698                        return 1; 
     699                default: 
     700                        *optlen = *(*ptr+1); 
     701                        if (*optlen<2) 
     702                                return 0; /* I have no idea wtf is going on 
     703                                           * with these packets 
     704                                           */ 
     705                        (*len)-=*optlen; 
     706                        (*data)=(*ptr+2); 
     707                        (*ptr)+=*optlen; 
     708                        if (*len<0) 
     709                                return 0; 
     710                        return 1; 
     711        } 
     712        assert(0); 
     713} 
     714 
     715 
  • trunk/lib/trace.c

    r695 r707  
    678678} legacy_framing_t; 
    679679*/ 
    680  
    681  
    682  
    683  
    684 /* parse an ip or tcp option 
    685  * @param[in,out] ptr   the pointer to the current option 
    686  * @param[in,out] len   the length of the remaining buffer 
    687  * @param[out] type     the type of the option 
    688  * @param[out] optlen   the length of the option 
    689  * @param[out] data     the data of the option 
    690  * 
    691  * @returns bool true if there is another option (and the fields are filled in) 
    692  *               or false if this was the last option. 
    693  * 
    694  * This updates ptr to point to the next option after this one, and updates 
    695  * len to be the number of bytes remaining in the options area.  Type is updated 
    696  * to be the code of this option, and data points to the data of this option, 
    697  * with optlen saying how many bytes there are. 
    698  * 
    699  * @note Beware of fragmented packets. 
    700  * @author Perry Lorier 
    701  */ 
    702 int trace_get_next_option(unsigned char **ptr,int *len, 
    703                         unsigned char *type, 
    704                         unsigned char *optlen, 
    705                         unsigned char **data) 
    706 { 
    707         if (*len<=0) 
    708                 return 0; 
    709         *type=**ptr; 
    710         switch(*type) { 
    711                 case 0: /* End of options */ 
    712                         return 0; 
    713                 case 1: /* Pad */ 
    714                         (*ptr)++; 
    715                         (*len)--; 
    716                         return 1; 
    717                 default: 
    718                         *optlen = *(*ptr+1); 
    719                         if (*optlen<2) 
    720                                 return 0; /* I have no idea wtf is going on 
    721                                            * with these packets 
    722                                            */ 
    723                         (*len)-=*optlen; 
    724                         (*data)=(*ptr+2); 
    725                         (*ptr)+=*optlen; 
    726                         if (*len<0) 
    727                                 return 0; 
    728                         return 1; 
    729         } 
    730         assert(0); 
    731 } 
    732680 
    733681 
Note: See TracChangeset for help on using the changeset viewer.