18 #ifndef INCLUDE_RCF_IPADDRESS_HPP 19 #define INCLUDE_RCF_IPADDRESS_HPP 23 #include <RCF/Export.hpp> 24 #include <RCF/Config.hpp> 25 #include <RCF/ServerTransport.hpp> 27 #include <RCF/BsdSockets.hpp> 31 #if RCF_FEATURE_IPV6==1 33 typedef in6_addr In6Addr;
34 typedef sockaddr_in6 SockAddrIn6;
35 typedef sockaddr_storage SockAddrStorage;
51 struct In6Addr sin6_addr;
55 struct SockAddrStorage
57 sockaddr_in mSockAddrIn;
63 typedef std::shared_ptr<Exception> ExceptionPtr;
73 explicit IpAddress(
const std::string & ip);
76 explicit IpAddress(
const std::string & ip,
int port);
80 enum Type { V4_or_V6, V4, V6 };
82 static void setPreferredResolveProtocol(Type type);
83 static Type getPreferredResolveProtocol();
87 explicit IpAddress(
const std::string & ip,
int port, Type restrictTo);
88 explicit IpAddress(
const sockaddr_in &addr);
89 explicit IpAddress(
const SockAddrIn6 &addr);
90 explicit IpAddress(
const sockaddr &addr, std::size_t addrLen, Type type);
93 void init(
const sockaddr &addr, std::size_t addrLen, Type type);
95 int createSocket(
int socketType = SOCK_STREAM,
int protocol = IPPROTO_TCP)
const;
96 void getSockAddr(sockaddr *&, Platform::OS::BsdSockets::socklen_t &)
const;
97 std::string getIp()
const;
101 void resolve()
const;
102 void resolve(ExceptionPtr & e)
const;
103 std::string string()
const;
105 bool isResolved()
const;
106 bool isBroadcast()
const;
107 bool isMulticast()
const;
108 bool isLoopback()
const;
109 bool matches(
const IpAddress & rhs, std::size_t bits = std::size_t(-1))
const;
111 void setPort(
int port);
113 bool operator==(
const IpAddress & rhs)
const;
114 bool operator!=(
const IpAddress & rhs)
const;
115 bool operator<(
const IpAddress &rhs)
const;
119 void extractIpAndPort();
122 mutable bool mResolved;
123 mutable sockaddr_in mAddrV4;
124 mutable SockAddrIn6 mAddrV6;
152 #endif // ! INCLUDE_RCF_IPADDRESS_HPP Describes the network address of a remote peer.
Definition: ServerTransport.hpp:36
Represents an IPv6 IP address.
Definition: IpAddress.hpp:141
Represents an IPv4 IP address.
Definition: IpAddress.hpp:131
Definition: AmiIoHandler.hpp:23
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...
Represents an IP address (IPv4 or IPv6).
Definition: IpAddress.hpp:66