packages/net/wifidog/patches/020-Modify-get-ip-from-iface-method.patch
Eneas U de Queiroz 6f09843053 wifidog: fix getting ip from interface, cleanup
Patch taken from upstream fixes an Invalid argument error while trying
to get the IP address of an interface.
Makefile was updated to current style.
(cherry-picked from 5ab9f3e357)

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
2019-07-11 11:41:21 -03:00

28 lines
987 B
Diff

From 37b2dda9b1d62eb91028f6d590beddd36f7b79c8 Mon Sep 17 00:00:00 2001
From: Nathan Samson <nathan@nathansamson.be>
Date: Mon, 1 Feb 2016 21:37:22 +0100
Subject: [PATCH] Modify get ip from iface method.
This used to use a RAW socket, while now it used a DGRAM socket.
Previously it failed with operation not permitted, while this version
seems to work reliably.
diff --git a/src/util.c b/src/util.c
index 46ec5a2..426ba13 100644
--- a/src/util.c
+++ b/src/util.c
@@ -174,11 +174,13 @@ get_iface_ip(const char *ifname)
u_int32_t ip;
/* Create a socket */
- if ((sockd = socket(AF_INET, SOCK_RAW, htons(0x8086))) < 0) {
+ if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
debug(LOG_ERR, "socket(): %s", strerror(errno));
return NULL;
}
+ /* I want to get an IPv4 IP address */
+ if_data.ifr_addr.sa_family = AF_INET;
/* Get IP of internal interface */
strncpy(if_data.ifr_name, ifname, 15);
if_data.ifr_name[15] = '\0';