* Reverted back to the original version of BNetworkAddress::SetAddress();
in_addr_t is now in network endian again. Thanks, Philippe! * Made SetToLoopback(), and SetToLocal() a bit more useful (although the latter isn't implemented yet). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40552 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, Haiku, Inc. All Rights Reserved.
|
* Copyright 2010-2011, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _NETWORK_ADDRESS_H
|
#ifndef _NETWORK_ADDRESS_H
|
||||||
@@ -63,8 +63,10 @@ public:
|
|||||||
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(int family = AF_UNSPEC,
|
||||||
status_t SetToLoopback();
|
uint16 port = 0);
|
||||||
|
status_t SetToLoopback(int family = AF_UNSPEC,
|
||||||
|
uint16 port = 0);
|
||||||
status_t SetToMask(int family, uint32 prefixLength);
|
status_t SetToMask(int family, uint32 prefixLength);
|
||||||
status_t SetToWildcard(int family, uint16 port = 0);
|
status_t SetToWildcard(int family, uint16 port = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, Axel Dörfler, [email protected].
|
* Copyright 2010-2011, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ BNetworkAddress::SetToBroadcast(int family, uint16 port)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BNetworkAddress::SetToLocal()
|
BNetworkAddress::SetToLocal(int family, uint16 port)
|
||||||
{
|
{
|
||||||
// TODO: choose a local address from the network interfaces
|
// TODO: choose a local address from the network interfaces
|
||||||
return fStatus = B_NOT_SUPPORTED;
|
return fStatus = B_NOT_SUPPORTED;
|
||||||
@@ -361,9 +361,24 @@ BNetworkAddress::SetToLocal()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BNetworkAddress::SetToLoopback()
|
BNetworkAddress::SetToLoopback(int family, uint16 port)
|
||||||
{
|
{
|
||||||
return SetTo("localhost");
|
switch (family) {
|
||||||
|
// TODO: choose family depending on availability of IPv6
|
||||||
|
case AF_UNSPEC:
|
||||||
|
case AF_INET:
|
||||||
|
SetTo(htonl(INADDR_LOOPBACK), port);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AF_INET6:
|
||||||
|
SetTo(in6addr_loopback, port);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fStatus = B_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -446,7 +461,7 @@ BNetworkAddress::SetAddress(in_addr_t inetAddress)
|
|||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
sockaddr_in& address = (sockaddr_in&)fAddress;
|
sockaddr_in& address = (sockaddr_in&)fAddress;
|
||||||
address.sin_addr.s_addr = htonl(inetAddress);
|
address.sin_addr.s_addr = inetAddress;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -694,17 +694,17 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address,
|
|||||||
switch (option) {
|
switch (option) {
|
||||||
case OPTION_ROUTER_ADDRESS:
|
case OPTION_ROUTER_ADDRESS:
|
||||||
syslog(LOG_DEBUG, " gateway: %s\n",
|
syslog(LOG_DEBUG, " gateway: %s\n",
|
||||||
_AddressToString(data).String());
|
_AddressToString(data).String());
|
||||||
address.AddString("gateway", _AddressToString(data));
|
address.AddString("gateway", _AddressToString(data));
|
||||||
break;
|
break;
|
||||||
case OPTION_SUBNET_MASK:
|
case OPTION_SUBNET_MASK:
|
||||||
syslog(LOG_DEBUG, " subnet: %s\n",
|
syslog(LOG_DEBUG, " subnet: %s\n",
|
||||||
_AddressToString(data).String());
|
_AddressToString(data).String());
|
||||||
address.AddString("mask", _AddressToString(data));
|
address.AddString("mask", _AddressToString(data));
|
||||||
break;
|
break;
|
||||||
case OPTION_BROADCAST_ADDRESS:
|
case OPTION_BROADCAST_ADDRESS:
|
||||||
syslog(LOG_DEBUG, " broadcast: %s\n",
|
syslog(LOG_DEBUG, " broadcast: %s\n",
|
||||||
_AddressToString(data).String());
|
_AddressToString(data).String());
|
||||||
address.AddString("broadcast", _AddressToString(data));
|
address.AddString("broadcast", _AddressToString(data));
|
||||||
break;
|
break;
|
||||||
case OPTION_DOMAIN_NAME_SERVER:
|
case OPTION_DOMAIN_NAME_SERVER:
|
||||||
@@ -721,8 +721,8 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address,
|
|||||||
}
|
}
|
||||||
case OPTION_SERVER_ADDRESS:
|
case OPTION_SERVER_ADDRESS:
|
||||||
syslog(LOG_DEBUG, " server: %s\n",
|
syslog(LOG_DEBUG, " server: %s\n",
|
||||||
_AddressToString(data).String());
|
_AddressToString(data).String());
|
||||||
fServer.SetAddress(ntohl(*(in_addr_t*)data));
|
fServer.SetAddress(*(in_addr_t*)data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTION_ADDRESS_LEASE_TIME:
|
case OPTION_ADDRESS_LEASE_TIME:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ NetworkAddressTest::TestSetTo()
|
|||||||
|
|
||||||
CPPUNIT_ASSERT(address.SetTo("127.0.0.1") == B_OK);
|
CPPUNIT_ASSERT(address.SetTo("127.0.0.1") == B_OK);
|
||||||
CPPUNIT_ASSERT(address.Family() == AF_INET);
|
CPPUNIT_ASSERT(address.Family() == AF_INET);
|
||||||
CPPUNIT_ASSERT(address == BNetworkAddress(INADDR_LOOPBACK));
|
CPPUNIT_ASSERT(address == BNetworkAddress(htonl(INADDR_LOOPBACK)));
|
||||||
|
|
||||||
CPPUNIT_ASSERT(address.SetTo("::1") == B_OK);
|
CPPUNIT_ASSERT(address.SetTo("::1") == B_OK);
|
||||||
CPPUNIT_ASSERT(address.Family() == AF_INET6);
|
CPPUNIT_ASSERT(address.Family() == AF_INET6);
|
||||||
|
|||||||
Reference in New Issue
Block a user