source: libpacketdump/eth_34525.c @ 176646e

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 176646e was 176646e, checked in by Yuwei Wang <yww4@…>, 11 years ago

add ipv6 parser for libpacketdump

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[176646e]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
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//#define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))
20//#define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))
21//
22DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
23{
24        libtrace_ip6_t *ip = (libtrace_ip6_t*)packet;
25       
26        uint32_t tmp = ntohl(*(uint32_t*)ip);
27
28        printf("IPv6: Version %u\n", (tmp >> 28) & 0x000000f);
29        printf("IPv6: Class %u\n", (tmp >> 20) & 0x000000ff);
30        printf("IPv6: Flow Label %u\n", tmp & 0x000fffff);
31        printf("IPv6: Payload Length %u\n", ntohs(ip->plen));
32        printf("IPv6: Next Header %u\n", ip->nxt);
33        printf("IPv6: Hop Limit %u\n", ip->hlim);
34
35
36        char ipstr[INET6_ADDRSTRLEN];                             
37        inet_ntop(AF_INET6, &(ip->ip_src), ipstr, INET6_ADDRSTRLEN);
38
39        printf("IPv6: Source IP %s\n", ipstr);
40        inet_ntop(AF_INET6, &(ip->ip_dst), ipstr, INET6_ADDRSTRLEN);
41        printf("IPv6: Destination IP %s\n", ipstr);
42
43        decode_next(packet+sizeof(libtrace_ip6_t),len-sizeof(libtrace_ip6_t),"ip",ip->nxt);
44        return;
45}
Note: See TracBrowser for help on using the repository browser.