* 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:
parent
1b53751478
commit
ddf57b6cf6
@ -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.
|
||||
*/
|
||||
#ifndef _NETWORK_ADDRESS_H
|
||||
@ -63,8 +63,10 @@ public:
|
||||
void SetTo(const BNetworkAddress& other);
|
||||
|
||||
status_t SetToBroadcast(int family, uint16 port = 0);
|
||||
status_t SetToLocal();
|
||||
status_t SetToLoopback();
|
||||
status_t SetToLocal(int family = AF_UNSPEC,
|
||||
uint16 port = 0);
|
||||
status_t SetToLoopback(int family = AF_UNSPEC,
|
||||
uint16 port = 0);
|
||||
status_t SetToMask(int family, uint32 prefixLength);
|
||||
status_t SetToWildcard(int family, uint16 port = 0);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2010-2011, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -353,7 +353,7 @@ BNetworkAddress::SetToBroadcast(int family, uint16 port)
|
||||
|
||||
|
||||
status_t
|
||||
BNetworkAddress::SetToLocal()
|
||||
BNetworkAddress::SetToLocal(int family, uint16 port)
|
||||
{
|
||||
// TODO: choose a local address from the network interfaces
|
||||
return fStatus = B_NOT_SUPPORTED;
|
||||
@ -361,9 +361,24 @@ BNetworkAddress::SetToLocal()
|
||||
|
||||
|
||||
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;
|
||||
|
||||
sockaddr_in& address = (sockaddr_in&)fAddress;
|
||||
address.sin_addr.s_addr = htonl(inetAddress);
|
||||
address.sin_addr.s_addr = inetAddress;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -722,7 +722,7 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address,
|
||||
case OPTION_SERVER_ADDRESS:
|
||||
syslog(LOG_DEBUG, " server: %s\n",
|
||||
_AddressToString(data).String());
|
||||
fServer.SetAddress(ntohl(*(in_addr_t*)data));
|
||||
fServer.SetAddress(*(in_addr_t*)data);
|
||||
break;
|
||||
|
||||
case OPTION_ADDRESS_LEASE_TIME:
|
||||
|
@ -49,7 +49,7 @@ NetworkAddressTest::TestSetTo()
|
||||
|
||||
CPPUNIT_ASSERT(address.SetTo("127.0.0.1") == B_OK);
|
||||
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.Family() == AF_INET6);
|
||||
|
Loading…
Reference in New Issue
Block a user