📄 pppmessager.cpp
字号:
# // PppMessager.cpp : Defines the class behaviors for the application.
# //
#
# #include "stdafx.h"
# #include "PppMessager.h"
# #include "PppMessagerDlg.h"
# #include "Protocol.h"
# #include "UserMessage.h"
#
# #ifdef _DEBUG
# #define new DEBUG_NEW
# #undef THIS_FILE
# static char THIS_FILE[] = __FILE__;
# #endif
#
# unsigned int SendPacketThread(LPVOID lpParam);
# unsigned int RecvPacketThread(LPVOID lpParam);
#
# /////////////////////////////////////////////////////////////////////////////
# // CPppMessagerApp
#
# BEGIN_MESSAGE_MAP(CPppMessagerApp, CWinApp)
# //{{AFX_MSG_MAP(CPppMessagerApp)
# // NOTE - the ClassWizard will add and remove mapping macros here.
# // DO NOT EDIT what you see in these blocks of generated code!
# //}}AFX_MSG
# ON_COMMAND(ID_HELP, CWinApp::OnHelp)
# END_MESSAGE_MAP()
#
# /////////////////////////////////////////////////////////////////////////////
# // CPppMessagerApp construction
#
# CPppMessagerApp::CPppMessagerApp()
# {
# // TODO: add construction code here,
# // Place all significant initialization in InitInstance
# }
#
# /////////////////////////////////////////////////////////////////////////////
# // The one and only CPppMessagerApp object
#
# CPppMessagerApp theApp;
#
# /////////////////////////////////////////////////////////////////////////////
# // CPppMessagerApp initialization
#
# BOOL CPppMessagerApp::InitInstance()
# {
# AfxEnableControlContainer();
#
# // Standard initialization
# // If you are not using these features and wish to reduce the size
# // of your final executable, you should remove from the following
# // the specific initialization routines you do not need.
#
# #ifdef _AFXDLL
# Enable3dControls(); // Call this when using MFC in a shared DLL
# #else
# Enable3dControlsStatic(); // Call this when linking to MFC statically
# #endif
# Protocol Messager;//Create a messager.
# CWinThread * pWinThread = NULL;
# DWORD dwSendThreadId, dwRecvThreadId;
#
# CPppMessagerDlg MainDlg;
# m_pMainWnd = &MainDlg;
#
# //Init Messager.
# Messager.InitProtocol();
#
# //Create new thread for sending icmp packet.
# pWinThread = AfxBeginThread(SendPacketThread, &Messager, THREAD_PRIORITY_NORMAL, 0, 0 \
# , NULL);
# dwSendThreadId = pWinThread->m_nThreadID;
#
# //Create new thread for recving imcp packet.
# pWinThread = AfxBeginThread(RecvPacketThread, &Messager, THREAD_PRIORITY_NORMAL, 0, 0 \
# , NULL);
# dwRecvThreadId = pWinThread->m_nThreadID;
#
# //Load dwSendThreadId and dwRecvThreadId to main dialog setings.
# MainDlg.LoadPacketHandlerId(dwSendThreadId, dwRecvThreadId);
#
#
# int nResponse = MainDlg.DoModal();
# if (nResponse == IDOK)
# {
# // TODO: Place code here to handle when the dialog is
# // dismissed with OK
# }
# else if (nResponse == IDCANCEL)
# {
# // TODO: Place code here to handle when the dialog is
# // dismissed with Cancel
# }
#
#
# return FALSE;
# }
#
#
#
# //////////////////////////////////////////////////////////////////////////////
# //
# // Description: This thread is used to send packet passed by main thread.
# //
# // Argument: lpParam ---- The param passed by AfxBeignThread function.
# //
# // ReturnValue: uiExitCode ---- The exit code of this thread.
# //
# // Comment: None.
# //
# /////////////////////////////////////////////////////////////////////////////
# unsigned int SendPacketThread(LPVOID lpParam)
# {
# unsigned int uiExitCode = 0;
# Protocol * pMessager = NULL;
# HWND hMainDlg = NULL;
# USER_DATA * pUserData = NULL;
# MSG Msg;
#
# int nBytes;
# //char test[50];
#
# //Get messager address.
# pMessager = (Protocol *)lpParam;
#
# while(1)
# {
# //Get message from message queue.
# memset(&Msg, 0, sizeof(Msg));
# PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE);
#
# //Handle the received message.
# if(MAIN_TH_MWIN_ANNOUNCE_HANDLE == Msg.message)
# {
# hMainDlg = (HWND)(Msg.wParam);
# }
# else if(MAIN_TH_MWIN_SEND_MESSAGE == Msg.message)
# {
# pUserData = (USER_DATA *)Msg.wParam;
# nBytes = pMessager->SendIcmpPacket(pUserData->pcData, pUserData->nDataLen \
# , ICMP_ECHOREPLY, pUserData->pcDestIpAddr);
# }
#
# //Sleep(1000);
# }
#
# return uiExitCode;
# }
#
#
#
# //////////////////////////////////////////////////////////////////////////////
# //
# // Description: This thread is used to recevie packet from raw socket.
# //
# // Argument: lpParam ---- The param passed by AfxBeginThread.
# //
# // ReturnValue: The exit code of this thread.
# //
# // Comment: None.
# //
# /////////////////////////////////////////////////////////////////////////////
# unsigned int RecvPacketThread(LPVOID lpParam)
# {
# unsigned int uiExitCode = 0;
# MSG Msg;
# Protocol * pMessager = NULL;
# HWND hMainDlg = NULL;
# int nBytes;
# char pcDataBuffer[5000];
#
# pMessager = (Protocol *)lpParam;
#
# while(1)
# {
# //Get message from local message queue.
# memset(&Msg, 0, sizeof(Msg));
# PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE);
#
# //Handle message.
# if(MAIN_TH_MWIN_ANNOUNCE_HANDLE == Msg.message)
# {
# hMainDlg = (HWND)Msg.wParam;
# }
#
#
# //Receive packet from messager.
# memset(pcDataBuffer, 0, sizeof(pcDataBuffer));
# nBytes = pMessager->RecvIcmpPacket(pcDataBuffer, sizeof(pcDataBuffer), 0);
#
# if(nBytes != -1)
# {
# //Post the packet to main dlg of main thread.
# SendMessage(hMainDlg, RECV_TH_ANNOUNCE_RECV_MESSAGE, (WPARAM)pcDataBuffer \
# , (LPARAM)nBytes);
# }
#
# //Sleep(1000);
#
# }
#
# return uiExitCode;
# }
#
#
# //Not finish commuication between maindlg and recv or send thread.
# //Add listcontrol is used to test. and send packet thread is not tested.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -