# --- T2-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by scripts/Create-CopyPatch. # # T2 SDE: package/*/netkit-base/ping.patch.musl # Copyright (C) 2021 The T2 SDE Project # # More information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # --- T2-COPYRIGHT-NOTE-END --- Fix compiling against musl. Mostly prefix ip and icmp structs with "netkit_" to prevent conflits with netinet/ip*.h definitions. Also define _GNU_SOURCE macro + include types.h to convert u_int*_t to uint*_t. --- netkit-base-0.17/ping/ping.c.vanilla 2021-08-04 22:03:25.335849434 +0200 +++ netkit-base-0.17/ping/ping.c 2021-08-04 22:06:35.067829112 +0200 @@ -61,11 +61,14 @@ * This program has to run SUID to ROOT to access the ICMP socket. */ +#define _GNU_SOURCE +#include + #include #include #include #include -#include +#include #include #include @@ -184,10 +187,10 @@ static u_int8_t inpack[IP_MAXPACKET]; static int ipoptlen; -#define INPACK_IP ((struct ip *)inpack) -#define INPACK_OPTS (inpack+sizeof(struct ip)) -#define INPACK_ICMP ((struct icmp *)(inpack+sizeof(struct ip)+ipoptlen)) -#define INPACK_PAYLOAD (INPACK_ICMP->icmp_data) +#define INPACK_IP ((struct netkit_ip *)inpack) +#define INPACK_OPTS (inpack+sizeof(struct netkit_ip)) +#define INPACK_ICMP ((struct netkit_icmp *)(inpack+sizeof(struct netkit_ip)+ipoptlen)) +#define INPACK_PAYLOAD (INPACK_ICMP->netkit_icmp_data) #define INPACK_TIME ((struct timeval *)INPACK_PAYLOAD) #define INPACK_DATA (INPACK_PAYLOAD+(timing ? sizeof(struct timeval) : 0)) @@ -206,8 +209,8 @@ static u_int8_t outpack[IP_MAXPACKET]; static int datalen = DEFDATALEN; -#define OUTPACK_ICMP ((struct icmp *)outpack) -#define OUTPACK_PAYLOAD (OUTPACK_ICMP->icmp_data) +#define OUTPACK_ICMP ((struct netkit_icmp *)outpack) +#define OUTPACK_PAYLOAD (OUTPACK_ICMP->netkit_icmp_data) #define OUTPACK_TIME ((struct timeval *)OUTPACK_PAYLOAD) #define OUTPACK_DATA (OUTPACK_PAYLOAD+(timing ? sizeof(struct timeval) : 0)) @@ -343,13 +346,13 @@ */ static void -pr_iph(struct ip *ip) +pr_iph(struct netkit_ip *ip) { u_int hlen; u_char *cp; hlen = ip->ip_hl << 2; - cp = ((u_char *)ip) + sizeof(struct ip); /* point to options */ + cp = ((u_char *)ip) + sizeof(struct netkit_ip); /* point to options */ printf("Vr HL TOS Len ID Flg off TTL Pro cks " "Src Dst Data\n"); @@ -361,7 +364,7 @@ printf(" %s ", inet_ntoa(ip->ip_src)); printf(" %s ", inet_ntoa(ip->ip_dst)); /* dump any option bytes */ - while (hlen-- > sizeof(struct ip)) { + while (hlen-- > sizeof(struct netkit_ip)) { printf("%02x", *cp++); } putchar('\n'); @@ -372,7 +375,7 @@ * Dump some info on a returned (via ICMP) IP packet. */ static void -pr_retip(struct ip *ip) +pr_retip(struct netkit_ip *ip) { int hlen; u_char *cp; @@ -402,7 +405,7 @@ */ static void -pr_icmph(struct icmp *icp) +pr_icmph(struct netkit_icmp *icp) { switch(icp->icmp_type) { case ICMP_ECHOREPLY: @@ -465,11 +468,11 @@ break; } /* Print returned IP header information */ - pr_retip((struct ip *)icp->icmp_data); + pr_retip((struct netkit_ip *)icp->netkit_icmp_data); break; case ICMP_SOURCE_QUENCH: printf("Source Quench\n"); - pr_retip((struct ip *)icp->icmp_data); + pr_retip((struct netkit_ip *)icp->netkit_icmp_data); break; case ICMP_REDIRECT: switch(icp->icmp_code) { @@ -489,8 +492,8 @@ printf("Redirect, Bad Code: %d", icp->icmp_code); break; } - printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr)); - pr_retip((struct ip *)icp->icmp_data); + printf("(New addr: %s)\n", inet_ntoa(icp->netkit_icmp_gwaddr)); + pr_retip((struct netkit_ip *)icp->netkit_icmp_data); break; case ICMP_ECHO: printf("Echo Request\n"); @@ -509,12 +512,12 @@ icp->icmp_code); break; } - pr_retip((struct ip *)icp->icmp_data); + pr_retip((struct netkit_ip *)icp->netkit_icmp_data); break; case ICMP_PARAMETERPROB: printf("Parameter problem: IP address = %s\n", - inet_ntoa(icp->icmp_gwaddr)); - pr_retip((struct ip *)icp->icmp_data); + inet_ntoa(icp->netkit_icmp_gwaddr)); + pr_retip((struct netkit_ip *)icp->netkit_icmp_data); break; case ICMP_TIMESTAMP: printf("Timestamp\n"); @@ -671,8 +674,8 @@ int pr_pack(int packlen, struct sockaddr_in *from) { - struct ip *ip; - struct icmp *icp; + struct netkit_ip *ip; + struct netkit_icmp *icp; struct timeval now, packettv; long triptime = 0; int hlen, dupflag; @@ -683,7 +686,7 @@ /* Check the IP header */ ip = INPACK_IP; hlen = ip->ip_hl << 2; - if (hlen < (int)sizeof(struct ip)) { + if (hlen < (int)sizeof(struct netkit_ip)) { if (options & F_VERBOSE) { fprintf(stderr, "ping: packet too short (%d octets with " @@ -701,7 +704,7 @@ } return 0; } - ipoptlen = hlen - sizeof(struct ip); + ipoptlen = hlen - sizeof(struct netkit_ip); packlen -= hlen; icp = INPACK_ICMP; @@ -718,11 +721,11 @@ /* Now the ICMP part */ if (icp->icmp_type == ICMP_ECHOREPLY) { - if (icp->icmp_id != ident) + if (icp->netkit_icmp_id != ident) return 0; /* 'Twas not our ECHO */ nreceived++; if (timing) { - memcpy(&packettv, icp->icmp_data, sizeof(struct timeval)); + memcpy(&packettv, icp->netkit_icmp_data, sizeof(struct timeval)); tvsub(&now, &packettv); /* precision: tenths of milliseconds */ @@ -735,13 +738,13 @@ tmax = triptime; } - if (TST(icp->icmp_seq % mx_dup_ck)) { + if (TST(icp->netkit_icmp_seq % mx_dup_ck)) { ++nrepeats; --nreceived; dupflag = 1; } else { - SET(icp->icmp_seq % mx_dup_ck); + SET(icp->netkit_icmp_seq % mx_dup_ck); dupflag = 0; } @@ -756,7 +759,7 @@ } else { printf("%d octets from %s: icmp_seq=%u", packlen, - inet_ntoa(from->sin_addr), icp->icmp_seq); + inet_ntoa(from->sin_addr), icp->netkit_icmp_seq); printf(" ttl=%d", ip->ip_ttl); if (timing) { printf(" time=%ld.%ld ms", triptime/10, @@ -848,7 +851,7 @@ void pinger(void) { - struct icmp *icp; + struct netkit_icmp *icp; size_t packlen; int sentlen; @@ -856,10 +859,10 @@ icp->icmp_type = ICMP_ECHO; icp->icmp_code = 0; icp->icmp_cksum = 0; - icp->icmp_seq = ntransmitted++; - icp->icmp_id = ident; + icp->netkit_icmp_seq = ntransmitted++; + icp->netkit_icmp_id = ident; - CLR(icp->icmp_seq % mx_dup_ck); + CLR(icp->netkit_icmp_seq % mx_dup_ck); if (timing) { struct timeval tmptm; @@ -1101,7 +1104,7 @@ * Clear environment. * (This protects against various problems with libc.) */ - __environ = &null; + //__environ = &null; /* * Certain options require that the man behind the curtain be --- netkit-base-0.17/ping/pingpack.h.vanilla 2000-02-04 10:38:37.000000000 +0100 +++ netkit-base-0.17/ping/pingpack.h 2021-08-04 19:15:24.480929177 +0200 @@ -44,7 +44,7 @@ /* * Structure of an internet header, naked of options. */ -struct ip { +struct netkit_ip { #if BYTE_ORDER == LITTLE_ENDIAN u_int8_t ip_hl:4; /* header length */ u_int8_t ip_v:4; /* version */ @@ -65,20 +65,20 @@ }; -struct icmp { +struct netkit_icmp { u_int8_t icmp_type; /* type of message, see below */ u_int8_t icmp_code; /* type sub code */ u_int16_t icmp_cksum; /* ones complement checksum of struct */ union { struct in_addr ih_gwaddr; /* gateway address */ - struct ih_idseq { /* echo datagram */ - u_int16_t icd_id; - u_int16_t icd_seq; - } ih_idseq; + struct netkit_ih_idseq { /* echo datagram */ + u_int16_t netkit_icd_id; + u_int16_t netkit_icd_seq; + } netkit_ih_idseq; } icmp_hun; -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define netkit_icmp_gwaddr icmp_hun.ih_gwaddr +#define netkit_icmp_id icmp_hun.netkit_ih_idseq.netkit_icd_id +#define netkit_icmp_seq icmp_hun.netkit_ih_idseq.netkit_icd_seq - u_int8_t icmp_data[1]; + u_int8_t netkit_icmp_data[1]; };