5 #ifndef GCOMM_ASIO_ADDR_HPP
6 #define GCOMM_ASIO_ADDR_HPP
8 #include "gu_exception.hpp"
10 #include "asio_protonet.hpp"
17 static inline std::string escape_addr(
const asio::ip::address& addr)
21 return addr.to_v4().to_string();
25 return "[" + addr.to_v6().to_string() +
"]";
29 static inline std::string unescape_addr(
const std::string& addr)
31 std::string ret(addr);
32 size_t pos(ret.find(
'['));
33 if (pos != std::string::npos) ret.erase(pos, 1);
35 if (pos != std::string::npos) ret.erase(pos, 1);
40 static inline std::string anyaddr(
const asio::ip::address& addr)
42 if (addr.is_v4() ==
true)
44 return addr.to_v4().any().to_string();
48 return addr.to_v6().any().to_string();
55 void set_fd_options(S& socket)
57 long flags(FD_CLOEXEC);
58 if (fcntl(socket.native(), F_SETFD, flags) == -1)
60 gu_throw_error(errno) <<
"failed to set FD_CLOEXEC";
65 #endif // GCOMM_ASIO_ADDR_HPP