source: libpacketdump/eth_2048.c @ 756b8f9

Last change on this file since 756b8f9 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

  • Property mode set to 100644
File size: 1.5 KB
[ace188a]1#include <sys/types.h>
2#include <sys/socket.h>
[950d54a]3#include <netinet/in.h>
4#include <stdio.h>
5#include "libpacketdump.h"
[4e65f42]6#ifndef WIN32
7        #include <netinet/in_systm.h>
[950d54a]9#include <arpa/inet.h>
[010fafb]10#include <netdb.h>
[c7062df]12DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
[4e65f42]14        libtrace_ip_t *ip = (libtrace_ip_t*)packet;
[950d54a]15        if (len>=1) {
[4e65f42]16                printf(" IP: Header Len %i",ip->ip_hl*4);
17                printf(" Ver %i",ip->ip_v);
[950d54a]18        }
[7d952cb]19        //DISPLAY(ip_tos," TOS %02x")
[387d299]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");
[950d54a]23        printf("\n IP:");
[387d299]24        DISPLAYS(ip, ip_id," Id %u");
26        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
[049e277]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");
[4e65f42]31        }
[950d54a]32        //printf("\n IP:");
[387d299]33        DISPLAY(ip, ip_ttl,"\n IP: TTL %i");
[4e65f42]34        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
35                struct protoent *ent=getprotobynumber(ip->ip_p);
[010fafb]36                if (ent) {
[4e65f42]37                        printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
[010fafb]38                }
39                else {
[4e65f42]40                        printf(" Proto %i",ip->ip_p);
[010fafb]41                }
42        } else {
43                printf("\n");
44                return;
45        }
[387d299]46        DISPLAYS(ip, ip_sum," Checksum %i\n");
47        DISPLAYIP(ip, ip_src," IP: Source %s ");
48        DISPLAYIP(ip, ip_dst,"Destination %s\n");
[66ad025]49        decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p);
[950d54a]50        return;
Note: See TracBrowser for help on using the repository browser.