NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
dns.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_DNS_HPP
23 #define NDN_UTIL_DNS_HPP
24 
25 #include "../util/time.hpp"
26 
27 #include <boost/asio/ip/address.hpp>
28 
29 // forward declaration
30 namespace boost {
31 namespace asio {
32 class io_service;
33 } // namespace asio
34 } // namespace boost
35 
36 namespace ndn {
37 namespace dns {
38 
39 typedef boost::asio::ip::address IpAddress;
40 typedef function<bool (const IpAddress& address)> AddressSelector;
41 
42 struct AnyAddress
43 {
44  bool
45  operator()(const IpAddress& address) const
46  {
47  return true;
48  }
49 };
50 
51 struct Ipv4Only
52 {
53  bool
54  operator()(const IpAddress& address) const
55  {
56  return address.is_v4();
57  }
58 };
59 
60 struct Ipv6Only
61 {
62  bool
63  operator()(const IpAddress& address) const
64  {
65  return address.is_v6();
66  }
67 };
68 
69 struct Error : public std::runtime_error
70 {
71  explicit
72  Error(const std::string& what)
73  : std::runtime_error(what)
74  {
75  }
76 };
77 
78 typedef function<void (const IpAddress& address)> SuccessCallback;
79 typedef function<void (const std::string& reason)> ErrorCallback;
80 
97 void
98 asyncResolve(const std::string& host,
99  const SuccessCallback& onSuccess,
100  const ErrorCallback& onError,
101  boost::asio::io_service& ioService,
102  const AddressSelector& addressSelector = AnyAddress(),
103  time::nanoseconds timeout = time::seconds(4));
104 
116 IpAddress
117 syncResolve(const std::string& host,
118  boost::asio::io_service& ioService,
119  const AddressSelector& addressSelector = AnyAddress());
120 
121 } // namespace dns
122 } // namespace ndn
123 
124 #endif // NDN_UTIL_DNS_HPP
Error(const std::string &what)
Definition: dns.hpp:72
Copyright (c) 2011-2015 Regents of the University of California.
Copyright (c) 2013-2015 Regents of the University of California.
function< void(const IpAddress &address)> SuccessCallback
Definition: dns.hpp:78
STL namespace.
IpAddress syncResolve(const std::string &host, boost::asio::io_service &ioService, const AddressSelector &addressSelector)
Synchronously resolve host.
Definition: dns.cpp:145
function< bool(const IpAddress &address)> AddressSelector
Definition: dns.hpp:40
function< void(const std::string &reason)> ErrorCallback
Definition: dns.hpp:79
bool operator()(const IpAddress &address) const
Definition: dns.hpp:63
void asyncResolve(const std::string &host, const SuccessCallback &onSuccess, const ErrorCallback &onError, boost::asio::io_service &ioService, const AddressSelector &addressSelector, time::nanoseconds timeout)
Asynchronously resolve host.
Definition: dns.cpp:132
boost::asio::ip::address IpAddress
Definition: dns.hpp:39
bool operator()(const IpAddress &address) const
Definition: dns.hpp:45
bool operator()(const IpAddress &address) const
Definition: dns.hpp:54