Repository navigation
Expand file tree
/
Copy pathcoa.cpp
More file actions
41 lines (34 loc) · 1.4 KB
/
Copy pathcoa.cpp
File metadata and controls
41 lines (34 loc) · 1.4 KB
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
// CoA / Disconnect listener (RFC 5176). Host / RAS_IP = addresses allowed to send requests.
// ./ezradius_coa <server-host-or-ip> <secret>
#include <atomic>
#include <csignal>
#include <cstdio>
#include "clsEpollReactor.h"
#include "EZCoA.h"
static std::atomic<bool> g_stop{false};
static RADIUSPacketTypeCodes onCoA(RADIUSPacketTypeCodes type, RadiusPacket &request, EZResponse &response, void *)
{
printf("%s user=[%s] session=[%s]\n", request.getCodeDescription((unsigned char)type),
request.getAttribute(USER_NAME).strValue.c_str(), request.getAttribute(ACCT_SESSION_ID).strValue.c_str());
// identify the session in the answer
response.AddAttribute(USER_NAME, request.getAttribute(USER_NAME).strValue.c_str());
response.AddAttribute(ACCT_SESSION_ID, request.getAttribute(ACCT_SESSION_ID).strValue.c_str());
return type == DISCONNECT_REQUEST ? DISCONNECT_ACK : COA_ACK;
}
int main(int argc, char **argv)
{
EZClientSettings settings;
settings.Host = argc > 1 ? argv[1] : "127.0.0.1";
settings.Secret = argc > 2 ? argv[2] : "change-me";
settings.CoAPort = 3799;
signal(SIGINT, [](int){ g_stop = true; });
netrector::EpollReactor reactor(0, 64);
EZCoA coa(&reactor, settings);
coa.SetGetRequests(onCoA, nullptr);
if(!coa.Start()){
fprintf(stderr, "can not bind the CoA port\n");
return 1;
}
reactor.run(g_stop);
return 0;
}