| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 public: | 29 public: |
| 30 // Creates a nil address. | 30 // Creates a nil address. |
| 31 SocketAddress(); | 31 SocketAddress(); |
| 32 | 32 |
| 33 // Creates the address with the given host and port. Host may be a | 33 // Creates the address with the given host and port. Host may be a |
| 34 // literal IP string or a hostname to be resolved later. | 34 // literal IP string or a hostname to be resolved later. |
| 35 SocketAddress(const std::string& hostname, int port); | 35 SocketAddress(const std::string& hostname, int port); |
| 36 | 36 |
| 37 // Creates the address with the given IP and port. | 37 // Creates the address with the given IP and port. |
| 38 // IP is given as an integer in host byte order. V4 only, to be deprecated. | 38 // IP is given as an integer in host byte order. V4 only, to be deprecated. |
| 39 SocketAddress(uint32 ip_as_host_order_integer, int port); | 39 SocketAddress(uint32_t ip_as_host_order_integer, int port); |
| 40 | 40 |
| 41 // Creates the address with the given IP and port. | 41 // Creates the address with the given IP and port. |
| 42 SocketAddress(const IPAddress& ip, int port); | 42 SocketAddress(const IPAddress& ip, int port); |
| 43 | 43 |
| 44 // Creates a copy of the given address. | 44 // Creates a copy of the given address. |
| 45 SocketAddress(const SocketAddress& addr); | 45 SocketAddress(const SocketAddress& addr); |
| 46 | 46 |
| 47 // Resets to the nil address. | 47 // Resets to the nil address. |
| 48 void Clear(); | 48 void Clear(); |
| 49 | 49 |
| 50 // Determines if this is a nil address (empty hostname, any IP, null port) | 50 // Determines if this is a nil address (empty hostname, any IP, null port) |
| 51 bool IsNil() const; | 51 bool IsNil() const; |
| 52 | 52 |
| 53 // Returns true if ip and port are set. | 53 // Returns true if ip and port are set. |
| 54 bool IsComplete() const; | 54 bool IsComplete() const; |
| 55 | 55 |
| 56 // Replaces our address with the given one. | 56 // Replaces our address with the given one. |
| 57 SocketAddress& operator=(const SocketAddress& addr); | 57 SocketAddress& operator=(const SocketAddress& addr); |
| 58 | 58 |
| 59 // Changes the IP of this address to the given one, and clears the hostname | 59 // Changes the IP of this address to the given one, and clears the hostname |
| 60 // IP is given as an integer in host byte order. V4 only, to be deprecated.. | 60 // IP is given as an integer in host byte order. V4 only, to be deprecated.. |
| 61 void SetIP(uint32 ip_as_host_order_integer); | 61 void SetIP(uint32_t ip_as_host_order_integer); |
| 62 | 62 |
| 63 // Changes the IP of this address to the given one, and clears the hostname. | 63 // Changes the IP of this address to the given one, and clears the hostname. |
| 64 void SetIP(const IPAddress& ip); | 64 void SetIP(const IPAddress& ip); |
| 65 | 65 |
| 66 // Changes the hostname of this address to the given one. | 66 // Changes the hostname of this address to the given one. |
| 67 // Does not resolve the address; use Resolve to do so. | 67 // Does not resolve the address; use Resolve to do so. |
| 68 void SetIP(const std::string& hostname); | 68 void SetIP(const std::string& hostname); |
| 69 | 69 |
| 70 // Sets the IP address while retaining the hostname. Useful for bypassing | 70 // Sets the IP address while retaining the hostname. Useful for bypassing |
| 71 // DNS for a pre-resolved IP. | 71 // DNS for a pre-resolved IP. |
| 72 // IP is given as an integer in host byte order. V4 only, to be deprecated. | 72 // IP is given as an integer in host byte order. V4 only, to be deprecated. |
| 73 void SetResolvedIP(uint32 ip_as_host_order_integer); | 73 void SetResolvedIP(uint32_t ip_as_host_order_integer); |
| 74 | 74 |
| 75 // Sets the IP address while retaining the hostname. Useful for bypassing | 75 // Sets the IP address while retaining the hostname. Useful for bypassing |
| 76 // DNS for a pre-resolved IP. | 76 // DNS for a pre-resolved IP. |
| 77 void SetResolvedIP(const IPAddress& ip); | 77 void SetResolvedIP(const IPAddress& ip); |
| 78 | 78 |
| 79 // Changes the port of this address to the given one. | 79 // Changes the port of this address to the given one. |
| 80 void SetPort(int port); | 80 void SetPort(int port); |
| 81 | 81 |
| 82 // Returns the hostname. | 82 // Returns the hostname. |
| 83 const std::string& hostname() const { return hostname_; } | 83 const std::string& hostname() const { return hostname_; } |
| 84 | 84 |
| 85 // Returns the IP address as a host byte order integer. | 85 // Returns the IP address as a host byte order integer. |
| 86 // Returns 0 for non-v4 addresses. | 86 // Returns 0 for non-v4 addresses. |
| 87 uint32 ip() const; | 87 uint32_t ip() const; |
| 88 | 88 |
| 89 const IPAddress& ipaddr() const; | 89 const IPAddress& ipaddr() const; |
| 90 | 90 |
| 91 int family() const {return ip_.family(); } | 91 int family() const {return ip_.family(); } |
| 92 | 92 |
| 93 // Returns the port part of this address. | 93 // Returns the port part of this address. |
| 94 uint16 port() const; | 94 uint16_t port() const; |
| 95 | 95 |
| 96 // Returns the scope ID associated with this address. Scope IDs are a | 96 // Returns the scope ID associated with this address. Scope IDs are a |
| 97 // necessary addition to IPv6 link-local addresses, with different network | 97 // necessary addition to IPv6 link-local addresses, with different network |
| 98 // interfaces having different scope-ids for their link-local addresses. | 98 // interfaces having different scope-ids for their link-local addresses. |
| 99 // IPv4 address do not have scope_ids and sockaddr_in structures do not have | 99 // IPv4 address do not have scope_ids and sockaddr_in structures do not have |
| 100 // a field for them. | 100 // a field for them. |
| 101 int scope_id() const {return scope_id_; } | 101 int scope_id() const {return scope_id_; } |
| 102 void SetScopeID(int id) { scope_id_ = id; } | 102 void SetScopeID(int id) { scope_id_ = id; } |
| 103 | 103 |
| 104 // Returns the 'host' portion of the address (hostname or IP) in a form | 104 // Returns the 'host' portion of the address (hostname or IP) in a form |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // The other version doesn't map, and outputs an AF_INET address for | 174 // The other version doesn't map, and outputs an AF_INET address for |
| 175 // v4 or mapped addresses, and AF_INET6 addresses for others. | 175 // v4 or mapped addresses, and AF_INET6 addresses for others. |
| 176 // Returns the size of the sockaddr_in or sockaddr_in6 structure that is | 176 // Returns the size of the sockaddr_in or sockaddr_in6 structure that is |
| 177 // written to the sockaddr_storage, or zero on failure. | 177 // written to the sockaddr_storage, or zero on failure. |
| 178 size_t ToDualStackSockAddrStorage(sockaddr_storage* saddr) const; | 178 size_t ToDualStackSockAddrStorage(sockaddr_storage* saddr) const; |
| 179 size_t ToSockAddrStorage(sockaddr_storage* saddr) const; | 179 size_t ToSockAddrStorage(sockaddr_storage* saddr) const; |
| 180 | 180 |
| 181 // Converts the IP address given in 'compact form' into dotted form. | 181 // Converts the IP address given in 'compact form' into dotted form. |
| 182 // IP is given as an integer in host byte order. V4 only, to be deprecated. | 182 // IP is given as an integer in host byte order. V4 only, to be deprecated. |
| 183 // TODO: Deprecate this. | 183 // TODO: Deprecate this. |
| 184 static std::string IPToString(uint32 ip_as_host_order_integer); | 184 static std::string IPToString(uint32_t ip_as_host_order_integer); |
| 185 | 185 |
| 186 // Same as IPToString but anonymizes it by hiding the last part. | 186 // Same as IPToString but anonymizes it by hiding the last part. |
| 187 // TODO: Deprecate this. | 187 // TODO: Deprecate this. |
| 188 static std::string IPToSensitiveString(uint32 ip_as_host_order_integer); | 188 static std::string IPToSensitiveString(uint32_t ip_as_host_order_integer); |
| 189 | 189 |
| 190 // Converts the IP address given in dotted form into compact form. | 190 // Converts the IP address given in dotted form into compact form. |
| 191 // Only dotted names (A.B.C.D) are converted. | 191 // Only dotted names (A.B.C.D) are converted. |
| 192 // Output integer is returned in host byte order. | 192 // Output integer is returned in host byte order. |
| 193 // TODO: Deprecate, replace wth agnostic versions. | 193 // TODO: Deprecate, replace wth agnostic versions. |
| 194 static bool StringToIP(const std::string& str, uint32* ip); | 194 static bool StringToIP(const std::string& str, uint32_t* ip); |
| 195 static uint32 StringToIP(const std::string& str); | 195 static uint32_t StringToIP(const std::string& str); |
| 196 | 196 |
| 197 // Converts the IP address given in printable form into an IPAddress. | 197 // Converts the IP address given in printable form into an IPAddress. |
| 198 static bool StringToIP(const std::string& str, IPAddress* ip); | 198 static bool StringToIP(const std::string& str, IPAddress* ip); |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 std::string hostname_; | 201 std::string hostname_; |
| 202 IPAddress ip_; | 202 IPAddress ip_; |
| 203 uint16 port_; | 203 uint16_t port_; |
| 204 int scope_id_; | 204 int scope_id_; |
| 205 bool literal_; // Indicates that 'hostname_' contains a literal IP string. | 205 bool literal_; // Indicates that 'hostname_' contains a literal IP string. |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 bool SocketAddressFromSockAddrStorage(const sockaddr_storage& saddr, | 208 bool SocketAddressFromSockAddrStorage(const sockaddr_storage& saddr, |
| 209 SocketAddress* out); | 209 SocketAddress* out); |
| 210 SocketAddress EmptySocketAddressWithFamily(int family); | 210 SocketAddress EmptySocketAddressWithFamily(int family); |
| 211 | 211 |
| 212 } // namespace rtc | 212 } // namespace rtc |
| 213 | 213 |
| 214 #endif // WEBRTC_BASE_SOCKETADDRESS_H_ | 214 #endif // WEBRTC_BASE_SOCKETADDRESS_H_ |
| OLD | NEW |