Ignore:
Timestamp:
07/04/14 11:37:25 (7 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
d14e23d
Parents:
9ad7a35
Message:

Remove duplicate macros in libpacketdump

Ensure OSPF libpacketdump module won't segfault or print garbage
if a truncated OSPF header is passed into it.

Renamed 'len' field in OSPF header to 'ospf_len' to avoid
potential conflict with variables named len in libpacketdump
code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpacketdump/eth_2048.c

    r66ad025 r387d299  
    1010#include <netdb.h>
    1111
    12 #define DISPLAY_EXP(x,fmt,exp) \
    13         if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \
    14                 printf(fmt,exp); \
    15         else \
    16                 return;
    17 
    18 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x)
    19 
    20 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))
    21 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))
    22 
    2312DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
    2413{
     
    2918        }
    3019        //DISPLAY(ip_tos," TOS %02x")
    31         DISPLAY_EXP(ip_tos," DSCP %02x",ip->ip_tos >> 2)
    32         DISPLAY_EXP(ip_tos," ECN %x",ip->ip_tos & 0x2)
    33         DISPLAYS(ip_len," Total Length %i")
     20        DISPLAY_EXP(ip, ip_tos," DSCP %02x",ip->ip_tos >> 2);
     21        DISPLAY_EXP(ip, ip_tos," ECN %x",ip->ip_tos & 0x2);
     22        DISPLAYS(ip, ip_len," Total Length %i");
    3423        printf("\n IP:");
    35         DISPLAYS(ip_id," Id %u");
     24        DISPLAYS(ip, ip_id," Id %u");
    3625       
    3726        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
     
    4231        }
    4332        //printf("\n IP:");
    44         DISPLAY(ip_ttl,"\n IP: TTL %i");
     33        DISPLAY(ip, ip_ttl,"\n IP: TTL %i");
    4534        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
    4635                struct protoent *ent=getprotobynumber(ip->ip_p);
     
    5544                return;
    5645        }
    57         DISPLAYS(ip_sum," Checksum %i\n");
    58         DISPLAYIP(ip_src," IP: Source %s ");
    59         DISPLAYIP(ip_dst,"Destination %s\n");
     46        DISPLAYS(ip, ip_sum," Checksum %i\n");
     47        DISPLAYIP(ip, ip_src," IP: Source %s ");
     48        DISPLAYIP(ip, ip_dst,"Destination %s\n");
    6049        decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p);
    6150        return;
Note: See TracChangeset for help on using the changeset viewer.