Browse code

- sleep between "throttle packets" option introduced - throttle introduced

Andrei Pelinescu-Onciul authored on 07/11/2003 14:31:51
Showing 1 changed files
... ...
@@ -50,6 +50,8 @@ Options:\n\
50 50
     -d address    destination address\n\
51 51
     -p port       destination port\n\
52 52
     -c count      number of packets to be sent\n\
53
+    -s usec       microseconds to sleep before sending \"throttle\" packets\n\
54
+    -t throttle   number of packets to send before sleeping\n\
53 55
     -v            increase verbosity level\n\
54 56
     -V            version number\n\
55 57
     -h            this help message\n\
... ...
@@ -74,6 +76,9 @@ int main (int argc, char** argv)
74 76
 	char *fname;
75 77
 	char *dst;
76 78
 	int port;
79
+	long usec;
80
+	int throttle;
81
+	int t;
77 82
 	
78 83
 	/* init */
79 84
 	count=0;
... ...
@@ -81,9 +86,11 @@ int main (int argc, char** argv)
81 86
 	fname=0;
82 87
 	dst=0;
83 88
 	port=0;
89
+	usec=0;
90
+	throttle=0;
84 91
 
85 92
 	opterr=0;
86
-	while ((c=getopt(argc,argv, "f:c:d:p:vhV"))!=-1){
93
+	while ((c=getopt(argc,argv, "f:c:d:p:s:t:vhV"))!=-1){
87 94
 		switch(c){
88 95
 			case 'f':
89 96
 				fname=optarg;
... ...
@@ -108,6 +115,20 @@ int main (int argc, char** argv)
108 115
 					goto error;
109 116
 				}
110 117
 				break;
118
+			case 's':
119
+				usec=strtol(optarg, &tmp, 10);
120
+				if ((tmp==0)||(*tmp)){
121
+					fprintf(stderr, "bad count: -c %s\n", optarg);
122
+					goto error;
123
+				}
124
+				break;
125
+			case 't':
126
+				throttle=strtol(optarg, &tmp, 10);
127
+				if ((tmp==0)||(*tmp)){
128
+					fprintf(stderr, "bad count: -c %s\n", optarg);
129
+					goto error;
130
+				}
131
+				break;
111 132
 			case 'V':
112 133
 				printf("version: %s\n", version);
113 134
 				printf("%s\n",id);
... ...
@@ -197,12 +218,20 @@ int main (int argc, char** argv)
197 218
 
198 219
 
199 220
 	/* flood loop */
221
+	t=throttle;
200 222
 	for (r=0; r<count; r++){
201 223
 		if ((verbose>1)&&(r%1000))  putchar('.');
202 224
 		if (send(sock, buf, n, 0)==-1) {
203 225
 			fprintf(stderr, "Error: send: %s\n",  strerror(errno));
204 226
 			exit(1);
205 227
 		}
228
+		if (usec){
229
+			t--;
230
+			if (t==0){
231
+				usleep(usec);
232
+				t=throttle;
233
+			}
234
+		}
206 235
 	}
207 236
 	printf("\n%d packets sent, %d bytes each => total %d bytes\n",
208 237
 			count, n, n*count);