* manually add pygments hatchling DEP and update .cache
[t2sde.git] / package / network / netkit-base / ping.patch.musl
blobbf48788f0bf346581c79ccbc4738cb5bedaf2789
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
3
4 # T2 SDE: package/*/netkit-base/ping.patch.musl
5 # Copyright (C) 2021 The T2 SDE Project
6
7 # More information can be found in the files COPYING and README.
8
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
14 # version.
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
23 @@ -61,11 +61,14 @@
24   *     This program has to run SUID to ROOT to access the ICMP socket.
25   */
27 +#define _GNU_SOURCE
28 +#include <sys/types.h>
30  #include <sys/param.h>
31  #include <sys/socket.h>
32  #include <sys/file.h>
33  #include <sys/time.h>
34 -#include <sys/signal.h>
35 +#include <signal.h>
37  #include <netinet/in.h>
38  #include <netinet/ip.h>
39 @@ -184,10 +187,10 @@
40  static u_int8_t inpack[IP_MAXPACKET];
41  static int ipoptlen;
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))
54 @@ -206,8 +209,8 @@
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))
65 @@ -343,13 +346,13 @@
66   */
67  static
68  void
69 -pr_iph(struct ip *ip)
70 +pr_iph(struct netkit_ip *ip)
71  {
72         u_int hlen;
73         u_char *cp;
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      "
80                "Src      Dst Data\n");
81 @@ -361,7 +364,7 @@
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++);
88         }
89         putchar('\n');
90 @@ -372,7 +375,7 @@
91   *     Dump some info on a returned (via ICMP) IP packet.
92   */
93  static void
94 -pr_retip(struct ip *ip)
95 +pr_retip(struct netkit_ip *ip)
96  {
97         int hlen;
98         u_char *cp;
99 @@ -402,7 +405,7 @@
100   */
101  static 
102  void
103 -pr_icmph(struct icmp *icp)
104 +pr_icmph(struct netkit_icmp *icp)
106         switch(icp->icmp_type) {
107         case ICMP_ECHOREPLY:
108 @@ -465,11 +468,11 @@
109                         break;
110                 }
111                 /* Print returned IP header information */
112 -               pr_retip((struct ip *)icp->icmp_data);
113 +               pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
114                 break;
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);
119                 break;
120         case ICMP_REDIRECT:
121                 switch(icp->icmp_code) {
122 @@ -489,8 +492,8 @@
123                         printf("Redirect, Bad Code: %d", icp->icmp_code);
124                         break;
125                 }
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);
130                 break;
131         case ICMP_ECHO:
132                 printf("Echo Request\n");
133 @@ -509,12 +512,12 @@
134                             icp->icmp_code);
135                         break;
136                 }
137 -               pr_retip((struct ip *)icp->icmp_data);
138 +               pr_retip((struct netkit_ip *)icp->netkit_icmp_data);
139                 break;
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);
146                 break;
147         case ICMP_TIMESTAMP:
148                 printf("Timestamp\n");
149 @@ -671,8 +674,8 @@
150  int
151  pr_pack(int packlen, struct sockaddr_in *from)
153 -       struct ip *ip;
154 -       struct icmp *icp;
155 +       struct netkit_ip *ip;
156 +       struct netkit_icmp *icp;
157         struct timeval now, packettv;
158         long triptime = 0;
159         int hlen, dupflag;
160 @@ -683,7 +686,7 @@
161         /* Check the IP header */
162         ip = INPACK_IP;
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) {
167                         fprintf(stderr,
168                                 "ping: packet too short (%d octets with "
169 @@ -701,7 +704,7 @@
170                 }
171                 return 0;
172         }
173 -       ipoptlen = hlen - sizeof(struct ip);
174 +       ipoptlen = hlen - sizeof(struct netkit_ip);
175         packlen -= hlen;
176         icp = INPACK_ICMP;
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 */
185                 nreceived++;
186                 if (timing) {
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 @@
193                                 tmax = triptime;
194                 }
196 -               if (TST(icp->icmp_seq % mx_dup_ck)) {
197 +               if (TST(icp->netkit_icmp_seq % mx_dup_ck)) {
198                         ++nrepeats;
199                         --nreceived;
200                         dupflag = 1;
201                 } 
202                 else {
203 -                       SET(icp->icmp_seq % mx_dup_ck);
204 +                       SET(icp->netkit_icmp_seq % mx_dup_ck);
205                         dupflag = 0;
206                 }
208 @@ -756,7 +759,7 @@
209                 }
210                 else {
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);
215                         if (timing) {
216                                 printf(" time=%ld.%ld ms", triptime/10,
217 @@ -848,7 +851,7 @@
218  void
219  pinger(void)
221 -       struct icmp *icp;
222 +       struct netkit_icmp *icp;
223         size_t packlen;
224         int sentlen;
226 @@ -856,10 +859,10 @@
227         icp->icmp_type = ICMP_ECHO;
228         icp->icmp_code = 0;
229         icp->icmp_cksum = 0;
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);
238         if (timing) {
239                 struct timeval tmptm;
240 @@ -1101,7 +1104,7 @@
241          * Clear environment.
242          * (This protects against various problems with libc.)
243          */
244 -       __environ = &null;
245 +       //__environ = &null;
247         /*
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
251 @@ -44,7 +44,7 @@
252  /*
253   * Structure of an internet header, naked of options.
254   */
255 -struct ip {
256 +struct netkit_ip {
257  #if BYTE_ORDER == LITTLE_ENDIAN
258         u_int8_t  ip_hl:4;                      /* header length */
259         u_int8_t  ip_v:4;                       /* version */
260 @@ -65,20 +65,20 @@
261  };
264 -struct icmp {
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 */
269         union {
270                 struct in_addr ih_gwaddr;       /* gateway address */
271 -               struct ih_idseq {               /* echo datagram */
272 -                       u_int16_t icd_id;
273 -                       u_int16_t icd_seq;
274 -               } ih_idseq;
275 +               struct netkit_ih_idseq {                /* echo datagram */
276 +                       u_int16_t netkit_icd_id;
277 +                       u_int16_t netkit_icd_seq;
278 +               } netkit_ih_idseq;
279         } icmp_hun;
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];
289  };