source: libpacketdump/eth_34887.c @ 8485d99

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 8485d99 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[ee6e802]1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
[09ebdb4]26#include <stdio.h>
27#include "libpacketdump.h"
28
29#define LE(lhs,n)                                               \
30        do {                                                    \
31                uint64_t num=0;                                 \
[c5f3398]32                int size=0;                                     \
[09ebdb4]33                if ((offset+n)>len*8) return;                   \
[c5f3398]34                if (n>16) {                                     \
[09ebdb4]35                        num=htonl(*(uint32_t*)(packet+offset/8));\
[c5f3398]36                        size = 32;\
37                } else if (n>8) {                               \
[09ebdb4]38                        num=htons(*(uint16_t*)(packet+offset/8));\
[c5f3398]39                        size = 16;                              \
40                } else {                                        \
[09ebdb4]41                        num=*(uint8_t*)(packet+offset/8);       \
[c5f3398]42                        size = 8;                               \
43                }                                               \
44                num=num>>(size - (n + (offset % 8)));           \
[09ebdb4]45                offset+=n;                                      \
[c5f3398]46                lhs=num&((1<<(n))-1);                           \
[09ebdb4]47        } while(0)
48
[c7062df]49DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
[09ebdb4]50{
[eade363]51        unsigned int offset=0;
[09ebdb4]52        int value;
[c5f3398]53        int more = 0;
54        LE(value,20);   printf(" MPLS: Label: %d\n",value);
55        LE(value,3);    printf(" MPLS: Class of service: %d\n",value);
56        LE(value,1);    printf(" MPLS: Stack: %s\n",value?"Last" :"More");
57        if (value == 0) more = 1;
58        LE(value,8);    printf(" MPLS: TTL: %d\n",value);
59       
[09ebdb4]60        /* MPLS doesn't say what it's encapsulating, so we make an educated
61         * guess and pray.
62         */
[c5f3398]63        if (more)
64                decode_next(packet+offset/8,len-4,"eth",0x8847);
65        else if ((*(packet+4)&0xF0) == 0x40)
[09ebdb4]66                decode_next(packet+offset/8,len-4,"eth",0x0800);
[c5f3398]67        else if ((*(packet+4)&0xF0) == 0x60)
[09ebdb4]68                decode_next(packet+offset/8,len-4,"eth",0x86DD);
69        else
70                decode_next(packet+offset/8,len-4,"link",1);
71
72        return;
73}
Note: See TracBrowser for help on using the repository browser.