Changeset 1359

Show
Ignore:
Timestamp:
17/06/08 10:49:48 (7 months ago)
Author:
spa1
Message:
  • Fixed numerous bugs in the MPLS libpacketdump decoder
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libpacketdump/eth_34887.c

    r1351 r1359  
    55        do {                                                    \ 
    66                uint64_t num=0;                                 \ 
     7                int size=0;                                     \ 
    78                if ((offset+n)>len*8) return;                   \ 
    8                 if (n>16)                                     \ 
     9                if (n>16) {                                   \ 
    910                        num=htonl(*(uint32_t*)(packet+offset/8));\ 
    10                 else if (n>8)                                   \ 
     11                        size = 32;\ 
     12                } else if (n>8) {                               \ 
    1113                        num=htons(*(uint16_t*)(packet+offset/8));\ 
    12                 else                                            \ 
     14                        size = 16;                              \ 
     15                } else {                                        \ 
    1316                        num=*(uint8_t*)(packet+offset/8);       \ 
    14                 num=num>>(32-n);                                \ 
     17                        size = 8;                               \ 
     18                }                                               \ 
     19                num=num>>(size - (n + (offset % 8)));           \ 
    1520                offset+=n;                                      \ 
    16                 lhs=num&((1<<(n+1))-1);                               \ 
     21                lhs=num&((1<<(n))-1);                         \ 
    1722        } while(0) 
    1823 
     
    2126        int offset=0; 
    2227        int value; 
    23         LE(value,20);   printf(" MPLS: Label: %d\n",offset); 
    24         LE(value,3);    printf(" MPLS: Class of service: %d\n",offset); 
    25         LE(value,1);    printf(" MPLS: Stack: %s\n",offset?"Last" :"More"); 
    26         LE(value,8);    printf(" MPLS: TTL: %d\n",offset); 
     28        int more = 0; 
     29        LE(value,20);   printf(" MPLS: Label: %d\n",value); 
     30        LE(value,3);    printf(" MPLS: Class of service: %d\n",value); 
     31        LE(value,1);    printf(" MPLS: Stack: %s\n",value?"Last" :"More"); 
     32        if (value == 0) more = 1; 
     33        LE(value,8);    printf(" MPLS: TTL: %d\n",value); 
     34         
    2735        /* MPLS doesn't say what it's encapsulating, so we make an educated 
    2836         * guess and pray. 
    2937         */ 
    30         if ((*(packet+32)&0xF0) == 0x40) 
     38        if (more) 
     39                decode_next(packet+offset/8,len-4,"eth",0x8847); 
     40        else if ((*(packet+4)&0xF0) == 0x40) 
    3141                decode_next(packet+offset/8,len-4,"eth",0x0800); 
    32         else if ((*(packet+32)&0xF0) == 0x60) 
     42        else if ((*(packet+4)&0xF0) == 0x60) 
    3343                decode_next(packet+offset/8,len-4,"eth",0x86DD); 
    3444        else