};
-static union {
- struct sockaddr sa;
- struct sockaddr_in sin;
+struct globals {
+ int pingsock;
+ len_and_sockaddr *source_lsa;
+ unsigned datalen;
+ int if_index;
+ unsigned long ntransmitted, nreceived, nrepeats, pingcount;
+ uint16_t myid;
+ unsigned tmin, tmax;
+ unsigned long tsum;
+ const char *hostname;
+ const char *dotted;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
#if ENABLE_PING6
- struct sockaddr_in6 sin6;
+ struct sockaddr_in6 sin6;
#endif
-} pingaddr;
-static len_and_sockaddr *source_lsa;
-static int pingsock = -1;
-static unsigned datalen; /* intentionally uninitialized to work around gcc bug */
-
-static int if_index;
-
-static unsigned long ntransmitted, nreceived, nrepeats, pingcount;
-static int myid;
-static unsigned tmin = UINT_MAX, tmax;
-static unsigned long tsum;
-static char rcvd_tbl[MAX_DUP_CHK / 8];
+ } pingaddr;
+ char rcvd_tbl[MAX_DUP_CHK / 8];
+};
+#define G (*(struct globals*)&bb_common_bufsiz1)
+#define pingsock (G.pingsock )
+#define source_lsa (G.source_lsa )
+#define datalen (G.datalen )
+#define if_index (G.if_index )
+#define ntransmitted (G.ntransmitted)
+#define nreceived (G.nreceived )
+#define nrepeats (G.nrepeats )
+#define pingcount (G.pingcount )
+#define myid (G.myid )
+#define tmin (G.tmin )
+#define tmax (G.tmax )
+#define tsum (G.tsum )
+#define hostname (G.hostname )
+#define dotted (G.dotted )
+#define pingaddr (G.pingaddr )
+#define rcvd_tbl (G.rcvd_tbl )
+void BUG_ping_globals_too_big(void);
+#define INIT_G() do { \
+ if (sizeof(G) > COMMON_BUFSIZE) \
+ BUG_ping_globals_too_big(); \
+ pingsock = -1; \
+ tmin = UINT_MAX; \
+} while (0)
-static const char *hostname;
-static const char *dotted;
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
pkt->icmp_cksum = 0;
pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp_id = myid;
+
+// I can't fucking believe someone thought it's okay to do it like this...
+// where's hton? Where is a provision for different word size, structure padding, etc??
+// FIXME!
gettimeofday((struct timeval *) &pkt->icmp_dun, NULL);
+
pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN);
sendping_tail(sendping4, pkt, datalen + ICMP_MINLEN);
pkt->icmp6_cksum = 0;
pkt->icmp6_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp6_id = myid;
+
+// FIXME!
gettimeofday((struct timeval *) &pkt->icmp6_data8[4], NULL);
sendping_tail(sendping6, pkt, datalen + sizeof(struct icmp6_hdr));
char *opt_c, *opt_s, *opt_I;
USE_PING6(sa_family_t af = AF_UNSPEC;)
+ INIT_G();
+
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
/* exactly one argument needed, -v and -q don't mix */
source_lsa = xdotted2sockaddr(opt_I, 0);
}
}
- myid = (int16_t) getpid();
+ myid = (uint16_t) getpid();
hostname = argv[optind];
#if ENABLE_PING6
if (option_mask32 & OPT_IPV4)