Kea 2.5.8
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>
10#include <asiolink/io_error.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 }
37 "IOEndpoint creation attempt for unsupported protocol: " <<
38 protocol);
39}
40
41bool
43 return (getProtocol() == other.getProtocol() &&
44 getPort() == other.getPort() &&
45 getFamily() == other.getFamily() &&
46 getAddress() == other.getAddress());
47}
48
49bool
51 return (!operator==(other));
52}
53
54ostream&
55operator<<(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
#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-lfc.