mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Change NetworkInfo to use SocketAddress.
PiperOrigin-RevId: 850164819
This commit is contained in:
committed by
Copybara-Service
parent
067b55ea85
commit
ffa760663b
@@ -62,9 +62,9 @@ class SocketAddress {
|
||||
int family() const { return address_.ss_family; }
|
||||
|
||||
// `Returns port in host byte order.
|
||||
int port() const;
|
||||
uint16_t port() const;
|
||||
// `port` is in host byte order.
|
||||
bool set_port(int port);
|
||||
bool set_port(uint16_t port);
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
@@ -72,6 +72,10 @@ class SocketAddress {
|
||||
// Returns false if the address is not IPv6 or is not link local.
|
||||
bool IsV6LinkLocal() const;
|
||||
|
||||
// Returns true if the address is a link local IPv4 address, ie. 169.254.X.X.
|
||||
// Returns false if the address is not IPv4 or is not link local.
|
||||
bool IsV4LinkLocal() const;
|
||||
|
||||
// Sets the scope id of the address.
|
||||
// Returns false if the address is not IPv6.
|
||||
bool SetScopeId(uint32_t scope_id);
|
||||
@@ -99,6 +103,11 @@ class SocketAddress {
|
||||
return reinterpret_cast<const sockaddr_in6*>(&address_);
|
||||
}
|
||||
|
||||
// Pack this SocketAddress into a ServiceAddress.
|
||||
// If `port` is non-zero, override the port from this SocketAddress with
|
||||
// `port` in the ServiceAddress.
|
||||
ServiceAddress ToServiceAddress(uint16_t port = 0) const;
|
||||
|
||||
private:
|
||||
sockaddr_storage address_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user