Skip to content

Instantly share code, notes, and snippets.

@songritk
Created July 12, 2020 10:41
Show Gist options
  • Save songritk/68c7fdb8064e6e7ac15ffaeb274967da to your computer and use it in GitHub Desktop.
Save songritk/68c7fdb8064e6e7ac15ffaeb274967da to your computer and use it in GitHub Desktop.
cut pcap file header
#include<iostream>
#include<fstream>
using namespace std;
int printhex(char c){
if(int(c) < 0) {
printf("%02x",int(c^0xffffff00));
}else{
printf("%02x",int(c));
}
return 0;
}
int main(){
char x;
int count=0;
ifstream ifs;
streampos pos;
streampos stop_pos;
ifs.open("arp-1_anon.pcapng", ios::binary|ios::in);
ifs.seekg(0, ios_base::end);
stop_pos=ifs.tellg();
ifs.seekg(224, ios_base::beg);
pos=ifs.tellg();
while(pos!=stop_pos){
if(count%104==0){
cout<<"\n";
}
ifs.read(&x,1);
printhex(x);
pos=ifs.tellg();
count++;
}
ifs.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment