{ "debug", no_argument, NULL, 'd'},
{ "msg", required_argument, NULL, 'm'},
{ "port", required_argument, NULL, 'p'},
+ { "repeat", required_argument, NULL, 'r'},
};
int debug = 0;
int opt,
sock,
n;
-
+ int repeat = 1;
me = strrchr(argv[0], '/');
if ( me ) me++; else me = argv[0];
- while ( (opt = getopt_long(argc, argv,"p:m:hd", opts, NULL)) != EOF )
+ while ( (opt = getopt_long(argc, argv,"p:m:hdr:", opts, NULL)) != EOF )
{
switch ( opt )
{
port = atoi(optarg);
break;
case 'd': debug = 1; break;
+ case 'r': repeat = atoi(optarg); break;
case 'h': usage(me); return 0;
case '?': usage(me); return 1;
}
exit(1);
}
n = strlen(msg? msg: DEF_MSG);
- if ( writen(sock, msg? msg: DEF_MSG, n) != n )
- {
- dprintf(("error writing message\n"));
- exit(1);
- }
- printf("reply: "); fflush(stdout);
- n = readln(sock, buff);
- if ( n < 0 )
- {
- perror("read() reply error");
- return 1;
+ for (;repeat; repeat--) {
+ if ( writen(sock, msg? msg: DEF_MSG, n) != n )
+ {
+ dprintf(("error writing message\n"));
+ exit(1);
+ }
+ printf("reply: "); fflush(stdout);
+ n = readln(sock, buff);
+ if ( n < 0 )
+ {
+ perror("read() reply error");
+ return 1;
+ }
+ writen(0, buff, n);
}
- writen(0, buff, n);
close(sock);
return 0;