TCP_HEADER *pTcpHeader; pTcpHeader = (TCP_HEADER*)(pChar + sizeof(ETHDR) + (ip->h_lenver &0xf) *4); packetList[currentPktIndex].srcPort = ntohs(pTcpHeader->th_sport); packetList[currentPktIndex].desPort = ntohs(pTcpHeader->th_dport);
memcpy(packetList[currentPktIndex].data, pChar + sizeof(ETHDR) + (ip->h_lenver &0xf) *4+20, 255); packetList[currentPktIndex].data[255] = 0; break; case IPPROTO_UDP: UDP_HEADER *pUdpHeader; pUdpHeader = (UDP_HEADER*)(pChar + sizeof(ETHDR) + (ip->h_lenver &0xf) *4); packetList[currentPktIndex].srcPort = ntohs(pUdpHeader->uh_sport); packetList[currentPktIndex].desPort = ntohs(pUdpHeader->uh_dport); memcpy(packetList[currentPktIndex].data, pChar + sizeof(ETHDR) + (ip->h_lenver &0xf) *4+sizeof(UDP_HEADER), 256); packetList[currentPktIndex].data[255] = 0; break; default: packetList[currentPktIndex].data[0] = 0; break; } currentPktIndex++; currentPktIndex %= MAX_PACKET; if (currentPktIndex == 0) mailDlg->PostMessage(RECV_PKT); break; } } continue; } else if (eth->eh_type == htons(ETH_ARP)) { if (arp->arp_tpa == htonl(myip) && arp->arp_opt == htons(ARP_REPLY)) { int i; for (i = 0; i < currentHstIndex; i++) { if (hostList[i].ip == arp->arp_spa) { break; } } if (i >= currentHstIndex) { hostList[currentHstIndex].ip = arp->arp_spa; memcpy(hostList[currentHstIndex].mac, eth->eh_src, 6); currentHstIndex++; } } else if (arp->arp_spa == htonl(myip) && arp->arp_opt == htons(ARP_REPLY)) memcpy(mmac, eth->eh_src, 6); for (int i = 0; i < oldHstIndex; i++) { if ((oldHostList[i].ip == arp->arp_spa || oldHostList[i].ip == arp->arp_tpa) && oldHostList[i].sniffer == 1) { packetList[currentPktIndex].srcIp = arp->arp_spa; packetList[currentPktIndex].desIp = arp->arp_tpa; packetList[currentPktIndex].protocol = ARP; packetList[currentPktIndex].data[0] = 0;
currentPktIndex++; currentPktIndex %= MAX_PACKET; if (currentPktIndex == 0) mailDlg->PostMessage(RECV_PKT); break; } } } } }
我们需要动态追踪局域网内节点的活动状态,以定时器实现:
void CNetHackerDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if (sthread == 0)
共15页: 上一页 [1] [2] [3] [4] [5] [6] [7] 8 [9] [10] [11] [12] [13] [14] [15] 下一页
|