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/ip_6.c

    r9ca0b29 r387d299  
    55#include <assert.h>
    66#include <netdb.h>
    7 
    8 #define SAFE(x) \
    9         ((unsigned int)len>=((char*)&tcp->x-(char*)tcp+sizeof(tcp->x)))
    10 #define DISPLAY_EXP(x,fmt,exp) \
    11         if (SAFE(x)) \
    12                 printf(fmt,exp); \
    13         else \
    14                 return;
    15 
    16 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,tcp->x)
    17 
    18 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(tcp->x))
    19 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(tcp->x))
    20 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&tcp->x))
    217
    228DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
     
    2713        libtrace_tcp_t *tcp = (libtrace_tcp_t *)packet;
    2814        printf(" TCP:");
    29         if (SAFE(source)) {
     15        if (SAFE(tcp, source)) {
    3016                struct servent *ent=getservbyport(tcp->source,"tcp");
    3117                if(ent) {
     
    3925                return;
    4026        }
    41         if (SAFE(dest)) {
     27        if (SAFE(tcp, dest)) {
    4228                struct servent *ent=getservbyport(tcp->dest,"tcp");
    4329                if(ent) {
     
    5238        }
    5339        printf("\n TCP:");
    54         DISPLAYL(seq," Seq %u");
     40        DISPLAYL(tcp, seq," Seq %u");
    5541        printf("\n TCP:");
    56         DISPLAYL(ack_seq," Ack %u");
     42        DISPLAYL(tcp, ack_seq," Ack %u");
    5743        if ((char*)&tcp->window-(char *)tcp>len) {
    5844                printf("\n");
     
    7157        if (tcp->ack) printf(" ACK");
    7258        if (tcp->urg) printf(" URG");
    73         DISPLAYS(window," Window %i");
     59        DISPLAYS(tcp, window," Window %i");
    7460        printf("\n TCP:");
    75         DISPLAYS(check," Checksum %i");
    76         DISPLAYS(urg_ptr," Urgent %i");
     61        DISPLAYS(tcp, check," Checksum %i");
     62        DISPLAYS(tcp, urg_ptr," Urgent %i");
    7763        pkt = (unsigned char*)packet+sizeof(*tcp);
    7864        plen = (len-sizeof *tcp) < (tcp->doff*4-sizeof(*tcp))?(len-sizeof(*tcp)):(tcp->doff*4-sizeof *tcp);
Note: See TracChangeset for help on using the changeset viewer.