* Added SetAddress() methods for IPv4, and IPv6 addresses.
* Improved API. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39590 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,8 +33,10 @@ public:
|
|||||||
BNetworkAddress(const sockaddr_in& address);
|
BNetworkAddress(const sockaddr_in& address);
|
||||||
BNetworkAddress(const sockaddr_in6& address);
|
BNetworkAddress(const sockaddr_in6& address);
|
||||||
BNetworkAddress(const sockaddr_dl& address);
|
BNetworkAddress(const sockaddr_dl& address);
|
||||||
BNetworkAddress(const in_addr_t address);
|
BNetworkAddress(in_addr_t address,
|
||||||
BNetworkAddress(const in6_addr* address);
|
uint16 port = 0);
|
||||||
|
BNetworkAddress(const in6_addr& address,
|
||||||
|
uint16 port = 0);
|
||||||
BNetworkAddress(const BNetworkAddress& other);
|
BNetworkAddress(const BNetworkAddress& other);
|
||||||
BNetworkAddress(BMessage* archive);
|
BNetworkAddress(BMessage* archive);
|
||||||
virtual ~BNetworkAddress();
|
virtual ~BNetworkAddress();
|
||||||
@@ -57,15 +59,18 @@ public:
|
|||||||
void SetTo(const sockaddr_in& address);
|
void SetTo(const sockaddr_in& address);
|
||||||
void SetTo(const sockaddr_in6& address);
|
void SetTo(const sockaddr_in6& address);
|
||||||
void SetTo(const sockaddr_dl& address);
|
void SetTo(const sockaddr_dl& address);
|
||||||
void SetTo(const in_addr_t address);
|
void SetTo(in_addr_t address, uint16 port = 0);
|
||||||
void SetTo(const in6_addr* address);
|
void SetTo(const in6_addr& address, uint16 port = 0);
|
||||||
void SetTo(const BNetworkAddress& other);
|
void SetTo(const BNetworkAddress& other);
|
||||||
|
|
||||||
status_t SetToBroadcast(int family, uint16 port = 0);
|
status_t SetToBroadcast(int family, uint16 port = 0);
|
||||||
status_t SetToLocal();
|
status_t SetToLocal();
|
||||||
status_t SetToLoopback();
|
status_t SetToLoopback();
|
||||||
status_t SetToMask(int family, uint32 prefixLength);
|
status_t SetToMask(int family, uint32 prefixLength);
|
||||||
status_t SetToWildcard(int family);
|
status_t SetToWildcard(int family, uint16 port = 0);
|
||||||
|
|
||||||
|
status_t SetAddress(in_addr_t address);
|
||||||
|
status_t SetAddress(const in6_addr& address);
|
||||||
void SetPort(uint16 port);
|
void SetPort(uint16 port);
|
||||||
status_t SetPort(const char* service);
|
status_t SetPort(const char* service);
|
||||||
|
|
||||||
@@ -126,7 +131,9 @@ public:
|
|||||||
|
|
||||||
operator const sockaddr*() const;
|
operator const sockaddr*() const;
|
||||||
operator const sockaddr&() const;
|
operator const sockaddr&() const;
|
||||||
|
operator const sockaddr*();
|
||||||
operator sockaddr*();
|
operator sockaddr*();
|
||||||
|
operator const sockaddr&();
|
||||||
operator sockaddr&();
|
operator sockaddr&();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -73,15 +73,15 @@ BNetworkAddress::BNetworkAddress(const sockaddr_dl& address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkAddress::BNetworkAddress(const in_addr_t address)
|
BNetworkAddress::BNetworkAddress(in_addr_t address, uint16 port)
|
||||||
{
|
{
|
||||||
SetTo(address);
|
SetTo(address, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkAddress::BNetworkAddress(const in6_addr* address)
|
BNetworkAddress::BNetworkAddress(const in6_addr& address, uint16 port)
|
||||||
{
|
{
|
||||||
SetTo(address);
|
SetTo(address, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -266,28 +266,28 @@ BNetworkAddress::SetTo(const sockaddr_dl& address)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BNetworkAddress::SetTo(const in_addr_t inetAddress)
|
BNetworkAddress::SetTo(in_addr_t inetAddress, uint16 port)
|
||||||
{
|
{
|
||||||
sockaddr_in& address = (sockaddr_in&)fAddress;
|
|
||||||
memset(&fAddress, 0, sizeof(sockaddr_storage));
|
memset(&fAddress, 0, sizeof(sockaddr_storage));
|
||||||
|
|
||||||
address.sin_family = AF_INET;
|
fAddress.ss_family = AF_INET;
|
||||||
address.sin_len = sizeof(sockaddr_in);
|
fAddress.ss_len = sizeof(sockaddr_in);
|
||||||
address.sin_addr.s_addr = inetAddress;
|
SetAddress(inetAddress);
|
||||||
|
SetPort(port);
|
||||||
fStatus = B_OK;
|
fStatus = B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BNetworkAddress::SetTo(const in6_addr* inet6Address)
|
BNetworkAddress::SetTo(const in6_addr& inet6Address, uint16 port)
|
||||||
{
|
{
|
||||||
sockaddr_in6& address = (sockaddr_in6&)fAddress;
|
|
||||||
memset(&fAddress, 0, sizeof(sockaddr_storage));
|
memset(&fAddress, 0, sizeof(sockaddr_storage));
|
||||||
|
|
||||||
address.sin6_family = AF_INET6;
|
fAddress.ss_family = AF_INET6;
|
||||||
address.sin6_len = sizeof(sockaddr_in6);
|
fAddress.ss_len = sizeof(sockaddr_in6);
|
||||||
memcpy(address.sin6_addr.s6_addr, inet6Address,
|
SetAddress(inet6Address);
|
||||||
sizeof(address.sin6_addr.s6_addr));
|
SetPort(port);
|
||||||
|
|
||||||
fStatus = B_OK;
|
fStatus = B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,9 +383,34 @@ BNetworkAddress::SetToMask(int family, uint32 prefixLength)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BNetworkAddress::SetToWildcard(int family)
|
BNetworkAddress::SetToWildcard(int family, uint16 port)
|
||||||
{
|
{
|
||||||
return SetTo(family, NULL);
|
return SetTo(family, NULL, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BNetworkAddress::SetAddress(in_addr_t inetAddress)
|
||||||
|
{
|
||||||
|
if (Family() != AF_INET)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
sockaddr_in& address = (sockaddr_in&)fAddress;
|
||||||
|
address.sin_addr.s_addr = inetAddress;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BNetworkAddress::SetAddress(const in6_addr& inet6Address)
|
||||||
|
{
|
||||||
|
if (Family() != AF_INET6)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
sockaddr_in6& address = (sockaddr_in6&)fAddress;
|
||||||
|
memcpy(address.sin6_addr.s6_addr, &inet6Address,
|
||||||
|
sizeof(address.sin6_addr.s6_addr));
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1022,7 +1047,19 @@ BNetworkAddress::operator sockaddr*()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BNetworkAddress::operator const sockaddr*()
|
||||||
|
{
|
||||||
|
return (sockaddr*)&fAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkAddress::operator sockaddr&()
|
BNetworkAddress::operator sockaddr&()
|
||||||
{
|
{
|
||||||
return (sockaddr&)fAddress;
|
return (sockaddr&)fAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BNetworkAddress::operator const sockaddr&()
|
||||||
|
{
|
||||||
|
return (sockaddr&)fAddress;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user