dts_t *deltas = NULL;
int nb_measurements = 0;
+
+char *local_host = "localhost";
+int local_port = 1024;
+char *remote_host = "localhost";
+int remote_port = 1025;
int mode = 0;
char *message = "udp socket";
void _usage_ext (FILE *fd)
{
- fprintf (fd, " localip localport remoteip remoteport [mode]\n");
- fprintf (fd, " mode (%d): 0 for ping-pong, 1 for ping, 2 for pong\n", mode);
+ fprintf (fd, "... lhost lport rhost rport [mode]\n");
+ fprintf (fd, " lhost: local host name (%s)\n", local_host);
+ fprintf (fd, " lport: local port number (%d)\n", local_port);
+ fprintf (fd, " rhost: remote host name (%s)\n", remote_host);
+ fprintf (fd, " rport: remote port number (%d)\n", remote_port);
+ fprintf (fd, " mode: 0 for ping-pong, 1 for ping, 2 for pong (%d)\n", mode);
}
void (*usage_ext) (FILE *) = _usage_ext;
-int (*parse_arg_ext) (char *) = NULL;
+int _parse_arg_ext (char *arg)
+{
+ static int narg = 0;
+
+ int rc = 0;
+ switch (narg) {
+ case 0: local_host= arg; break;
+ case 1: local_port = atoi (arg); if (local_port < 0) rc = 1; break;
+ case 2: remote_host = arg; break;
+ case 3: remote_port = atoi (arg); if (remote_port < 0) rc = 1; break;
+ case 4: mode = atoi (arg); break;
+ default: rc = 1;
+ }
+ narg++;
+
+ return rc;
+}
+int (*parse_arg_ext) (char *) = _parse_arg_ext;
#define MAXBUF 1024
int test (dts_t *buffer, int nb)
{
- char *local_host = "localhost";
- int local_port = 1024;
- char *remote_host = "localhost";
- int remote_port = 1025;
/* set global variables */
if (remote_ip == -1) {
return 1;
}
-
- pid_t pid = fork ();
+
+ pid_t pid = (mode == 0 ) ? fork () : -2;
if (pid == -1) {
fprintf (stderr, "error: fork\n");
return 1;
- } else if (pid == 0) {
+ } else if ((pid == 0) || (mode == 2)) {
int rc = pong (remote_port, local_ip, local_port);
exit (rc);
}
int rc = ping (local_port, remote_ip, remote_port);
- if (kill (pid, SIGTERM) == 0) {
+ if ((pid > 0) && (kill (pid, SIGTERM) == 0)) {
int wstatus;
if (waitpid (pid, &wstatus, WUNTRACED | WCONTINUED) == -1) {
fprintf (stderr, "error: waitpid\n");