summaryrefslogtreecommitdiff
path: root/security/gvm-libs/files/patch-boreas_ping.c
blob: dda6a1fd38b28bffc7e473485168ec416b7fb607 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--- boreas/ping.c	2021-02-01 10:20:11.000000000 -0500
+++ boreas/ping.c	2021-02-18 13:33:38.298849000 -0500
@@ -26,20 +26,25 @@
 #include <errno.h>
 #include <glib.h>
 #include <ifaddrs.h> /* for getifaddrs() */
-#include <linux/sockios.h>
 #include <net/ethernet.h>
 #include <net/if.h> /* for if_nametoindex() */
 #include <netinet/icmp6.h>
+#include <sys/types.h>
 #include <netinet/in.h>
+#include <netinet/ip.h>
 #include <netinet/ip6.h>
 #include <netinet/ip_icmp.h>
 #include <netinet/tcp.h>
-#include <netpacket/packet.h> /* for sockaddr_ll */
+#ifdef AF_LINK
+#   include <net/if_dl.h>
+#endif
+#ifdef AF_PACKET
+#   include <netpacket/packet.h>
+#endif
 #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
@@ -121,7 +126,7 @@
   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);
@@ -137,7 +142,7 @@
       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);
@@ -224,12 +229,12 @@
   static int init = -1;
 
   icmp = (struct icmphdr *) sendbuf;
-  icmp->type = ICMP_ECHO;
-  icmp->code = 0;
+  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;
@@ -292,7 +297,7 @@
     }
   else
     {
-      dst4.s_addr = dst6_p->s6_addr32[3];
+      dst4.s_addr = dst6_p->s6_addr[12];
       send_icmp_v4 (scanner->icmpv4soc, dst4_p);
     }
 }
@@ -554,7 +559,7 @@
     }
   else
     {
-      dst4.s_addr = dst6_p->s6_addr32[3];
+      dst4.s_addr = dst6_p->s6_addr[12];
       send_tcp_v4 (scanner, dst4_p);
     }
 }
@@ -568,7 +573,7 @@
 static void
 send_arp_v4 (int soc, struct in_addr *dst_p)
 {
-  struct sockaddr_ll soca;
+  struct sockaddr_dl soca;
   struct arp_hdr arphdr;
   int frame_length;
   uint8_t *ether_frame;
@@ -637,10 +642,10 @@
     }
 
   /* Fill in sockaddr_ll.*/
-  soca.sll_ifindex = ifaceindex;
-  soca.sll_family = AF_PACKET;
-  memcpy (soca.sll_addr, src_mac, 6 * sizeof (uint8_t));
-  soca.sll_halen = 6;
+  soca.sdl_index = ifaceindex;
+  soca.sdl_family = AF_LINK;
+  memcpy (soca.sdl_data, src_mac, 6 * sizeof (uint8_t));
+  soca.sdl_alen = 6;
 
   /* Fill ARP header.*/
   /* IP addresses. */
@@ -652,7 +657,7 @@
    * Protocol address length is length of IPv4.
    * OpCode is ARP request. */
   arphdr.htype = htons (1);
-  arphdr.ptype = htons (ETH_P_IP);
+  arphdr.ptype = htons (AF_INET);
   arphdr.hlen = 6;
   arphdr.plen = 4;
   arphdr.opcode = htons (1);
@@ -667,8 +672,8 @@
   memcpy (ether_frame, dst_mac, 6 * sizeof (uint8_t));
   memcpy (ether_frame + 6, src_mac, 6 * sizeof (uint8_t));
   /* ethernet type code */
-  ether_frame[12] = ETH_P_ARP / 256;
-  ether_frame[13] = ETH_P_ARP % 256;
+  ether_frame[12] = AF_ARP / 256;
+  ether_frame[13] = AF_ARP % 256;
   /* ARP header.  ETH_HDRLEN = 14, ARP_HDRLEN = 28 */
   memcpy (ether_frame + 14, &arphdr, 28 * sizeof (uint8_t));
 
@@ -733,7 +738,7 @@
     }
   else
     {
-      dst4.s_addr = dst6_p->s6_addr32[3];
+      dst4.s_addr = dst6_p->s6_addr[12];
       send_arp_v4 (scanner->arpv4soc, dst4_p);
     }
 }