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
|
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
//#pragma pack
using namespace std;
// header struct definition
struct s_header {
unsigned char verCode;
unsigned char serviceType;
unsigned short totLength;
unsigned char reserved;
unsigned char flags;
unsigned short hopCount;
unsigned long srcAddr;
unsigned long destAddr;
} fileheader;// you can make a global header variable RIGHT HERE if you want to
// string tables
char * codes[] = {
"OK",
"Possible data corruption"
"Reserved"
};
char * services[] = {
"Normal",
"Low Priority",
"High Priority",
"Medium Priority",
"So-so Priority",
"Needed Yesterday",
"Nevermind"
"Reserved"
};
char * flags[] = {
"Grumpy",
"Sneezy",
"Bashful",
"Doc",
"Dopey",
"Tipsy",
"Surly",
"Snow White"
};
int main(int argc, char * argv[]) {
char buffer[1024];
char ch;
int size, x;
ifstream myfile("PACKETS.txt", ios::in | ios::binary);
if (!myfile) {
cout << "Cannot open file.\n";
return 1;
}
myfile.read((char *)& fileheader, sizeof s_header);
size = fileheader.totLength - 32; // calculate data size
cout << "Version: " << fileheader.verCode << endl;
cout << "Code: " << fileheader.verCode << endl;
cout << "Total Length: " << fileheader.totLength << endl;
cout << "Service Type: " << fileheader.serviceType << endl;
cout << "Hop Count: " << fileheader.hopCount << endl;
cout << "Source Address: " << fileheader.srcAddr << endl;
cout << "Dest Address: " << fileheader.destAddr << endl;
cout << "Data: ";
myfile.close();
cout << endl;
system("pause");
}
|