[haiku-commits] Re: haiku: hrev48684 - src/kits/network headers/compatibility/bsd

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 16 Jan 2015 14:01:47 +0100

Am 16/01/2015 um 13:10 schrieb pulkomandy@xxxxxxxxxxxxx:

+int getifaddrs(struct ifaddrs **ifap)

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();

A C function should never throw.

+                       // 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.

That's really ugly, though. Also, it will probably free it, not delete
it (ie. its destructor won't be called).

+void freeifaddrs(struct ifaddrs *ifa)

void
freeifaddrs(struct ifaddrs* ifa)

Finally, since it's part of libbnetapi.so, why don't you put its function prototype in a standard header (and since it's also part of glibc).

Bye,
   Axel.

Other related posts: