Skip to content

Commit 37b2dda

Browse files
committed
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.
1 parent 1b835ba commit 37b2dda

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ get_iface_ip(const char *ifname)
174174
u_int32_t ip;
175175

176176
/* Create a socket */
177-
if ((sockd = socket(AF_INET, SOCK_RAW, htons(0x8086))) < 0) {
177+
if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
178178
debug(LOG_ERR, "socket(): %s", strerror(errno));
179179
return NULL;
180180
}
181181

182+
/* I want to get an IPv4 IP address */
183+
if_data.ifr_addr.sa_family = AF_INET;
182184
/* Get IP of internal interface */
183185
strncpy(if_data.ifr_name, ifname, 15);
184186
if_data.ifr_name[15] = '\0';

0 commit comments

Comments
 (0)