1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| int CSnifferDlg::Sniffer_updateList(struct pcap_pkthdr *data_header, struct data_packet *data, const u_char *pkt_data) { u_char *data_packet_list; data_packet_list = (u_char*)malloc(data_header->len); memcpy(data_packet_list, pkt_data, data_header->len); this->m_localDataList.AddTail(data); this->m_netDataList.AddTail(data_packet_list); data->len = data_header->len; time_t local_tv_sec = data_header->ts.tv_sec; struct tm *ltime = localtime(&local_tv_sec); data->time[0] = ltime->tm_year + 1900; data->time[1] = ltime->tm_mon + 1; data->time[2] = ltime->tm_mday; data->time[3] = ltime->tm_hour; data->time[4] = ltime->tm_min; data->time[5] = ltime->tm_sec;
CString buffer; buffer.Format("%d", this->packetNum); int nextItem = this->m_listCtrl.InsertItem(this->packetNum, buffer); CString timestr; timestr.Format("%d/%d/%d %d:%d:%d", data->time[0], data->time[1], data->time[2], data->time[3], data->time[4], data->time[5]); this->m_listCtrl.SetItemText(nextItem, 1, timestr); buffer.Empty(); buffer.Format("%d", data->len); this->m_listCtrl.SetItemText(nextItem, 2, buffer); buffer.Empty(); buffer.Format("%02X-%02X-%02X-%02X-%02X-%02X", data->ethh->src[0], data->ethh->src[1], data->ethh->src[2], data->ethh->src[3], data->ethh->src[4], data->ethh->src[5]); this->m_listCtrl.SetItemText(nextItem, 3, buffer); buffer.Empty(); buffer.Format("%02X-%02X-%02X-%02X-%02X-%02X", data->ethh->dest[0], data->ethh->dest[1], data->ethh->dest[2], data->ethh->dest[3], data->ethh->dest[4], data->ethh->dest[5]); this->m_listCtrl.SetItemText(nextItem, 4, buffer); this->m_listCtrl.SetItemText(nextItem, 5, CString(data->type)); buffer.Empty(); if (data->ethh->type == PROTO_ARP) { buffer.Format("%d.%d.%d.%d", data->arph->src_ip[0], data->arph->src_ip[1], data->arph->src_ip[2], data->arph->src_ip[3]); } else if (data->ethh->type == PROTO_IP_V4) { struct in_addr in; in.S_un.S_addr = data->ip4h->src_addr; buffer = CString(inet_ntoa(in)); } else if (data->ethh->type == PROTO_IP_V6) { for (int i = 0; i < 8; i++) { if (i <= 6) buffer.AppendFormat("%02x:", data->ip6h->src_addr[i]); else buffer.AppendFormat("%02x", data->ip6h->src_addr[i]); } } this->m_listCtrl.SetItemText(nextItem, 6, buffer); buffer.Empty(); if (data->ethh->type == PROTO_ARP) { buffer.Format("%d.%d.%d.%d", data->arph->dest_ip[0], data->arph->dest_ip[1], data->arph->dest_ip[2], data->arph->dest_ip[3]); } else if (data->ethh->type == PROTO_IP_V4) { struct in_addr in; in.S_un.S_addr = data->ip4h->dest_addr; buffer = CString(inet_ntoa(in)); } else if (data->ethh->type == PROTO_IP_V6) { for (int i = 0; i < 8; i++) { if (i <= 6) buffer.AppendFormat("%02x:", data->ip6h->dest_addr[i]); else buffer.AppendFormat("%02x", data->ip6h->dest_addr[i]); } } this->m_listCtrl.SetItemText(nextItem, 7, buffer); this->packetNum++; return 1; }
|