You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
987 B

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