/
decap_cisco3550.c
106 lines (93 loc) · 3.02 KB
/
decap_cisco3550.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//---------------------------------------------------------
//
// fmadio pcap de-encapsuation utility
//
//
// Copyright (C) 2018-2023 fmad engineering llc aaron foo
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Exablaze Footer de-encapsulation
//
//---------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/shm.h>
#include <sys/ioctl.h>
#include "decap.h"
u8* PrettyNumber(u64 num);
//---------------------------------------------------------------------------------------------
void fDecap_Cisco3550_Open(fDecap_t* D, int argc, char* argv[])
{
for (int i=1; i < argc; i++)
{
if (strcmp(argv[i], "--cisco3550") == 0)
{
fprintf(stderr, "Cisco 3550 (Exablaze footer)\n");
D->DecapCisco3550 = true;
}
}
}
void fDecap_Cisco3550_Close(fDecap_t* D)
{
}
static void fDecap_Cisco3550_Sample(void)
{
}
//---------------------------------------------------------------------------------------------
// Exablaze de-encapsulation
//
// 1) extracts an replaces the pcap timestamp with the absolute timestamp from the
// footer
//
// 2) strips the footer, so the orignial packet and FCS are written to the pcap
//
u16 fDecap_Cisco3550_Unpack( fDecap_t* D,
u64 PCAPTS,
fEther_t** pEther,
u8** pPayload,
u32* pPayloadLength,
u32* pMetaPort,
u64* pMetaTS,
u32* pMetaFCS)
{
// grab the footer, assumption is every packet has a footer
ExablazeFooter_t* Footer = (ExablazeFooter_t*)(pPayload[0] + pPayloadLength[0] - sizeof(ExablazeFooter_t));
u64 TS = (u64)swap32(Footer->Sec)*1000000000ULL + (1000000000ULL*(u64)swap32(Footer->NSec)) / 0x100000000ULL;
if (D->DecapDump)
{
fprintf(stderr, "| cisco3550 TS: %20lli %s ", TS, FormatTS(TS));
fprintf(stderr, "%8i %f %02i", swap32(Footer->Sec), swap32(Footer->NSec) / (float)0x100000000), Footer->PSec;
fprintf(stderr, "PortID: %4i ", Footer->PortID);
fprintf(stderr, "DevID: %4x", swap16(Footer->DeviceID));
}
// set new packet length (strip footer)
//pPayloadLength[0] = pPayloadLength[0] - 16;
// overwrite the timestamp
pMetaTS[0] = TS;
return 0;
}