📄 icmpprotocoldlg.cpp
字号:
return colno;
}
//////////////////////////////////////////
// //
// Update Trace List Display //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::UpdateTrace()
{
CString IPAddressMessage;
CString TripTimeMessage;
CString SeqMessage;
CString HostMessage;
if (PingSocket.rcvSockAddr.sin_addr.s_addr == NULL)
{
IPAddressMessage = "***********";
HostMessage.Format("**** No response (TTL = %ld)",
PingSocket.icmpCurSeq);
TripTimeMessage = "*";
}
else
{
TripTimeMessage.Format("%ld",
PingSocket.icmpRoundTripTime);
IPAddressMessage.Format("%s",
inet_ntoa(PingSocket.rcvSockAddr.sin_addr));
HostMessage.Format("%s",
inet_ntoa(PingSocket.rcvSockAddr.sin_addr));
}
SeqMessage.Format ("%ld",
PingSocket.icmpCurSeq);
DisplayTrace (TripTimeMessage,
IPAddressMessage,
HostMessage);
}
//////////////////////////////////////////
// //
// Display Trace //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::DisplayTrace(LPCSTR TripTimeMessage, LPCSTR IPAddressMessage, LPCSTR HostMessage)
{
int ItemNumber;
ItemNumber = m_ctlTraceList.GetItemCount();
if (ItemNumber > 0)
ItemNumber--;
SetDisplayImage (ItemNumber, Icon_Blank);
m_ctlTraceList.SetItemText(ItemNumber, 1, TripTimeMessage);
m_ctlTraceList.SetItemText(ItemNumber, 2, IPAddressMessage);
m_ctlTraceList.SetItemText(ItemNumber, 3, HostMessage);
}
//////////////////////////////////////////
// //
// Set Display Image //
// //
// Set the selected icon in the //
// trace list box and set the //
// focus to it. //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::SetDisplayImage(int FocusItem, ImageType FocusImage)
{
LV_ITEM TraceItem;
TraceItem.iItem = FocusItem;
TraceItem.iSubItem = 0;
TraceItem.mask = LVIF_IMAGE;
TraceItem.iImage = FocusImage;
m_ctlTraceList.SetItem (&TraceItem);
}
//////////////////////////////////////////
// //
// Set Trace Focus //
// //
// Set the focus to the TraceList //
// item and exit. //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::SetTraceFocus(int FocusItem, int FocusSubItem)
{
LV_ITEM TraceItem;
TraceItem.iItem = FocusItem;
TraceItem.iSubItem = FocusSubItem;
TraceItem.mask = LVIF_STATE;
TraceItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
m_ctlTraceList.SetItem (&TraceItem);
m_ctlTraceList.EnsureVisible (FocusItem, FALSE);
}
//////////////////////////////////////////
// //
// Set Trace Sequence //
// //
// Output the current sequence number //
// set focus, and exit. //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::SetTraceSequence(int Seq, int FocusItem, ImageType FocusImage)
{
CString SeqMessage;
SeqMessage.Format ("%ld", Seq);
m_ctlTraceList.InsertItem (FocusItem, SeqMessage, FocusImage);
SetTraceFocus (FocusItem, 0);
}
//////////////////////////////////////////
// //
// Display Blank Line //
// //
// Display a blank line and exit. //
// //
//////////////////////////////////////////
void CICMPProtocolDlg::DisplayBlankLine(void)
{
int FocusItem;
FocusItem = m_ctlTraceList.GetItemCount();
if (FocusItem != 0)
{
m_ctlTraceList.InsertItem (FocusItem, " ", Icon_Blank);
SetTraceFocus (FocusItem, 0);
}
}
//////////////////////////////////////////
// //
// Trace Comment //
// //
// Output the comment at the current //
// display line, set focus and exit. //
// //
//////////////////////////////////////////
//插入TRACE信息
void CICMPProtocolDlg::TraceComment(CString Comment)
{
m_ctlTraceList.InsertItem (m_ctlTraceList.GetItemCount(),
"",
Icon_BlueArrow);
SetTraceFocus (m_ctlTraceList.GetItemCount()-1,
0);
DisplayTrace ("", "", Comment);
}
//////////////////////////////////////////////////////////////////////////
// //
// REGISTRY LOAD AND SAVE SECTION //
// //
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// //
// Get a raw socket and set message processor //
// Return TRUE if Icmp object allocated //
// //
//////////////////////////////////////////////////////////
//初始化SOCKET
BOOL CICMPProtocolDlg::InitSockets()
{
if (!PingSocket.OpenNewSocket(GetSafeHwnd(),
WSA_PING_ASYNC,
FD_READ | FD_WRITE,
AF_INET,
SOCK_RAW,
IPPROTO_ICMP))
{
PingSocket.DisplayError ("WSA_PING_ASYNC",
"CICMPProtocolDlg::InitSockets");
return FALSE;
}
return TRUE;
}
//////////////////////////////////////////////////////////
// //
// Get Windows Winsock settings from Registry //
// //
//////////////////////////////////////////////////////////
BOOL CICMPProtocolDlg::FetchWinsockSettings()
{
SysTCPIP STcpIp;
if (!STcpIp.WinsockVersion(&wsaData))
{
MessageBox ("No valid winsock.dll detected",
"CICMPProtocolDlg::OnInitDialog",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
if (!STcpIp.GetLocalHostName (&m_strLocalHost))
{
gethostname(CurrentHostName, MAXHOSTNAME);
}
else
{
memcpy (CurrentHostName, m_strLocalHost, m_strLocalHost.GetLength());
CurrentHostName[m_strLocalHost.GetLength()] = 0;
}
m_strLocalHost = CurrentHostName;
if (!STcpIp.GetDomainName(&LocalDomainName))
LocalDomainName = "";
m_strLocalHost += "." + LocalDomainName;
memcpy (CurrentHostName, m_strLocalHost, m_strLocalHost.GetLength());
CurrentHostName[m_strLocalHost.GetLength()] = 0;
if (!STcpIp.GetNSName (&LocalNameServer))
LocalNameServer = "";
m_strNameServer = "Name Server: " + LocalNameServer;
SetDlgItemText (IDC_LocalHost, m_strLocalHost);
SetDlgItemText (IDC_NameServer, m_strNameServer);
LoadRegValues();
SetDlgItemText (IDC_DEST, HostName);
return TRUE;
}
//////////////////////////////////////////
// //
// Load operating options //
// //
//////////////////////////////////////////
BOOL CICMPProtocolDlg::LoadRegValues(void)
{
RegKey hKey;
DWORD dwType;
icmpDataLen = 64;
memcpy (HostName, CurrentHostName, MAXHOSTNAME);
PingSocket.icmpPingTimer = 3000;
PingSocket.icmpMaxHops = 30;
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
&icmpDataLen,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
icmpDataLen,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""BufferSize""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
&PingSocket.icmpPingTimer,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
PingSocket.icmpPingTimer,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""PingTimeout""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
&PingSocket.icmpMaxHops,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
PingSocket.icmpMaxHops,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""MaxHops""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
&DefHost,
&dwType))
{
DefHost = HostName;
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
HostName,
REG_SZ))
{
MessageBox ("Unable to access registry entry for ""DefaultHost""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
memcpy (HostName, DefHost, DefHost.GetLength());
HostName[DefHost.GetLength()] = 0;
return TRUE;
} // End LoadRegValues
//////////////////////////////////////////////
// //
// Save updated operating options //
// //
//////////////////////////////////////////////
void CICMPProtocolDlg::SaveRegValues()
{
RegKey hKey;
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
icmpDataLen,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""BufferSize""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
PingSocket.icmpPingTimer,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""PingTimeout""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
PingSocket.icmpMaxHops,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""MaxHops""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
DefHost,
REG_SZ))
{
MessageBox ("Unable to access registry entry for ""DefaultHost""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
} // End SaveRegValues
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -