-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheapclient.cpp
74 lines (64 loc) · 2.1 KB
/
eapclient.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
/*
eapclient.cpp: implementation for pure eap client
Copyright (C) 2014 C.C.<[email protected]>
This file is part of ccnt.
ccnt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ccnt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ccnt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "eapclient.h"
EAPClient::EAPClient(EAPOption *opt,pcap_t *pdev):_option(opt),_pcapdev(pdev),
_start_packet(nullptr),_logoff_packet(nullptr),_response_packet{nullptr,nullptr,nullptr},
_start_length(0),_logoff_length(0),_response_length{0,0,0}
{}
EAPClient::~EAPClient()
{
pcap_close(_pcapdev);
delete[] _response_packet[2];
delete[] _response_packet[1];
delete[] _response_packet[0];
delete[] _logoff_packet;
delete[] _start_packet;
_start_packet=nullptr;
_logoff_packet=nullptr;
_response_packet[0]=nullptr;
_response_packet[1]=nullptr;
_response_packet[2]=nullptr;
}
void EAPClient::start() throw(eap_runtime_error)
{
if (pcap_sendpacket(_pcapdev,_start_packet,_start_length) !=0)
{
throw eap_runtime_error("ERROR when sending EAPOL-Start:pcap_sendpacket");
}
}
void EAPClient::logoff() throw(eap_runtime_error)
{
if (pcap_sendpacket(_pcapdev,_logoff_packet,_logoff_length) !=0)
{
throw eap_runtime_error("ERROR when sending EAPOL-Logoff:pcap_sendpacket");
}
}
void EAPClient::packet_loop() throw(eap_error)
{
struct pcap_pkthdr *header;
uint8_t *pkt_data;
int ret=-1;
while(0<=(ret=pcap_next_ex(_pcapdev,&header,const_cast<const u_char**>(&pkt_data))))
{
if(ret==0){ continue; }
try{
packet_handler(pkt_data);
}
catch(eap_error&){
throw;
}
}
}