-From c09dd24a7d63988e0acef7d033bd3e088fc005c0 Mon Sep 17 00:00:00 2001
-From: Jiri Popelka <jpopelka@redhat.com>
-Date: Thu, 24 Jan 2013 12:39:50 +0100
-Subject: [PATCH] Linux interface discovery
-
-Use the same discovery code as for *BSD and OS X,
-i.e. the getifaddrs() function.
----
- common/discover.c | 398 +++---------------------------------------------------
- 1 file changed, 17 insertions(+), 381 deletions(-)
-
-diff --git a/common/discover.c b/common/discover.c
-index 1d84219..f2a8f6d 100644
---- a/common/discover.c
-+++ b/common/discover.c
-@@ -379,391 +379,13 @@ end_iface_scan(struct iface_conf_list *ifaces) {
+diff -up dhcp-4.3.5b1/common/discover.c.getifaddrs dhcp-4.3.5b1/common/discover.c
+--- dhcp-4.3.5b1/common/discover.c.getifaddrs 2016-09-12 17:10:39.585374741 +0200
++++ dhcp-4.3.5b1/common/discover.c 2016-09-12 17:15:56.160628636 +0200
+@@ -373,392 +373,13 @@ end_iface_scan(struct iface_conf_list *i
ifaces->sock = -1;
}
- */
-int
-begin_iface_scan(struct iface_conf_list *ifaces) {
-- char buf[256];
+- char buf[IF_LINE_LENGTH];
- int len;
- int i;
-
- */
-static int
-next_iface4(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
-- char buf[256];
+- char buf[IF_LINE_LENGTH];
- int len;
- char *p;
- char *name;
- log_error("Interface name '%s' too long", name);
- return 0;
- }
-- strcpy(info->name, name);
+- strncpy(info->name, name, sizeof(info->name) - 1);
-
-#ifdef ALIAS_NAMED_PERMUTED
- /* interface aliases look like "eth0:1" or "wlan1:3" */
-#endif
-
- memset(&tmp, 0, sizeof(tmp));
-- strcpy(tmp.ifr_name, name);
+- strncpy(tmp.ifr_name, name, sizeof(tmp.ifr_name) - 1);
- if (ioctl(ifaces->sock, SIOCGIFADDR, &tmp) < 0) {
- if (errno == EADDRNOTAVAIL) {
- continue;
- memcpy(&info->addr, &tmp.ifr_addr, sizeof(tmp.ifr_addr));
-
- memset(&tmp, 0, sizeof(tmp));
-- strcpy(tmp.ifr_name, name);
+- strncpy(tmp.ifr_name, name, sizeof(tmp.ifr_name) - 1);
- if (ioctl(ifaces->sock, SIOCGIFFLAGS, &tmp) < 0) {
- log_error("Error getting interface flags for '%s'; %m",
- name);
- */
-static int
-next_iface6(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
-- char buf[256];
+- char buf[IF_LINE_LENGTH];
- int len;
- char *p;
- char *name;
- log_error("IPv6 interface name '%s' too long", name);
- return 0;
- }
-- strcpy(info->name, name);
+- strncpy(info->name, name, sizeof(info->name) - 1);
-
-#ifdef SKIP_DUMMY_INTERFACES
- } while (strncmp(info->name, "dummy", 5) == 0);
- * Get our flags.
- */
- memset(&tmp, 0, sizeof(tmp));
-- strcpy(tmp.ifr_name, name);
+- strncpy(tmp.ifr_name, name, sizeof(tmp.ifr_name) - 1);
- if (ioctl(ifaces->sock, SIOCGIFFLAGS, &tmp) < 0) {
- log_error("Error getting interface flags for '%s'; %m", name);
- *err = 1;
- */
-int
-next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
+- memset(info, 0, sizeof(struct iface_info));
- if (next_iface4(info, err, ifaces)) {
- return 1;
- }
* -----------
*
- * FreeBSD, NetBSD, OpenBSD, and OS X all have the getifaddrs()
-+ * FreeBSD, NetBSD, OpenBSD, OS X and Linux all have the getifaddrs()
++ * FreeBSD, NetBSD, OpenBSD, OS X and Linux all have the getifaddrs()
* function.
*
* The getifaddrs() man page describes the use.
-@@ -811,6 +433,8 @@ begin_iface_scan(struct iface_conf_list *ifaces) {
+@@ -806,6 +427,8 @@ begin_iface_scan(struct iface_conf_list
*/
int
next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
if (ifaces->next == NULL) {
*err = 0;
return 0;
-@@ -822,8 +446,20 @@ next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
- return 0;
+@@ -818,8 +441,20 @@ next_iface(struct iface_info *info, int
}
- strcpy(info->name, ifaces->next->ifa_name);
+ memset(info, 0, sizeof(struct iface_info));
+ strncpy(info->name, ifaces->next->ifa_name, sizeof(info->name) - 1);
- memcpy(&info->addr, ifaces->next->ifa_addr,
- ifaces->next->ifa_addr->sa_len);
+
info->flags = ifaces->next->ifa_flags;
ifaces->next = ifaces->next->ifa_next;
*err = 0;
---
-1.8.1
-