source: libpacketdump/eth_2048.c @ 387d299

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 387d299 was 387d299, checked in by Shane Alcock <salcock@…>, 7 years ago

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.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <sys/types.h>
2#include <sys/socket.h>
3#include <netinet/in.h>
4#include <stdio.h>
5#include "libpacketdump.h"
6#ifndef WIN32
7        #include <netinet/in_systm.h>
8#endif
9#include <arpa/inet.h>
10#include <netdb.h>
11
12DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
13{
14        libtrace_ip_t *ip = (libtrace_ip_t*)packet;
15        if (len>=1) {
16                printf(" IP: Header Len %i",ip->ip_hl*4);
17                printf(" Ver %i",ip->ip_v);
18        }
19        //DISPLAY(ip_tos," TOS %02x")
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");
23        printf("\n IP:");
24        DISPLAYS(ip, ip_id," Id %u");
25       
26        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
27                printf(" Fragoff %i", ntohs(ip->ip_off) & 0x1FFF);
28                if (ntohs(ip->ip_off) & 0x2000) printf(" MORE_FRAG");
29                if (ntohs(ip->ip_off) & 0x4000) printf(" DONT_FRAG");
30                if (ntohs(ip->ip_off) & 0x8000) printf(" RESV_FRAG");
31        }
32        //printf("\n IP:");
33        DISPLAY(ip, ip_ttl,"\n IP: TTL %i");
34        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
35                struct protoent *ent=getprotobynumber(ip->ip_p);
36                if (ent) {
37                        printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
38                }
39                else {
40                        printf(" Proto %i",ip->ip_p);
41                }
42        } else {
43                printf("\n");
44                return;
45        }
46        DISPLAYS(ip, ip_sum," Checksum %i\n");
47        DISPLAYIP(ip, ip_src," IP: Source %s ");
48        DISPLAYIP(ip, ip_dst,"Destination %s\n");
49        decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p);
50        return;
51}
Note: See TracBrowser for help on using the repository browser.