Kea: io_endpoint.cc Source File

| Kea 1.5.0

io_endpoint.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2016 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
22 using namespace std;
23
24 namespace isc {
25 namespace asiolink {
26
27 const IOEndpoint*
28 IOEndpoint::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
41 bool
42 IOEndpoint::operator==(const IOEndpoint& other) const {
43 return (getProtocol() == other.getProtocol() &&
44 getPort() == other.getPort() &&
45 getFamily() == other.getFamily() &&
46 getAddress() == other.getAddress());
47 }
48
49 bool
50 IOEndpoint::operator!=(const IOEndpoint& other) const {
51 return (!operator==(other));
52 }
53
54 ostream&
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 } // namespace asiolink
68 } // namespace isc
isc::asiolink::IOEndpoint::getPort
virtual uint16_t getPort() const =0
Returns the port of the endpoint.
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::IOEndpoint::getProtocol
virtual short getProtocol() const =0
Returns the protocol number of the endpoint (TCP, UDP...)
io_endpoint.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic)
Definition: io_address.h:45
io_address.h
io_error.h
isc::asiolink::IOEndpoint::getFamily
virtual short getFamily() const =0
Returns the address family of the endpoint.
isc::data::operator!=
bool operator!=(const Element &a, const Element &b)
Definition: data.cc:215
isc::asiolink::IOEndpoint
The IOEndpoint class is an abstract base class to represent a communication endpoint.
Definition: io_endpoint.h:38
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
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
tcp_endpoint.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:192
asiolink
A wrapper interface for the ASIO library.
udp_endpoint.h
isc::asiolink::IOError
An exception that is thrown if an error occurs within the IO module.
Definition: io_error.h:19
asio_wrapper.h
isc::data::operator==
bool operator==(const Element &a, const Element &b)
Definition: data.cc:211
isc::asiolink::IOEndpoint::getAddress
virtual IOAddress getAddress() const =0
Returns the address of the endpoint.
isc::asiolink::operator<<
ostream & operator<<(ostream &os, const IOEndpoint &endpoint)
Insert the IOEndpoint as a string into stream.
Definition: io_endpoint.cc:55