ports/security/gvm-libs/patches/patch-boreas_ping_c

143 lines
4.1 KiB
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
Index: boreas/ping.c
--- boreas/ping.c.orig
+++ boreas/ping.c
@@ -17,9 +17,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
#include "ping.h"
-#include "../base/prefs.h" /* for prefs_get() */
#include "arp.h"
#include "util.h"
@@ -27,17 +30,16 @@
#include <errno.h>
#include <glib.h>
#include <ifaddrs.h> /* for getifaddrs() */
-#include <linux/sockios.h>
+#include <unistd.h>
+#include <sys/sockio.h>
#include <netinet/icmp6.h>
#include <netinet/in.h>
+#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/types.h>
#include <unistd.h>
#undef G_LOG_DOMAIN
@@ -106,7 +108,7 @@ throttle (int soc, int so_sndbuf)
int cur_so_sendbuf = -1;
/* Get the current size of the output queue size */
- if (ioctl (soc, SIOCOUTQ, &cur_so_sendbuf) == -1)
+ if (ioctl (soc, TIOCOUTQ, &cur_so_sendbuf) == -1)
{
g_warning ("%s: ioctl error: %s", __func__, strerror (errno));
usleep (100000);
@@ -122,7 +124,7 @@ throttle (int soc, int so_sndbuf)
while (cur_so_sendbuf >= so_sndbuf)
{
usleep (100000);
- if (ioctl (soc, SIOCOUTQ, &cur_so_sendbuf) == -1)
+ if (ioctl (soc, TIOCOUTQ, &cur_so_sendbuf) == -1)
{
g_warning ("%s: ioctl error: %s", __func__, strerror (errno));
usleep (100000);
@@ -202,19 +204,19 @@ send_icmp_v4 (int soc, struct in_addr *dst)
int len;
int datalen = 56;
- struct icmphdr *icmp;
+ struct icmp *icmp;
/* Throttling related variables */
static int so_sndbuf = -1; // socket send buffer
static int init = -1;
- icmp = (struct icmphdr *) sendbuf;
- icmp->type = ICMP_ECHO;
- icmp->code = 0;
+ icmp = (struct icmp *) sendbuf;
+ icmp->icmp_type = ICMP_ECHO;
+ icmp->icmp_code = 0;
len = 8 + datalen;
- icmp->checksum = 0;
- icmp->checksum = in_cksum ((u_short *) icmp, len);
+ icmp->icmp_cksum = 0;
+ icmp->icmp_cksum = in_cksum ((u_short *) icmp, len);
memset (&soca, 0, sizeof (soca));
soca.sin_family = AF_INET;
@@ -254,24 +256,14 @@ send_icmp (gpointer key, gpointer value, gpointer scan
struct in_addr dst4;
struct in_addr *dst4_p = &dst4;
static int count = 0;
- int icmp_retries, grace_period = 0;
- const char *tmp;
- if ((icmp_retries =
- (tmp = prefs_get ("icmp_retries")) != NULL ? atoi (tmp) : 1)
- <= 0)
- icmp_retries = 1;
- else if (icmp_retries > 1)
- grace_period =
- (tmp = prefs_get ("icmp_grace_period")) != NULL ? atoi (tmp) : 0;
scanner = (scanner_t *) scanner_p;
- // we may send multiple icmp message to reduce to chance of unwanted drops
- for (int i = 0; i < icmp_retries; i++)
- {
if (g_hash_table_contains (scanner->hosts_data->alivehosts, key))
return;
- if (++count % BURST == 0)
+
+ count++;
+ if (count % BURST == 0)
usleep (BURST_TIMEOUT);
if (gvm_host_get_addr6 ((gvm_host_t *) value, dst6_p) < 0)
@@ -287,12 +279,9 @@ send_icmp (gpointer key, gpointer value, gpointer scan
}
else
{
- dst4.s_addr = dst6_p->s6_addr32[3];
+ dst4.s_addr = dst6_p->s6_addr[12];
send_icmp_v4 (scanner->icmpv4soc, dst4_p);
}
- if (grace_period > 0)
- usleep (grace_period);
- }
}
/**
@@ -552,7 +541,7 @@ send_tcp (gpointer key, gpointer value, gpointer scann
}
else
{
- dst4.s_addr = dst6_p->s6_addr32[3];
+ dst4.s_addr = dst6_p->s6_addr[12];
send_tcp_v4 (scanner, dst4_p);
}
}
@@ -602,7 +591,7 @@ send_arp (gpointer host_value_str, gpointer value, gpo
/* Need to transform the IPv6 mapped IPv4 address back to an IPv4 string.
* We can not just use the host_value_str as it might be an IPv4 mapped
* IPv6 string. */
- if (inet_ntop (AF_INET, &(dst6_p->s6_addr32[3]), ipv4_str,
+ if (inet_ntop (AF_INET, &(dst6_p->s6_addr[12]), ipv4_str,
sizeof (ipv4_str))
== NULL)
{