guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dhcp] 10/12: dhcp: source for .so, used by some now-redundant functions


From: Rohan Prinja
Subject: [dhcp] 10/12: dhcp: source for .so, used by some now-redundant functions in interfaces.scm
Date: Sat, 06 Jun 2015 18:16:58 +0000

wenderen pushed a commit to branch master
in repository dhcp.

commit c24603cf653498ed99eefb1bb350f7a5392002ce
Author: Rohan Prinja <address@hidden>
Date:   Sat Jun 6 23:44:42 2015 +0530

    dhcp: source for .so, used by some now-redundant functions in interfaces.scm
---
 lib/interfaces.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/lib/interfaces.c b/lib/interfaces.c
new file mode 100644
index 0000000..0d09a9b
--- /dev/null
+++ b/lib/interfaces.c
@@ -0,0 +1,54 @@
+/// GNU Guix DHCP Client.
+///
+/// Copyright 2015 Free Software Foundation, Inc.
+///
+/// This program is free software; you can redistribute it and/or modify it
+/// under the terms of the GNU General Public License as published by
+/// the Free Software Foundation; either version 3 of the License, or (at
+/// your option) any later version.
+///
+/// This program is distributed in the hope that it will be useful, but
+/// WITHOUT ANY WARRANTY; without even the implied warranty of
+/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+/// GNU General Public License for more details.
+///
+/// You should have received a copy of the GNU General Public License
+/// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <stdio.h>
+
+void print_interfaces() {
+    struct ifaddrs *ifaddr, *itr;
+    if (getifaddrs(&ifaddr) == -1) {
+        return;
+    }
+    for (itr = ifaddr; itr; itr = itr->ifa_next) {
+        if (itr->ifa_addr == NULL) {
+            continue;
+        }
+        int family = itr->ifa_addr->sa_family;
+        if (family == AF_INET || family == AF_INET6) {
+            printf("Name: %s, ", itr->ifa_name);
+            printf("Address: %s, ", family == AF_INET ? "AF_INET" : family == 
AF_INET6 ? "AF_INET6" : "");
+           printf("Flags: %d\n", itr->ifa_flags);
+        }
+    }
+}
+
+char* get_sockaddr_data(struct ifaddrs* ifaddr) {
+    return ifaddr->ifa_addr->sa_data;
+}
+
+struct ifaddrs* get_first_interface_ptr() {
+    struct ifaddrs *ifaddr, *itr;
+    if (getifaddrs(&ifaddr) == -1) {
+        return NULL;
+    }
+    return ifaddr;
+}
+
+void free_interfaces(struct ifaddrs *ifaddr) {
+    freeifaddrs(ifaddr);
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]