-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_Net.cpp
81 lines (61 loc) · 2.67 KB
/
C_Net.cpp
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
//////////////////////////////////////////////////////////////////////////////////
// [ Net_Class_Source ]
//////////////////////////////////////////////////////////////////////////////////
#include "C_Net.hpp"
//////////////////////////////////////////////////////////////////////////////////
// [ start ]
//////////////////////////////////////////////////////////////////////////////////
int C_Net::start(){
if(CNInterface.create() != C_NET_INTERFACE_READY){
cout << "ERROR: CNInterface.create" << endl;
return(C_NET_ERROR);
}
return(C_NET_READY);
}
//////////////////////////////////////////////////////////////////////////////////
// [ send ]
//////////////////////////////////////////////////////////////////////////////////
int C_Net::send(const S_Net_Interface* pSInterface, S_ArpPacket* pSArp, int cPackets, int cSleep){
if(!pSInterface || !pSArp || !cPackets) return(C_NET_ERROR);
UCHAR pData[5000];
DWORD cData = 0;
CNArp.getPacket(pData, &cData, pSArp);
CNRaw.open(pSInterface);
CNRaw.start(C_NET_ID_ARP, &CA_Arp[0], C_NET_BUFFER);
usleep(50000);
for(int n = 0; n < cPackets; n++){
CNRaw.send(pData, cData);
usleep(cSleep * 1000);
}
usleep(50000);
CNRaw.stop();
CNRaw.close();
return(C_NET_READY);
}
//////////////////////////////////////////////////////////////////////////////////
// [ on_arp_data ]
//////////////////////////////////////////////////////////////////////////////////
void C_Net::on_arp_data(int id, int cData){
if(id != C_NET_ID_ARP) return;
if(cData < (int)(cETHERNET_HEADER + cARP_HEADER)) return;
ETHERNET_HEADER* pRCV_ethhdr = (ETHERNET_HEADER*)&CA_Arp[0];
ARP_HEADER* pRCV_arp = (ARP_HEADER*)(&CA_Arp[cETHERNET_HEADER]);
if(pRCV_ethhdr->Type == ETH_TYP_ARP){
if(pRCV_arp->ARP_OpCode == ARP_REQUEST){
cout << "ARP_REQUEST" << endl;
}else
if(pRCV_arp->ARP_OpCode == ARP_RESPONSE){
cout << "ARP_RESPONSE" << endl;
}
cout << "IP:" << dec
<< (int)pRCV_arp->ARP_IP_S[0] << "." << (int)pRCV_arp->ARP_IP_S[1] << "."
<< (int)pRCV_arp->ARP_IP_S[2] << "." << (int)pRCV_arp->ARP_IP_S[3] << endl;
cout << "MAC:" << hex
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[0] << ":"
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[1] << ":"
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[2] << ":"
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[3] << ":"
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[4] << ":"
<< setfill('0') << setw(2) << (int)pRCV_arp->ARP_MAC_S[5] << endl;
}
}