1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 # T2 SDE: package/*/netkit-base/ping.patch.musl
5 # Copyright (C) 2021 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
15 # --- T2-COPYRIGHT-NOTE-END ---
17 Fix compiling against musl. Mostly prefix ip and icmp structs with "netkit_"
18 to prevent conflits with netinet/ip*.h definitions. Also define _GNU_SOURCE
19 macro + include types.h to convert u_int*_t to uint*_t.
21 --- netkit-base-0.17/ping/ping.c.vanilla 2021-08-04 22:03:25.335849434 +0200
22 +++ netkit-base-0.17/ping/ping.c 2021-08-04 22:06:35.067829112 +0200
24 * This program has to run SUID to ROOT to access the ICMP socket.
28 +#include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/socket.h>
34 -#include <sys/signal.h>
37 #include <netinet/in.h>
38 #include <netinet/ip.h>
40 static u_int8_t inpack[IP_MAXPACKET];
43 -#define INPACK_IP ((struct ip *)inpack)
44 -#define INPACK_OPTS (inpack+sizeof(struct ip))
45 -#define INPACK_ICMP ((struct icmp *)(inpack+sizeof(struct ip)+ipoptlen))
46 -#define INPACK_PAYLOAD (INPACK_ICMP->icmp_data)
47 +#define INPACK_IP ((struct netkit_ip *)inpack)
48 +#define INPACK_OPTS (inpack+sizeof(struct netkit_ip))
49 +#define INPACK_ICMP ((struct netkit_icmp *)(inpack+sizeof(struct netkit_ip)+ipoptlen))
50 +#define INPACK_PAYLOAD (INPACK_ICMP->netkit_icmp_data)
51 #define INPACK_TIME ((struct timeval *)INPACK_PAYLOAD)
52 #define INPACK_DATA (INPACK_PAYLOAD+(timing ? sizeof(struct timeval) : 0))
55 static u_int8_t outpack[IP_MAXPACKET];
56 static int datalen = DEFDATALEN;
58 -#define OUTPACK_ICMP ((struct icmp *)outpack)
59 -#define OUTPACK_PAYLOAD (OUTPACK_ICMP->icmp_data)
60 +#define OUTPACK_ICMP ((struct netkit_icmp *)outpack)
61 +#define OUTPACK_PAYLOAD (OUTPACK_ICMP->netkit_icmp_data)
62 #define OUTPACK_TIME ((struct timeval *)OUTPACK_PAYLOAD)
63 #define OUTPACK_DATA (OUTPACK_PAYLOAD+(timing ? sizeof(struct timeval) : 0))
69 -pr_iph(struct ip *ip)
70 +pr_iph(struct netkit_ip *ip)
75 hlen = ip->ip_hl << 2;
76 - cp = ((u_char *)ip) + sizeof(struct ip); /* point to options */
77 + cp = ((u_char *)ip) + sizeof(struct netkit_ip); /* point to options */
79 printf("Vr HL TOS Len ID Flg off TTL Pro cks "
82 printf(" %s ", inet_ntoa(ip->ip_src));
83 printf(" %s ", inet_ntoa(ip->ip_dst));
84 /* dump any option bytes */
85 - while (hlen-- > sizeof(struct ip)) {
86 + while (hlen-- > sizeof(struct netkit_ip)) {
87 printf("%02x", *cp++);
91 * Dump some info on a returned (via ICMP) IP packet.
94 -pr_retip(struct ip *ip)
95 +pr_retip(struct netkit_ip *ip)
103 -pr_icmph(struct icmp *icp)
104 +pr_icmph(struct netkit_icmp *icp)
106 switch(icp->icmp_type) {
108 @@ -465,11 +468,11 @@
111 /* Print returned IP header information */
112 - pr_retip((struct ip *)icp->icmp_data);
113 + pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
115 case ICMP_SOURCE_QUENCH:
116 printf("Source Quench\n");
117 - pr_retip((struct ip *)icp->icmp_data);
118 + pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
121 switch(icp->icmp_code) {
123 printf("Redirect, Bad Code: %d", icp->icmp_code);
126 - printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr));
127 - pr_retip((struct ip *)icp->icmp_data);
128 + printf("(New addr: %s)\n", inet_ntoa(icp->netkit_icmp_gwaddr));
129 + pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
132 printf("Echo Request\n");
133 @@ -509,12 +512,12 @@
137 - pr_retip((struct ip *)icp->icmp_data);
138 + pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
140 case ICMP_PARAMETERPROB:
141 printf("Parameter problem: IP address = %s\n",
142 - inet_ntoa(icp->icmp_gwaddr));
143 - pr_retip((struct ip *)icp->icmp_data);
144 + inet_ntoa(icp->netkit_icmp_gwaddr));
145 + pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
148 printf("Timestamp\n");
151 pr_pack(int packlen, struct sockaddr_in *from)
155 + struct netkit_ip *ip;
156 + struct netkit_icmp *icp;
157 struct timeval now, packettv;
161 /* Check the IP header */
163 hlen = ip->ip_hl << 2;
164 - if (hlen < (int)sizeof(struct ip)) {
165 + if (hlen < (int)sizeof(struct netkit_ip)) {
166 if (options & F_VERBOSE) {
168 "ping: packet too short (%d octets with "
173 - ipoptlen = hlen - sizeof(struct ip);
174 + ipoptlen = hlen - sizeof(struct netkit_ip);
178 @@ -718,11 +721,11 @@
180 /* Now the ICMP part */
181 if (icp->icmp_type == ICMP_ECHOREPLY) {
182 - if (icp->icmp_id != ident)
183 + if (icp->netkit_icmp_id != ident)
184 return 0; /* 'Twas not our ECHO */
187 - memcpy(&packettv, icp->icmp_data, sizeof(struct timeval));
188 + memcpy(&packettv, icp->netkit_icmp_data, sizeof(struct timeval));
189 tvsub(&now, &packettv);
191 /* precision: tenths of milliseconds */
192 @@ -735,13 +738,13 @@
196 - if (TST(icp->icmp_seq % mx_dup_ck)) {
197 + if (TST(icp->netkit_icmp_seq % mx_dup_ck)) {
203 - SET(icp->icmp_seq % mx_dup_ck);
204 + SET(icp->netkit_icmp_seq % mx_dup_ck);
211 printf("%d octets from %s: icmp_seq=%u", packlen,
212 - inet_ntoa(from->sin_addr), icp->icmp_seq);
213 + inet_ntoa(from->sin_addr), icp->netkit_icmp_seq);
214 printf(" ttl=%d", ip->ip_ttl);
216 printf(" time=%ld.%ld ms", triptime/10,
222 + struct netkit_icmp *icp;
226 @@ -856,10 +859,10 @@
227 icp->icmp_type = ICMP_ECHO;
230 - icp->icmp_seq = ntransmitted++;
231 - icp->icmp_id = ident;
232 + icp->netkit_icmp_seq = ntransmitted++;
233 + icp->netkit_icmp_id = ident;
235 - CLR(icp->icmp_seq % mx_dup_ck);
236 + CLR(icp->netkit_icmp_seq % mx_dup_ck);
239 struct timeval tmptm;
240 @@ -1101,7 +1104,7 @@
242 * (This protects against various problems with libc.)
245 + //__environ = &null;
248 * Certain options require that the man behind the curtain be
249 --- netkit-base-0.17/ping/pingpack.h.vanilla 2000-02-04 10:38:37.000000000 +0100
250 +++ netkit-base-0.17/ping/pingpack.h 2021-08-04 19:15:24.480929177 +0200
253 * Structure of an internet header, naked of options.
257 #if BYTE_ORDER == LITTLE_ENDIAN
258 u_int8_t ip_hl:4; /* header length */
259 u_int8_t ip_v:4; /* version */
265 +struct netkit_icmp {
266 u_int8_t icmp_type; /* type of message, see below */
267 u_int8_t icmp_code; /* type sub code */
268 u_int16_t icmp_cksum; /* ones complement checksum of struct */
270 struct in_addr ih_gwaddr; /* gateway address */
271 - struct ih_idseq { /* echo datagram */
275 + struct netkit_ih_idseq { /* echo datagram */
276 + u_int16_t netkit_icd_id;
277 + u_int16_t netkit_icd_seq;
280 -#define icmp_gwaddr icmp_hun.ih_gwaddr
281 -#define icmp_id icmp_hun.ih_idseq.icd_id
282 -#define icmp_seq icmp_hun.ih_idseq.icd_seq
283 +#define netkit_icmp_gwaddr icmp_hun.ih_gwaddr
284 +#define netkit_icmp_id icmp_hun.netkit_ih_idseq.netkit_icd_id
285 +#define netkit_icmp_seq icmp_hun.netkit_ih_idseq.netkit_icd_seq
287 - u_int8_t icmp_data[1];
288 + u_int8_t netkit_icmp_data[1];