blob: c5b01cfa2e4111b6ce52e7d1c43231ff85607c63 (
plain)
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
|
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <perfdhcp/perf_socket.h>
#include <dhcp/iface_mgr.h>
#include <boost/foreach.hpp>
using namespace isc::dhcp;
namespace isc {
namespace perfdhcp {
PerfSocket::PerfSocket(const int socket) :
SocketInfo(asiolink::IOAddress("127.0.0.1"), 0, socket),
ifindex_(0), valid_(true) {
try {
initSocketData();
} catch (const Exception&) {
valid_ = false;
}
}
PerfSocket::~PerfSocket() {
IfacePtr iface = IfaceMgr::instance().getIface(ifindex_);
if (iface) {
iface->delSocket(sockfd_);
}
}
void
PerfSocket::initSocketData() {
BOOST_FOREACH(IfacePtr iface, IfaceMgr::instance().getIfaces()) {
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
if (s.sockfd_ == sockfd_) {
ifindex_ = iface->getIndex();
addr_ = s.addr_;
return;
}
}
}
isc_throw(BadValue, "interface for specified socket descriptor not found");
}
}
}
|