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.

26 lines
920 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. --- a/src/util.c
  9. +++ b/src/util.c
  10. @@ -174,11 +174,13 @@ get_iface_ip(const char *ifname)
  11. u_int32_t ip;
  12. /* Create a socket */
  13. - if ((sockd = socket(AF_INET, SOCK_RAW, htons(0x8086))) < 0) {
  14. + if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  15. debug(LOG_ERR, "socket(): %s", strerror(errno));
  16. return NULL;
  17. }
  18. + /* I want to get an IPv4 IP address */
  19. + if_data.ifr_addr.sa_family = AF_INET;
  20. /* Get IP of internal interface */
  21. strncpy(if_data.ifr_name, ifname, 15);
  22. if_data.ifr_name[15] = '\0';