[PATCH 2/2] Add using_dgram as member of globals struct

Radoslav Kolev radoslav.kolev at suse.com
Tue Apr 15 08:33:19 UTC 2025


---
 networking/ping.c | 136 +++++++++++++++++++++++++---------------------
 1 file changed, 74 insertions(+), 62 deletions(-)

diff --git a/networking/ping.c b/networking/ping.c
index b2ff92b82..1df073d3a 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -217,9 +217,82 @@ enum {
 	PINGINTERVAL = 1, /* 1 second */
 	pingsock = 0,
 };
+#if !ENABLE_FEATURE_FANCY_PING
+
+/* Globals for simple version */
 
+struct globals {
+	char *hostname;
+	char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
+	uint16_t myid;
 #if ENABLE_FEATURE_PING_NONROOT
-static int using_dgram;
+	int using_dgram;
+#endif
+} FIX_ALIASING;
+#define G (*(struct globals*)bb_common_bufsiz1)
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
+#define using_dgram  (G.using_dgram )
+#else
+
+/* Globals for fancy version */
+
+struct globals {
+	int if_index;
+	char *str_I;
+	len_and_sockaddr *source_lsa;
+	unsigned datalen;
+	unsigned pingcount; /* must be int-sized */
+	unsigned opt_ttl;
+	unsigned long ntransmitted, nreceived, nrepeats;
+	uint16_t myid;
+	uint8_t pattern;
+	unsigned tmin, tmax; /* in us */
+	unsigned long long tsum; /* in us, sum of all times */
+	unsigned cur_us; /* low word only, we don't need more */
+	unsigned deadline_us;
+	unsigned interval_us;
+	unsigned timeout;
+	unsigned sizeof_rcv_packet;
+	char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */
+	void *snd_packet; /* [datalen + ipv4/ipv6_const] */
+	const char *hostname;
+	const char *dotted;
+	union {
+		struct sockaddr sa;
+		struct sockaddr_in sin;
+#if ENABLE_PING6
+		struct sockaddr_in6 sin6;
+#endif
+	} pingaddr;
+	unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
+#if ENABLE_FEATURE_PING_NONROOT
+	int using_dgram;
+#endif
+} FIX_ALIASING;
+#define G (*(struct globals*)bb_common_bufsiz1)
+#define if_index     (G.if_index    )
+#define source_lsa   (G.source_lsa  )
+#define str_I        (G.str_I       )
+#define datalen      (G.datalen     )
+#define pingcount    (G.pingcount   )
+#define opt_ttl      (G.opt_ttl     )
+#define myid         (G.myid        )
+#define tmin         (G.tmin        )
+#define tmax         (G.tmax        )
+#define tsum         (G.tsum        )
+#define timeout      (G.timeout     )
+#define hostname     (G.hostname    )
+#define dotted       (G.dotted      )
+#define pingaddr     (G.pingaddr    )
+#define rcvd_tbl     (G.rcvd_tbl    )
+#define using_dgram  (G.using_dgram )
+#define INIT_G() do { \
+	setup_common_bufsiz(); \
+	BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
+	datalen = DEFDATALEN; \
+	timeout = MAXWAIT; \
+	tmin = UINT_MAX; \
+} while (0)
 #endif
 
 static void
@@ -293,14 +366,6 @@ static int get_source_port(int fd) {
 
 /* Simple version */
 
-struct globals {
-	char *hostname;
-	char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
-	uint16_t myid;
-} FIX_ALIASING;
-#define G (*(struct globals*)bb_common_bufsiz1)
-#define INIT_G() do { setup_common_bufsiz(); } while (0)
-
 static void noresp(int ign UNUSED_PARAM)
 {
 	printf("No response from %s\n", G.hostname);
@@ -493,59 +558,6 @@ enum {
 };
 
 
-struct globals {
-	int if_index;
-	char *str_I;
-	len_and_sockaddr *source_lsa;
-	unsigned datalen;
-	unsigned pingcount; /* must be int-sized */
-	unsigned opt_ttl;
-	unsigned long ntransmitted, nreceived, nrepeats;
-	uint16_t myid;
-	uint8_t pattern;
-	unsigned tmin, tmax; /* in us */
-	unsigned long long tsum; /* in us, sum of all times */
-	unsigned cur_us; /* low word only, we don't need more */
-	unsigned deadline_us;
-	unsigned interval_us;
-	unsigned timeout;
-	unsigned sizeof_rcv_packet;
-	char *rcv_packet; /* [datalen + MAXIPLEN + MAXICMPLEN] */
-	void *snd_packet; /* [datalen + ipv4/ipv6_const] */
-	const char *hostname;
-	const char *dotted;
-	union {
-		struct sockaddr sa;
-		struct sockaddr_in sin;
-#if ENABLE_PING6
-		struct sockaddr_in6 sin6;
-#endif
-	} pingaddr;
-	unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
-} FIX_ALIASING;
-#define G (*(struct globals*)bb_common_bufsiz1)
-#define if_index     (G.if_index    )
-#define source_lsa   (G.source_lsa  )
-#define str_I        (G.str_I       )
-#define datalen      (G.datalen     )
-#define pingcount    (G.pingcount   )
-#define opt_ttl      (G.opt_ttl     )
-#define myid         (G.myid        )
-#define tmin         (G.tmin        )
-#define tmax         (G.tmax        )
-#define tsum         (G.tsum        )
-#define timeout      (G.timeout     )
-#define hostname     (G.hostname    )
-#define dotted       (G.dotted      )
-#define pingaddr     (G.pingaddr    )
-#define rcvd_tbl     (G.rcvd_tbl    )
-#define INIT_G() do { \
-	setup_common_bufsiz(); \
-	BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
-	datalen = DEFDATALEN; \
-	timeout = MAXWAIT; \
-	tmin = UINT_MAX; \
-} while (0)
 
 
 #define BYTE(bit)	rcvd_tbl[(bit)>>3]
-- 
2.47.1



More information about the busybox mailing list