File: eth_33024.c

package info (click to toggle)
libtrace3 3.0.7-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,676 kB
  • ctags: 3,140
  • sloc: ansic: 20,551; sh: 10,125; cpp: 1,384; makefile: 415; yacc: 96; lex: 50
file content (40 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include "libpacketdump.h"

#define LE(lhs,n)                                               \
        do {                                                    \
                uint64_t num=0;                                 \
                int size=0;                                     \
                if ((offset+n)>len*8) return;                   \
                if (n>16) {                                     \
                        num=htonl(*(uint32_t*)(packet+offset/8));\
                        size = 32;\
                } else if (n>8) {                               \
                        num=htons(*(uint16_t*)(packet+offset/8));\
                        size = 16;                              \
                } else {                                        \
                        num=*(uint8_t*)(packet+offset/8);       \
                        size = 8;                               \
                }                                               \
                num=num>>(size - (n + (offset % 8)));           \
                offset+=n;                                      \
                lhs=num&((1<<(n))-1);                           \
        } while(0)

DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
        unsigned int offset=0;
        int value;
        uint16_t ethertype;

        LE(value, 3);   printf(" VLAN: User Priority: %d\n", value);
        LE(value, 1);   printf(" VLAN: Format Indicator: %d\n", value);
        LE(value, 12);  printf(" VLAN: ID: %d\n", value);
        LE(value, 16);  printf(" VLAN: EtherType: 0x%04x\n", (uint16_t)value);
        ethertype = (uint16_t) value;

        decode_next(packet + 4, len - 4, "eth", ethertype);

        return;
}