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

📄 ipmonitorview.cpp

📁 WMD驱动编程,本人收集整理的10多个例子和编程环境配置文档,特别是8139驱动,加了许多说明,并测试通过.
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
//
//	(C) Copyright 1999 - 2000 Mark Roddy
//	All Rights Reserved
//
//	Hollis Technology Solutions
//	94 Dow Road
//	Hollis, NH 03049
//	info@hollistech.com
//
//	Synopsis: 
// 
//
//	Version Information:
//
//	$Header: /iphook/usr/IpMonitor/IpMonitorView.cpp 3     1/27/00 10:35p Markr $ 
//
///////////////////////////////////////////////////////////////////////////////
// IpMonitorView.cpp : implementation of the CIpMonitorView class
//

#include "stdafx.h"
#include "IpMonitor.h"

#include "IpMonitorDoc.h"
#include "IpMonitorView.h"
#include "Mainfrm.h"
#include "winsock2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView

IMPLEMENT_DYNCREATE(CIpMonitorView, CListView)

BEGIN_MESSAGE_MAP(CIpMonitorView, CListView)
	//{{AFX_MSG_MAP(CIpMonitorView)
	ON_WM_CREATE()
	ON_MESSAGE(BUFFER_AVAILABLE_MSG, OnBufferMessage)
	ON_COMMAND(ID_DOC_CLEAR, OnDocClear)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView construction/destruction

CIpMonitorView::CIpMonitorView()
{
	m_dwDefaultStyle |= LVS_REPORT;
	theApp.m_theView = this;

}

CIpMonitorView::~CIpMonitorView()
{
}

BOOL CIpMonitorView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.style |= LVS_REPORT;


	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView drawing

void CIpMonitorView::OnDraw(CDC* pDC)
{
	CIpMonitorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView printing

BOOL CIpMonitorView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CIpMonitorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CIpMonitorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView diagnostics

#ifdef _DEBUG
void CIpMonitorView::AssertValid() const
{
	CListView::AssertValid();
}

void CIpMonitorView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

CIpMonitorDoc* CIpMonitorView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CIpMonitorDoc)));
	return (CIpMonitorDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CIpMonitorView message handlers

void CIpMonitorView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	// this code only works for a report-mode list view
	ASSERT(GetStyle() & LVS_REPORT);

	// Gain a reference to the list control itself
	CListCtrl& theCtrl = GetListCtrl();

	// Insert a column. This override is the most convenient.
	theCtrl.InsertColumn(0, _T("TIME                        "), LVCFMT_LEFT);

	// The other InsertColumn() override requires an initialized
	// LVCOLUMN structure.
	LVCOLUMN col;

	col.mask = LVCF_FMT | LVCF_TEXT;
	col.pszText = _T("SEQ      ");
	col.fmt = LVCFMT_LEFT;
	theCtrl.InsertColumn(1, &col);

	col.mask = LVCF_FMT | LVCF_TEXT;
	col.pszText = _T("S/R");
	col.fmt = LVCFMT_LEFT;
	theCtrl.InsertColumn(2, &col);

	col.mask = LVCF_FMT | LVCF_TEXT;
	col.pszText = _T("IP HEADER                                            ");
	col.fmt = LVCFMT_LEFT;
	theCtrl.InsertColumn(3, &col);

	//
	// this last column is just and 'end of row marker'.
	//
	col.mask = LVCF_FMT | LVCF_TEXT;
	col.pszText = _T("");
	col.fmt = LVCFMT_LEFT;
	theCtrl.InsertColumn(4, &col);

	// Set reasonable widths for our columns
	theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
	theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
	theCtrl.SetColumnWidth(2, LVSCW_AUTOSIZE_USEHEADER);
	theCtrl.SetColumnWidth(3, LVSCW_AUTOSIZE_USEHEADER);
	theCtrl.SetColumnWidth(4, 0);
}


void CIpMonitorView::displayContents(IPHOOK_DATA * data)
{
	if (!validIpHookData(data)) {

		return;
	}

	LVITEM item;
	CString msg;
	CString docItem;
	//
	// time 
	//
	msg.Format(_T("%016.16I64x"), data->timestamp);

	LPTSTR  tbuf = msg.LockBuffer();

	item.mask		= LVIF_TEXT | LVIF_PARAM;
	item.iItem		= 0x7FFFFFFF;
	item.iSubItem	= 0;
	item.pszText	= tbuf;
	item.cchTextMax	= _tcslen( item.pszText ) + 1;
	item.lParam		= 0;

	int row = GetListCtrl().InsertItem(&item);

	if (row == -1) {

		AfxErrorMessageBox(CString(_T("InsertItem failed")), 0);

		return;
	}

	msg.UnlockBuffer();

	docItem = msg;

	msg.Format("%08.8x", data->sequence);

	tbuf = msg.LockBuffer();

	GetListCtrl().SetItemText(row, 1, tbuf);

	msg.UnlockBuffer();

	docItem += CString(" ") + msg;

	//
	// S/R
	//
	if (data->direction) {

		msg = _T(" R ");

	} else {

		msg = _T(" S ");

	}

	tbuf = msg.LockBuffer();

	GetListCtrl().SetItemText(row, 2, tbuf);

	msg.UnlockBuffer();

	docItem += CString(" ") + msg;

	//
	// IP Header
	//
	msg.Format(
		_T("VL: %02.2x TOS: %02.2x LEN: %04.4x ID: %04.4x OFF: %04.4x TTL: %02.2x  PROT: %02.2x SRC: %08.8x DEST: %08.8x"),
		data->header.iph_verlen,
		data->header.iph_tos,
		ntohs(data->header.iph_length),
		ntohs(data->header.iph_id),
		ntohs(data->header.iph_offset),
		data->header.iph_ttl,
		data->header.iph_protocol,
		ntohl(data->header.iph_src),
		ntohl(data->header.iph_dest));

	tbuf = msg.LockBuffer();

	GetListCtrl().SetItemText(row, 3, tbuf);

	msg.UnlockBuffer();

	docItem += CString(" ") + msg;

	if (theApp.m_theDoc) {

		theApp.m_theDoc->addItem(docItem);
	}

}


int CIpMonitorView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	lpCreateStruct->style |= LVS_REPORT;

	if (CListView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	return 0;
}

afx_msg LRESULT CIpMonitorView::OnBufferMessage(WPARAM wParam, LPARAM lParam)
{
	IPHOOK_BUFFER * buffer = (IPHOOK_BUFFER * )wParam;

	UCHAR * rawBuffer = (UCHAR *) buffer;

	if (!validIpHookBuffer(buffer)) {

		delete[] rawBuffer;

		rawBuffer = NULL;

		return 0;

	}
	//
	// lets just assume that it is valid? not!
	//
	if (buffer->valid > buffer->entries) {

		delete[] rawBuffer;

		return 0;
	}

	//
	// display the contents
	//
	for (UINT index = 0; index < buffer->valid; index++) {

		displayContents(&buffer->buffer[index]);

	}
	//
	// delete the buffer
	//	

	delete[] rawBuffer;

	//
	// if scrolling is enabled, make the last item visible
	//
	// Ensure that the last item is visible.
	//
	int nCount = GetListCtrl().GetItemCount();
	if (nCount > 0) {
   
		GetListCtrl().EnsureVisible( nCount -1, FALSE );
	}


	return 0;
}



void CIpMonitorView::reInitView()
{

	GetListCtrl().DeleteAllItems();

}

void CIpMonitorView::OnDocClear() 
{
	reInitView();
	
}
///////////////////////////////////////////////////////////////////////////////
// 
// Change History Log
//
// $Log: /iphook/usr/IpMonitor/IpMonitorView.cpp $
// 
// 3     1/27/00 10:35p Markr
// Prepare to release!
//
///////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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