[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);
+}
- [dhcp] branch master updated (30d7a60 -> d6b11dd), Rohan Prinja, 2015/06/06
- [dhcp] 02/12: dhcp: tell git to ignore log files, Rohan Prinja, 2015/06/06
- [dhcp] 05/12: dhcp: add in deprecated time-offset option, Rohan Prinja, 2015/06/06
- [dhcp] 01/12: dhcp: arp hardware address identifiers, Rohan Prinja, 2015/06/06
- [dhcp] 04/12: dhcp: change module names to reflect directory structure, Rohan Prinja, 2015/06/06
- [dhcp] 08/12: dhcp: code for sending packets, incomplete, untested, Rohan Prinja, 2015/06/06
- [dhcp] 10/12: dhcp: source for .so, used by some now-redundant functions in interfaces.scm,
Rohan Prinja <=
- [dhcp] 06/12: dhcp: packet objects, untested, Rohan Prinja, 2015/06/06
- [dhcp] 03/12: dhcp: add unused and private-use options, fix some other mistakes, Rohan Prinja, 2015/06/06
- [dhcp] 09/12: dhcp: dhcp configuration objects, Rohan Prinja, 2015/06/06
- [dhcp] 07/12: dhcp: code to read info about network interfaces, untested, Rohan Prinja, 2015/06/06
- [dhcp] 12/12: dhcp: client code, incomplete, Rohan Prinja, 2015/06/06
- [dhcp] 11/12: dhcp: tests for the (dhcp *) modules, incomplete, Rohan Prinja, 2015/06/06