m_hostList.SetText(i + 1, 5, "OFF"); }
m_hostList.Invalidate();
上述代码的思路是给fromip~min(myip-1,toip),myip+1~toip范围内的主机发送ARP请求报文并监控其ARP回复,从而获得其IP与MAC的对应关系。当然,它首先用了同样的原理来获取本机的MAC地址。
为了在表格的垂直滚动条滚动时正确的设置滚动条的位置和显示正确的主机列表,我们应该给XTable添加垂直滚动条消息处理函数:
void XTable::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { // TODO: Add your message handler code here and/or call default static UINT nVWndPos = 0; switch (nSBCode) { case SB_LINEDOWN: case SB_PAGEDOWN: nPos = nVWndPos + 13; SetScrollPos(SB_VERT, nPos); nVWndPos = nPos; break; case SB_LINEUP: case SB_PAGEUP: nPos = nVWndPos - 13; SetScrollPos(SB_VERT, nPos); nVWndPos = nPos; break; case SB_THUMBTRACK: SetScrollPos(SB_VERT, nPos); nVWndPos = nPos; break; }
for (int i = nVWndPos / 13, j = 0; i < currentHstIndex; i++, j++) { CString str; SetText(j + 1, 0, inet_ntoa(*(struct in_addr*)(&(hostList[i].ip))));
if (hostList[i].sniffer == 0) SetText(j + 1, 2, "OFF"); else SetText(j + 1, 2, "ON");
str.Format("%02x-%02x-%02x-%02x-%02x-%02x", hostList[i].mac[0], hostList[i].mac[1], hostList[i].mac[2], hostList[i].mac[3], hostList[i].mac[4], hostList[i].mac[5]); SetText(i + 1, 1, str);
if (hostList[i].arpCheat == 0) SetText(j + 1, 3, "OFF"); else SetText(j + 1, 3, "ON"); if (hostList[i].ipConflict == 0) SetText(j + 1, 4, "OFF"); else SetText(j + 1, 4, "ON"); } for (; j < MAX_HOST; j++) { for (int k = 0; k < 5; k++) SetText(j + 1, k, ""); }
Invalidate();
CWnd::OnVScroll(nSBCode, nPos, pScrollBar); }
上述程序依赖于监控(sniffer)相关代码,核心代码如下:
DWORD WINAPI Sniff(void *p) { char recvbuf[1024 *250];
memset(packetList, 0, MAX_PACKET *sizeof(PacketList)); if (PacketSetHwFilter(lpadapter, NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE)
共15页: 上一页 [1] [2] [3] [4] [5] 6 [7] [8] [9] [10] [11] [12] [13] [14] [15] 下一页
|