[haiku-commits] r40552 - in haiku/trunk: headers/os/net src/kits/network/libnetapi src/servers/net src/tests/kits/net/libnetapi

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 18 Feb 2011 22:09:21 +0100 (CET)

Author: axeld
Date: 2011-02-18 22:09:21 +0100 (Fri, 18 Feb 2011)
New Revision: 40552
Changeset: http://dev.haiku-os.org/changeset/40552

Modified:
   haiku/trunk/headers/os/net/NetworkAddress.h
   haiku/trunk/src/kits/network/libnetapi/NetworkAddress.cpp
   haiku/trunk/src/servers/net/DHCPClient.cpp
   haiku/trunk/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
Log:
* 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.


Modified: haiku/trunk/headers/os/net/NetworkAddress.h
===================================================================
--- haiku/trunk/headers/os/net/NetworkAddress.h 2011-02-18 20:30:05 UTC (rev 
40551)
+++ haiku/trunk/headers/os/net/NetworkAddress.h 2011-02-18 21:09:21 UTC (rev 
40552)
@@ -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 @@
                        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);
 

Modified: haiku/trunk/src/kits/network/libnetapi/NetworkAddress.cpp
===================================================================
--- haiku/trunk/src/kits/network/libnetapi/NetworkAddress.cpp   2011-02-18 
20:30:05 UTC (rev 40551)
+++ haiku/trunk/src/kits/network/libnetapi/NetworkAddress.cpp   2011-02-18 
21:09:21 UTC (rev 40552)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Copyright 2010-2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 
@@ -353,7 +353,7 @@
 
 
 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 @@
 
 
 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 @@
                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;
 }
 

Modified: haiku/trunk/src/servers/net/DHCPClient.cpp
===================================================================
--- haiku/trunk/src/servers/net/DHCPClient.cpp  2011-02-18 20:30:05 UTC (rev 
40551)
+++ haiku/trunk/src/servers/net/DHCPClient.cpp  2011-02-18 21:09:21 UTC (rev 
40552)
@@ -694,17 +694,17 @@
                switch (option) {
                        case OPTION_ROUTER_ADDRESS:
                                syslog(LOG_DEBUG, "  gateway: %s\n",
-                                               
_AddressToString(data).String());
+                                       _AddressToString(data).String());
                                address.AddString("gateway", 
_AddressToString(data));
                                break;
                        case OPTION_SUBNET_MASK:
                                syslog(LOG_DEBUG, "  subnet: %s\n",
-                                               
_AddressToString(data).String());
+                                       _AddressToString(data).String());
                                address.AddString("mask", 
_AddressToString(data));
                                break;
                        case OPTION_BROADCAST_ADDRESS:
                                syslog(LOG_DEBUG, "  broadcast: %s\n",
-                                               
_AddressToString(data).String());
+                                       _AddressToString(data).String());
                                address.AddString("broadcast", 
_AddressToString(data));
                                break;
                        case OPTION_DOMAIN_NAME_SERVER:
@@ -721,8 +721,8 @@
                        }
                        case OPTION_SERVER_ADDRESS:
                                syslog(LOG_DEBUG, "  server: %s\n",
-                                               
_AddressToString(data).String());
-                               fServer.SetAddress(ntohl(*(in_addr_t*)data));
+                                       _AddressToString(data).String());
+                               fServer.SetAddress(*(in_addr_t*)data);
                                break;
 
                        case OPTION_ADDRESS_LEASE_TIME:

Modified: haiku/trunk/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
===================================================================
--- haiku/trunk/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp     
2011-02-18 20:30:05 UTC (rev 40551)
+++ haiku/trunk/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp     
2011-02-18 21:09:21 UTC (rev 40552)
@@ -49,7 +49,7 @@
 
        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);


Other related posts:

  • » [haiku-commits] r40552 - in haiku/trunk: headers/os/net src/kits/network/libnetapi src/servers/net src/tests/kits/net/libnetapi - axeld