aboutsummaryrefslogtreecommitdiff
path: root/net/net-mtools/patches/006-msend-send-a-limited-number-of-test-packets.patch
blob: 8e8db738eaa9448eaacb7c650a14449264adc74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 1013b0a83aef868e6cd33b2f467b9f886b41e7bc Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: Fri, 22 Apr 2022 12:59:56 +0300
Subject: [PATCH 6/6] msend: send a limited number of test packets

For easier integration into a selftest framework, limit the amount of
packets that the program sends via a command-line argument.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 msend.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

--- a/msend.c
+++ b/msend.c
@@ -56,7 +56,7 @@ typedef struct timerhandler_s {
 	struct sock *to;
 	char *achOut;
 	int len;
-	int n;
+	int num_pkts;
 } timerhandler_t;
 timerhandler_t handler_par;
 void timerhandler();
@@ -82,6 +82,7 @@ Usage:  msend [-g GROUP] [-p PORT] [-joi
                the first router will drop the packets!  Default: 1\n\
   -text \"text\" Specify a string to use as payload in the packets, also\n\
                displayed by the mreceive command.  Default: empty\n\
+  -c           Number of packets to send. Default: send indefinitely\n\
   -n           Encode -text argument as a number instead of a string.\n\
   -v           Print version information.\n\
   -h           Print the command usage.\n\n", VERSION);
@@ -97,6 +98,7 @@ int main(int argc, char *argv[])
 	struct itimerval times;
 	sigset_t sigset;
 	struct sigaction act;
+	int num_pkts = 0;
 	int ret, i;
 
 	if ((argc == 2) && (strcmp(argv[ii], "-v") == 0)) {
@@ -171,6 +173,12 @@ int main(int argc, char *argv[])
 			ii++;
 			NUM = 1;
 			ii++;
+		} else if (strcmp(argv[ii], "-c") == 0) {
+			ii++;
+			if ((ii < argc) && !(strchr(argv[ii], '-'))) {
+				num_pkts = atoi(argv[ii]);
+				ii++;
+			}
 		} else if (strcmp(argv[ii], "-text") == 0) {
 			ii++;
 			if ((ii < argc) && !(strchr(argv[ii], '-'))) {
@@ -255,7 +263,7 @@ int main(int argc, char *argv[])
 		handler_par.to = &to;
 		handler_par.achOut = achOut;
 		handler_par.len = strlen(achOut) + 1;
-		handler_par.n = 0;
+		handler_par.num_pkts = num_pkts;
 
 		/* now wait for the alarms */
 		sigemptyset(&sigset);
@@ -264,7 +272,7 @@ int main(int argc, char *argv[])
 		}
 		return 0;
 	} else {
-		for (i = 0; i < 10; i++) {
+		for (i = 0; num_pkts && i < num_pkts; i++) {
 			if (NUM) {
 				achOut[3] = (unsigned char)(i >> 24);
 				achOut[2] = (unsigned char)(i >> 16);
@@ -307,6 +315,9 @@ void timerhandler(void)
 		exit(1);
 	}
 
+	if (iCounter == handler_par.num_pkts)
+		exit(1);
+
 	iCounter++;
 	return;
 }