![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef IP_TRACE_TRACECOLLECTOR_HPP 00029 #define IP_TRACE_TRACECOLLECTOR_HPP 00030 00031 #include <IP/trace/PacketTrace.hpp> 00032 00033 #include <fstream> 00034 #include <list> 00035 00036 namespace ip { namespace trace { 00037 00038 typedef struct pcap_hdr_s { 00039 unsigned long int magic_number; /* magic number */ 00040 uint16_t version_major; /* major version number */ 00041 uint16_t version_minor; /* minor version number */ 00042 long int thiszone; /* GMT to local correction */ 00043 unsigned long int sigfigs; /* accuracy of timestamps */ 00044 unsigned long int snaplen; /* max length of captured packets, in octets */ 00045 unsigned long int network; /* data link type */ 00046 } pcap_hdr_t; 00047 00048 typedef struct packet_hdr_s { 00049 unsigned long int timestamp; 00050 unsigned long int microseconds; 00051 unsigned long int includedNumOctets; 00052 unsigned long int origNumOctets; 00053 } packet_hdr_t; 00054 00055 typedef struct mac_hdr_s { 00056 uint8_t destination[6]; 00057 uint8_t source[6]; 00058 uint16_t type; 00059 } mac_hdr_t; 00060 00061 typedef struct ip_hdr_s { 00062 uint8_t versionAndLength; 00063 uint8_t typeOfService; 00064 uint16_t totalLength; 00065 uint16_t identification; 00066 uint16_t flagsAndOffset; 00067 uint8_t ttl; 00068 uint8_t protocol; 00069 uint16_t checksum; 00070 unsigned long int sourceAddress; 00071 unsigned long int destinationAddress; 00072 } ip_hdr_t; 00073 00074 typedef struct tcp_hdr_s { 00075 uint16_t source_port; 00076 uint16_t destination_port; 00077 unsigned long int sequenceNumber; 00078 unsigned long int ackNumber; 00079 uint16_t flags; // Header length 6 highest 4 bit 00080 uint16_t window; 00081 uint16_t checksum; 00082 uint16_t urgentPointer; 00083 00084 } tcp_hdr_t; 00085 00086 00087 typedef std::list<PacketTrace> PacketTraceContainer; 00088 00089 class TraceCollector 00090 { 00091 public: 00092 00093 TraceCollector(std::string filename); 00094 00095 ~TraceCollector() {}; 00096 00097 void 00098 addPacketTrace(PacketTrace pt); 00099 00100 bool 00101 hasSomethingToWrite() const; 00102 00103 void 00104 write(); 00105 00106 private: 00107 00108 void 00109 writeFileHeader(std::ofstream& theFile); 00110 00111 void 00112 writePacket(std::ofstream& theFile, const PacketTrace& pt); 00113 00114 uint16_t 00115 ipChecksum(ip_hdr_t ipHeader); 00116 00117 uint16_t 00118 reverse16(const uint16_t orig); 00119 00120 unsigned long int 00121 reverse32(const unsigned long int orig); 00122 00123 std::string filename; 00124 00125 int counter; 00126 00127 bool writeHeader; 00128 00129 PacketTraceContainer ptc; 00130 00131 }; 00132 00133 00134 } // trace 00135 } // ip 00136 00137 #endif // IP_TRACE_TRACECOLLECTOR_HPP
1.5.5