123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #ifndef RTC_BASE_SOCKET_ADDRESS_H_
- #define RTC_BASE_SOCKET_ADDRESS_H_
- #include <string>
- #ifdef UNIT_TEST
- #include <ostream> // no-presubmit-check TODO(webrtc:8982)
- #endif
- #include "rtc_base/ip_address.h"
- #include "rtc_base/system/rtc_export.h"
- #undef SetPort
- struct sockaddr_in;
- struct sockaddr_storage;
- namespace rtc {
- class RTC_EXPORT SocketAddress {
- public:
-
- SocketAddress();
-
-
-
- SocketAddress(const std::string& hostname, int port);
-
-
-
- SocketAddress(uint32_t ip_as_host_order_integer, int port);
-
-
- SocketAddress(const IPAddress& ip, int port);
-
- SocketAddress(const SocketAddress& addr);
-
- void Clear();
-
- bool IsNil() const;
-
- bool IsComplete() const;
-
- SocketAddress& operator=(const SocketAddress& addr);
-
-
- void SetIP(uint32_t ip_as_host_order_integer);
-
- void SetIP(const IPAddress& ip);
-
-
- void SetIP(const std::string& hostname);
-
-
-
- void SetResolvedIP(uint32_t ip_as_host_order_integer);
-
-
- void SetResolvedIP(const IPAddress& ip);
-
-
- void SetPort(int port);
-
- const std::string& hostname() const { return hostname_; }
-
-
- uint32_t ip() const;
- const IPAddress& ipaddr() const;
- int family() const { return ip_.family(); }
-
- uint16_t port() const;
-
-
-
-
-
- int scope_id() const { return scope_id_; }
- void SetScopeID(int id) { scope_id_ = id; }
-
-
-
- std::string HostAsURIString() const;
-
-
- std::string HostAsSensitiveURIString() const;
-
- std::string PortAsString() const;
-
- std::string ToString() const;
-
- std::string ToSensitiveString() const;
-
- bool FromString(const std::string& str);
- #ifdef UNIT_TEST
- inline std::ostream& operator<<(
- std::ostream& os) {
- return os << HostAsURIString() << ":" << port();
- }
- #endif
-
-
-
- bool IsAnyIP() const;
-
-
-
- bool IsLoopbackIP() const;
-
-
-
- bool IsPrivateIP() const;
-
- bool IsUnresolvedIP() const;
-
- bool operator==(const SocketAddress& addr) const;
- inline bool operator!=(const SocketAddress& addr) const {
- return !this->operator==(addr);
- }
-
- bool operator<(const SocketAddress& addr) const;
-
- bool EqualIPs(const SocketAddress& addr) const;
-
- bool EqualPorts(const SocketAddress& addr) const;
-
- size_t Hash() const;
-
-
- void ToSockAddr(sockaddr_in* saddr) const;
-
- bool FromSockAddr(const sockaddr_in& saddr);
-
-
-
-
-
-
- size_t ToDualStackSockAddrStorage(sockaddr_storage* saddr) const;
- size_t ToSockAddrStorage(sockaddr_storage* saddr) const;
- private:
- std::string hostname_;
- IPAddress ip_;
- uint16_t port_;
- int scope_id_;
- bool literal_;
- };
- RTC_EXPORT bool SocketAddressFromSockAddrStorage(const sockaddr_storage& saddr,
- SocketAddress* out);
- SocketAddress EmptySocketAddressWithFamily(int family);
- }
- #endif
|