From: Benoît Canet <benoit.canet.cont...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master
libc/getifaddrs: Extract and use allocate_and_add_ifaddrs
The code will need to allocate twice as much
ifaddr_storage structure to be able to return mac
addresses in their own ifaddrs structure.
Signed-off-by: Benoît Canet <ben...@scylladb.com>
Message-Id: <1477485154-13682-3-git-send-email-ben...@scylladb.com>
---
diff --git a/libc/network/getifaddrs.c b/libc/network/getifaddrs.c
--- a/libc/network/getifaddrs.c
+++ b/libc/network/getifaddrs.c
@@ -112,18 +112,27 @@ static void dealwithipv6(stor **list, stor** head)
fclose(f);
}
+int allocate_and_add_ifaddrs(stor **list, stor **head, struct if_nameindex
*ii)
+{
+ size_t i;
+ for(i = 0; ii[i].if_index || ii[i].if_name; i++) {
+ stor* curr = list_add(list, head, ii[i].if_name);
+ if(!curr) {
+ return 0;
+ }
+ }
+ return i;
+}
+
int getifaddrs(struct ifaddrs **ifap)
{
stor *list = 0, *head = 0;
struct if_nameindex* ii = if_nameindex();
if(!ii) return -1;
size_t i;
- for(i = 0; ii[i].if_index || ii[i].if_name; i++) {
- stor* curr = list_add(&list, &head, ii[i].if_name);
- if(!curr) {
- if_freenameindex(ii);
- goto err2;
- }
+ if (!allocate_and_add_ifaddrs(&list, &head, ii)) {
+ if_freenameindex(ii);
+ goto err2;
}
if_freenameindex(ii);
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.