[haiku-commits] haiku: hrev48685 - in src/kits/network/libnetapi: . src/kits/network

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 16 Jan 2015 13:28:55 +0100 (CET)

hrev48685 adds 1 changeset to branch 'master'
old head: e2fc7cd3c7be1918e8de18e984d10acb5ea2626d
new head: 46c267cf18011590897c353df1cc2649aec3715a
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=46c267cf1801+%5Ee2fc7cd3c7be

----------------------------------------------------------------------------

46c267cf1801: Move getifaddrs to libbnetapi
  
  * Since it uses BNetworkAddress, it can't be in libnetwork.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev48685
Commit:      46c267cf18011590897c353df1cc2649aec3715a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=46c267cf1801
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Fri Jan 16 12:26:35 2015 UTC

----------------------------------------------------------------------------

3 files changed, 89 insertions(+), 71 deletions(-)
src/kits/network/interfaces.cpp           | 72 +---------------------
src/kits/network/libnetapi/Jamfile        |  1 +
src/kits/network/libnetapi/getifaddrs.cpp | 87 +++++++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/kits/network/interfaces.cpp b/src/kits/network/interfaces.cpp
index 42a043d..cd8aacb 100644
--- a/src/kits/network/interfaces.cpp
+++ b/src/kits/network/interfaces.cpp
@@ -1,10 +1,9 @@
 /*
- * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
+ * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
  *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
- *             Adrien Destugues, pulkomandy@xxxxxxxxxxxxx
  */
 
 
@@ -17,9 +16,6 @@
 #include <unistd.h>
 
 #include <AutoDeleter.h>
-#include <NetworkAddress.h>
-#include <NetworkInterface.h>
-#include <NetworkRoster.h>
 
 #include "compatibility/bsd/ifaddrs.h"
 
@@ -147,69 +143,3 @@ if_freenameindex(struct if_nameindex *interfaceArray)
        }
        free(interfaceArray);
 }
-
-
-int getifaddrs(struct ifaddrs **ifap)
-{
-       if (ifap == NULL) {
-               errno = B_BAD_VALUE;
-               return -1;
-       }
-
-       BNetworkRoster& roster = BNetworkRoster::Default();
-
-       uint32 cookie;
-
-       struct ifaddrs* previous = NULL;
-       struct ifaddrs* current = NULL;
-       BNetworkInterface* interface = new BNetworkInterface();
-
-       while (roster.GetNextInterface(&cookie, *interface) == B_OK) {
-               BNetworkInterfaceAddress address;
-               int32 i = 0;
-               while (interface->GetAddressAt(i++, address) == B_OK) {
-                       current = new ifaddrs();
-
-                       // Chain this interface with the next one
-                       current->ifa_next = previous;
-                       previous = current;
-
-                       current->ifa_data = interface;
-                       current->ifa_name = interface->Name();
-                               // Points to the name in the BNetworkInterface 
instance, which
-                               // is added as ifa_data so freeifaddrs can 
release it.
-                       current->ifa_flags = address.Flags();
-                       current->ifa_addr = new 
sockaddr(address.Address().SockAddr());
-                       current->ifa_netmask = new 
sockaddr(address.Mask().SockAddr());
-                       current->ifa_dstaddr = new 
sockaddr(address.Destination().SockAddr());
-               }
-
-               interface = new BNetworkInterface();
-       }
-
-       delete interface;
-       *ifap = current;
-
-       return 0;
-}
-
-
-void freeifaddrs(struct ifaddrs *ifa)
-{
-       struct ifaddrs* next;
-       BNetworkInterface* interface = NULL;
-       while (ifa != NULL) {
-               if (ifa->ifa_data != interface) {
-                       interface = (BNetworkInterface*)ifa->ifa_data;
-                       delete interface;
-               }
-
-               delete ifa->ifa_addr;
-               delete ifa->ifa_netmask;
-               delete ifa->ifa_dstaddr;
-
-               next = ifa->ifa_next;
-               delete ifa;
-               ifa = next;
-       }
-}
diff --git a/src/kits/network/libnetapi/Jamfile 
b/src/kits/network/libnetapi/Jamfile
index 643840b..066ceb4 100644
--- a/src/kits/network/libnetapi/Jamfile
+++ b/src/kits/network/libnetapi/Jamfile
@@ -79,6 +79,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
                        HttpResult.cpp
                        HttpTime.cpp
 
+                       getifaddrs.cpp
                        notifications.cpp
 
                        $(md5Sources)
diff --git a/src/kits/network/libnetapi/getifaddrs.cpp 
b/src/kits/network/libnetapi/getifaddrs.cpp
new file mode 100644
index 0000000..e9431f1
--- /dev/null
+++ b/src/kits/network/libnetapi/getifaddrs.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2015, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Adrien Destugues, pulkomandy@xxxxxxxxxxxxx
+ */
+
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <AutoDeleter.h>
+#include <NetworkAddress.h>
+#include <NetworkInterface.h>
+#include <NetworkRoster.h>
+
+#include "compatibility/bsd/ifaddrs.h"
+
+
+int getifaddrs(struct ifaddrs **ifap)
+{
+       if (ifap == NULL) {
+               errno = B_BAD_VALUE;
+               return -1;
+       }
+
+       BNetworkRoster& roster = BNetworkRoster::Default();
+
+       uint32 cookie;
+
+       struct ifaddrs* previous = NULL;
+       struct ifaddrs* current = NULL;
+       BNetworkInterface* interface = new BNetworkInterface();
+
+       while (roster.GetNextInterface(&cookie, *interface) == B_OK) {
+               BNetworkInterfaceAddress address;
+               int32 i = 0;
+               while (interface->GetAddressAt(i++, address) == B_OK) {
+                       current = new ifaddrs();
+
+                       // Chain this interface with the next one
+                       current->ifa_next = previous;
+                       previous = current;
+
+                       current->ifa_data = interface;
+                       current->ifa_name = interface->Name();
+                               // Points to the name in the BNetworkInterface 
instance, which
+                               // is added as ifa_data so freeifaddrs can 
release it.
+                       current->ifa_flags = address.Flags();
+                       current->ifa_addr = new 
sockaddr(address.Address().SockAddr());
+                       current->ifa_netmask = new 
sockaddr(address.Mask().SockAddr());
+                       current->ifa_dstaddr = new 
sockaddr(address.Destination().SockAddr());
+               }
+
+               interface = new BNetworkInterface();
+       }
+
+       delete interface;
+       *ifap = current;
+
+       return 0;
+}
+
+
+void freeifaddrs(struct ifaddrs *ifa)
+{
+       struct ifaddrs* next;
+       BNetworkInterface* interface = NULL;
+       while (ifa != NULL) {
+               if (ifa->ifa_data != interface) {
+                       interface = (BNetworkInterface*)ifa->ifa_data;
+                       delete interface;
+               }
+
+               delete ifa->ifa_addr;
+               delete ifa->ifa_netmask;
+               delete ifa->ifa_dstaddr;
+
+               next = ifa->ifa_next;
+               delete ifa;
+               ifa = next;
+       }
+}
+


Other related posts: