Kea  1.9.9-git
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>
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  }
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
bool operator!=(const Element &a, const Element &b)
Definition: data.cc:214
STL namespace.
bool operator==(const Element &a, const Element &b)
Definition: data.cc:210
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-dhcp-ddns.