Kea: io_endpoint.cc Source File

| Kea 3.2.0-git

io_endpoint.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8#include <asiolink/asio_wrapper.h>
9#include <asiolink/io_address.h>
10#include <asiolink/io_error.h>
11#include <asiolink/io_endpoint.h>
12#include <asiolink/tcp_endpoint.h>
13#include <asiolink/udp_endpoint.h>
14
15#include <boost/lexical_cast.hpp>
16
17#include <cassert>
18#include <unistd.h> // for some IPC/network system calls
19#include <sys/socket.h>
20#include <netinet/in.h>
21
22using namespace std;
23
24namespace isc {
25namespace asiolink {
26
27const IOEndpoint*
28IOEndpoint::create(const int protocol, const IOAddress& address,
29 const unsigned short port)
30{
31 if (protocol == IPPROTO_UDP) {
32 return (new UDPEndpoint(address, port));
33 } else if (protocol == IPPROTO_TCP) {
34 return (new TCPEndpoint(address, port));
35 }
36 isc_throw(IOError,
37 "IOEndpoint creation attempt for unsupported protocol: " <<
38 protocol);
39}
40
41bool
42IOEndpoint::operator==(const IOEndpoint& other) const {
43 return (getProtocol() == other.getProtocol() &&
44 getPort() == other.getPort() &&
45 getFamily() == other.getFamily() &&
46 getAddress() == other.getAddress());
47}
48
49bool
50IOEndpoint::operator!=(const IOEndpoint& other) const {
51 return (!operator==(other));
52}
53
54ostream&
55 operator<<(ostream& os, const IOEndpoint& endpoint) {
56 if (endpoint.getFamily() == AF_INET6) {
57 os << "[" << endpoint.getAddress() << "]";
58 } else {
59 // In practice this should be AF_INET, but it's not guaranteed by
60 // the interface. We'll use the result of textual address
61 // representation opaquely.
62 os << endpoint.getAddress();
63 }
64 os << ":" << boost::lexical_cast<string>(endpoint.getPort());
65 return (os);
66}
67
68} // namespace asiolink
69} // namespace isc
asio_wrapper.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::asiolink::IOEndpoint
The IOEndpoint class is an abstract base class to represent a communication endpoint.
Definition io_endpoint.h:38
isc::asiolink::IOEndpoint::operator!=
bool operator!=(const IOEndpoint &other) const
Definition io_endpoint.cc:50
isc::asiolink::IOEndpoint::create
static const IOEndpoint * create(const int protocol, const IOAddress &address, const unsigned short port)
A polymorphic factory of endpoint from address and port.
Definition io_endpoint.cc:28
isc::asiolink::IOEndpoint::getFamily
virtual short getFamily() const =0
Returns the address family of the endpoint.
isc::asiolink::IOEndpoint::getAddress
virtual IOAddress getAddress() const =0
Returns the address of the endpoint.
isc::asiolink::IOEndpoint::operator==
bool operator==(const IOEndpoint &other) const
Definition io_endpoint.cc:42
isc::asiolink::IOEndpoint::getProtocol
virtual short getProtocol() const =0
Returns the protocol number of the endpoint (TCP, UDP...).
isc::asiolink::IOEndpoint::getPort
virtual uint16_t getPort() const =0
Returns the port of the endpoint.
isc::asiolink::IOError
An exception that is thrown if an error occurs within the IO module.
Definition io_error.h:19
isc::asiolink::TCPEndpoint
The TCPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a TCP ...
Definition tcp_endpoint.h:23
isc::asiolink::UDPEndpoint
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
Definition udp_endpoint.h:23
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
io_address.h
io_endpoint.h
io_error.h
isc::asiolink
Definition addr_utilities.cc:170
isc::asiolink::operator<<
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
Definition io_address.cc:131
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
tcp_endpoint.h
udp_endpoint.h