summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcp/tests/pkt_filter_test_stub.cc
blob: 7e87af504e78ef66d7e9bd994a60b29d10693dc6 (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
53
54
55
56
57
// Copyright (C) 2014-2022 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 <config.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include <dhcp/tests/pkt_filter_test_stub.h>

namespace isc {
namespace dhcp {
namespace test {

PktFilterTestStub::PktFilterTestStub()
    : direct_response_supported_(true), open_socket_callback_() {
}

bool
PktFilterTestStub::isDirectResponseSupported() const {
    return (direct_response_supported_);
}

SocketInfo
PktFilterTestStub::openSocket(Iface&,
           const isc::asiolink::IOAddress& addr,
           const uint16_t port, const bool, const bool) {
    int fd = open("/dev/null", O_RDONLY);
    if (fd < 0) {
        const char* errmsg = strerror(errno);
        isc_throw(Unexpected,
                  "PktFilterTestStub: cannot open /dev/null:" << errmsg);
    }

    if (open_socket_callback_) {
        open_socket_callback_(port);
    }

    return (SocketInfo(addr, port, fd));
}

Pkt4Ptr
PktFilterTestStub::receive(Iface&, const SocketInfo&) {
    return Pkt4Ptr();
}

int
PktFilterTestStub::send(const Iface&, uint16_t, const Pkt4Ptr&) {
    return (0);
}

}
}
}