⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capfilereader.h

📁 众所周知
💻 H
字号:
/*****************************************************************************\
FileName: CapFileReader.h
Purpose: 读取Cap文件
Author: Ahfu, ah_fu126@hotmail.com
Comment: 
Create At: 2006-12-27
\*****************************************************************************/
#ifndef _CAP_FILE_READER_H_
#define _CAP_FILE_READER_H_

#include <stdio.h>
#include <assert.h>
#include <time.h>
#include "IP.h"
#include <string.h>



#ifdef _DEBUG
	#define DEBUG_WRITE(str) printf(str)   /*输出调试信息,正式版本可关闭*/
	#define DEBUG_WRITE1(str, p1) printf((str), (p1))
	#define DEBUG_WRITE2(str, p1, p2) printf((str), (p1), (p2))
	#define DEBUG_WRITE3(str, p1, p2, p3) printf((str), (p1), (p2), (p3))
#else
	#define DEBUG_WRITE(str) /*printf(str)*/
	#define DEBUG_WRITE1(str, p1) /*printf((str), (p1))*/
	#define DEBUG_WRITE2(str, p1, p2) /*printf((str), (p1), (p2))*/
	#define DEBUG_WRITE3(str, p1, p2, p3) /*printf((str), (p1), (p2), (p3))*/
#endif

class CapFileReader
{
public:
	CapFileReader(void);
	~CapFileReader(void);
	bool Open(const char* CapFile);
	bool Read();
	void Close();
	inline unsigned short DataLength() const;
	bool GetSourceMacAddr(char* Buffer, int Length);
	bool GetDestMacAddr(char* Buffer, int Length);
	bool GetIPHeader(IP_HEADER& ip);
	bool GetIPData(int HeadLen, char* Buffer, int Length);
	bool GetInternetData(char* Buffer, int Length);
	inline time_t GetStartTime() const;
	inline unsigned int GetMicroSecond() const;
	inline unsigned short GetInternetProtocol() const;
private:
	CapFileReader(const CapFileReader& rsh);
	CapFileReader& operator=(const CapFileReader& rsh);
//-----------------------------------------------------------------------------
protected:

private:  //types
	enum
	{
		SPLIT_SEG_LEN = 40,  //分隔段的长度
		FILE_HEADER = 128  //文件头的长度
	};
private:
	FILE* m_fp;
	int m_CurPos;
	int m_NextPos;
	bool m_IsOpen;
	unsigned short m_DataLength;
	time_t m_StartTime;
	unsigned int m_MicroSecond;
	unsigned short m_Protocol;
};

unsigned short CapFileReader::DataLength() const
{
	return m_DataLength;
}

time_t CapFileReader::GetStartTime() const
{
	return m_StartTime;
}

unsigned int CapFileReader::GetMicroSecond() const
{
	return m_MicroSecond;
}

unsigned short CapFileReader::GetInternetProtocol() const
{
	return m_Protocol;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -