Portál AbcLinuxu, 10. května 2025 02:44
Inak na tento účel existuje originál nástroj tcprewrite,no bohužiaľ mi to nefunguje.Tu som to prebelal s autorom(je tam aj súbor s radiotap headers).
#include <stdlib.h> #include <stdio.h> #include <inttypes.h> #include <string.h> #include <unistd.h> #include <stdarg.h> #include <limits.h> #include <assert.h> typedef struct pcaprec_hdr_s { uint32_t ts_sec; /* timestamp seconds */ uint32_t ts_usec; /* timestamp microseconds */ uint32_t incl_len; /* number of octets of packet saved in file */ uint32_t orig_len; /* actual length of packet */ } pcaprec_hdr_t; int main(int argc, char **argv) { char c; // header for(int i = 0; i<24; i++) { fread(&c, 1, 1, stdin); } // https://github.com/itds-consulting/tetra-multiframe-sds/blob/master/pcap.py unsigned char _tmp_pcap[] = { 0xd4, 0xc3, 0xb2, 0xa1, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }; unsigned int _tmp_pcap_len = 24; fwrite(_tmp_pcap, _tmp_pcap_len, 1, stdout); // individual packets struct pcaprec_hdr_s h; size_t alloc = 0; char * packet = NULL; char * eh = malloc(6+6+2); while(!feof(stdin)) { // read packet header fread(&h, sizeof(struct pcaprec_hdr_s), 1, stdin); // read packet size_t len = h.incl_len; if(alloc < len) { packet = (char*)realloc((void*)packet, len); alloc = len; } fread(packet, len, 1, stdin); assert(len > 68); // patch with ethernet header // dst memcpy(eh, packet+40, 6); // src memcpy(eh+6, packet+52, 6); // ipv4 //eh[12] = 0x08; //eh[13] = 0x00; // copy memcpy(packet+66-12, eh, 12); // set size // strip checksums size_t diff = 66-12+4; h.incl_len -= diff; h.orig_len -= diff; // write header fwrite(&h, sizeof(struct pcaprec_hdr_s), 1, stdout); // write packet fwrite(packet+diff-4, len-diff, 1, stdout); } }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.