blob: 9a13ba1441ee4cc2b9478ac428d5c68be0613446 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 37b2dda9b1d62eb91028f6d590beddd36f7b79c8 Mon Sep 17 00:00:00 2001
2From: Nathan Samson <nathan@nathansamson.be>
3Date: Mon, 1 Feb 2016 21:37:22 +0100
4Subject: [PATCH] Modify get ip from iface method.
5
6This used to use a RAW socket, while now it used a DGRAM socket.
7Previously it failed with operation not permitted, while this version
8seems to work reliably.
9
10--- a/src/util.c
11+++ b/src/util.c
12@@ -174,11 +174,13 @@ get_iface_ip(const char *ifname)
13 u_int32_t ip;
14
15 /* Create a socket */
16- if ((sockd = socket(AF_INET, SOCK_RAW, htons(0x8086))) < 0) {
17+ if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
18 debug(LOG_ERR, "socket(): %s", strerror(errno));
19 return NULL;
20 }
21
22+ /* I want to get an IPv4 IP address */
23+ if_data.ifr_addr.sa_family = AF_INET;
24 /* Get IP of internal interface */
25 strncpy(if_data.ifr_name, ifname, 15);
26 if_data.ifr_name[15] = '\0';