|
|
|
@ -226,8 +226,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
progname = (char *) argv[0];
|
|
|
|
|
|
|
|
|
|
poptcon =
|
|
|
|
|
poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
|
|
|
|
|
poptcon = poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
|
|
|
|
|
|
|
|
|
|
while ((result = poptGetNextOpt(poptcon)) != -1) {
|
|
|
|
|
if (result < -1) {
|
|
|
|
@ -293,8 +292,7 @@ main(argc, argv)
|
|
|
|
|
case 'f':
|
|
|
|
|
remaining--;
|
|
|
|
|
if (strlen(fill_s) > 1)
|
|
|
|
|
err_quit
|
|
|
|
|
("Argument --fill should be a one-character string");
|
|
|
|
|
err_quit("Argument --fill should be a one-character string");
|
|
|
|
|
fill = fill_s[0];
|
|
|
|
|
fill_requested = 1;
|
|
|
|
|
break;
|
|
|
|
@ -328,8 +326,7 @@ main(argc, argv)
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (size <= 0) {
|
|
|
|
|
(void) fprintf(stderr, "%s: illegal packet size.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: illegal packet size.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
size_requested = 1;
|
|
|
|
@ -338,8 +335,7 @@ main(argc, argv)
|
|
|
|
|
remaining--;
|
|
|
|
|
timeout_requested = 1;
|
|
|
|
|
if (size <= 0) {
|
|
|
|
|
(void) fprintf(stderr, "%s: illegal timeout.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: illegal timeout.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -353,8 +349,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
if (number <= 0) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: illegal number of iterations.\n",
|
|
|
|
|
progname);
|
|
|
|
|
"%s: illegal number of iterations.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -367,9 +362,7 @@ main(argc, argv)
|
|
|
|
|
* waiting.
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: illegal waiting time.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: illegal waiting time.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -384,8 +377,7 @@ main(argc, argv)
|
|
|
|
|
module_find = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("Unknown character option %d (%c)", result,
|
|
|
|
|
(char) result);
|
|
|
|
|
printf("Unknown character option %d (%c)", result, (char) result);
|
|
|
|
|
usage(poptcon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -410,29 +402,25 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
#if ! (defined(OPENSSL) || defined(GNUTLS))
|
|
|
|
|
if (ssl) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: not compiled with SSL/TLS support.\n", progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: not compiled with SSL/TLS support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HTTP
|
|
|
|
|
if (http) {
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with HTTP support.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with HTTP support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef SMTP
|
|
|
|
|
if (smtp) {
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with SMTP support.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with SMTP support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef ICP
|
|
|
|
|
if (icp) {
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with ICP support.\n",
|
|
|
|
|
progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with ICP support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -444,8 +432,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
if (ssl && !http) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: SSL is only supported for HTTP requests.\n",
|
|
|
|
|
progname);
|
|
|
|
|
"%s: SSL is only supported for HTTP requests.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (!udp && !icp)
|
|
|
|
@ -462,23 +449,20 @@ main(argc, argv)
|
|
|
|
|
#ifndef USE_TOS
|
|
|
|
|
if (tos_requested) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: Not compiled with Type Of Service support.\n",
|
|
|
|
|
progname);
|
|
|
|
|
"%s: Not compiled with Type Of Service support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef USE_PRIORITY
|
|
|
|
|
if (priority_requested) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: Not compiled with socket priority support.\n",
|
|
|
|
|
progname);
|
|
|
|
|
"%s: Not compiled with socket priority support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAVE_SCTP
|
|
|
|
|
if (sctp_requested) {
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
|
"%s: Not compiled with SCTP support.\n", progname);
|
|
|
|
|
(void) fprintf(stderr, "%s: Not compiled with SCTP support.\n", progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -492,8 +476,7 @@ main(argc, argv)
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
/* Retries with the absolute name */
|
|
|
|
|
complete_plugin_name = (char *) malloc(MAX_LINE);
|
|
|
|
|
sprintf(complete_plugin_name, "%s/%s", PLUGINS_DIR,
|
|
|
|
|
plugin_name);
|
|
|
|
|
sprintf(complete_plugin_name, "%s/%s", PLUGINS_DIR, plugin_name);
|
|
|
|
|
plugin = dlopen(complete_plugin_name, RTLD_NOW);
|
|
|
|
|
}
|
|
|
|
|
if (!plugin) {
|
|
|
|
@ -510,8 +493,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
plugin_init = dlsym(plugin, "init");
|
|
|
|
|
if (!plugin_init) {
|
|
|
|
|
err_sys("Cannot find init in %s: %s", plugin_name,
|
|
|
|
|
dlerror());
|
|
|
|
|
err_sys("Cannot find init in %s: %s", plugin_name, dlerror());
|
|
|
|
|
}
|
|
|
|
|
global_options.udp = udp;
|
|
|
|
|
global_options.verbose = verbose;
|
|
|
|
@ -530,27 +512,23 @@ main(argc, argv)
|
|
|
|
|
plugin_raw = FALSE;
|
|
|
|
|
plugin_start = dlsym(plugin, "start");
|
|
|
|
|
if (!plugin_start) {
|
|
|
|
|
err_sys("Cannot find start in %s: %s", plugin_name,
|
|
|
|
|
dlerror());
|
|
|
|
|
err_sys("Cannot find start in %s: %s", plugin_name, dlerror());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
port_name = 0;
|
|
|
|
|
plugin_raw = TRUE;
|
|
|
|
|
plugin_raw_start = dlsym(plugin, "start_raw");
|
|
|
|
|
if (!plugin_raw_start) {
|
|
|
|
|
err_sys("Cannot find start_raw in %s: %s",
|
|
|
|
|
plugin_name, dlerror());
|
|
|
|
|
err_sys("Cannot find start_raw in %s: %s", plugin_name, dlerror());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
plugin_execute = dlsym(plugin, "execute");
|
|
|
|
|
if (!plugin_execute) {
|
|
|
|
|
err_sys("Cannot find execute in %s: %s", plugin_name,
|
|
|
|
|
dlerror());
|
|
|
|
|
err_sys("Cannot find execute in %s: %s", plugin_name, dlerror());
|
|
|
|
|
}
|
|
|
|
|
plugin_terminate = dlsym(plugin, "terminate");
|
|
|
|
|
if (!plugin_terminate) {
|
|
|
|
|
err_sys("Cannot find terminate in %s: %s", plugin_name,
|
|
|
|
|
dlerror());
|
|
|
|
|
err_sys("Cannot find terminate in %s: %s", plugin_name, dlerror());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (remaining == 0) {
|
|
|
|
@ -620,10 +598,8 @@ main(argc, argv)
|
|
|
|
|
if (*p == ':') {
|
|
|
|
|
*p = 0;
|
|
|
|
|
text_port = p + 1;
|
|
|
|
|
if (strcmp(text_port, "")) /* See bug *
|
|
|
|
|
* #850672 */
|
|
|
|
|
strncpy(port_name, text_port,
|
|
|
|
|
NI_MAXSERV);
|
|
|
|
|
if (strcmp(text_port, "")) /* See bug * * #850672 */
|
|
|
|
|
strncpy(port_name, text_port, NI_MAXSERV);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -634,15 +610,9 @@ main(argc, argv)
|
|
|
|
|
if (strcmp(port_name, DEFAULT_HTTP_TCP_PORT)
|
|
|
|
|
== 0) {
|
|
|
|
|
strcpy(port_name, "80");
|
|
|
|
|
} else
|
|
|
|
|
if (strcmp
|
|
|
|
|
(port_name,
|
|
|
|
|
DEFAULT_HTTPS_TCP_PORT) == 0) {
|
|
|
|
|
} else if (strcmp(port_name, DEFAULT_HTTPS_TCP_PORT) == 0) {
|
|
|
|
|
strcpy(port_name, "443");
|
|
|
|
|
} else
|
|
|
|
|
if (strcmp
|
|
|
|
|
(port_name,
|
|
|
|
|
DEFAULT_ICP_UDP_PORT) == 0) {
|
|
|
|
|
} else if (strcmp(port_name, DEFAULT_ICP_UDP_PORT) == 0) {
|
|
|
|
|
strcpy(port_name, "3130");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -665,13 +635,10 @@ main(argc, argv)
|
|
|
|
|
idna_to_ascii_8z(utf8_server, &ace_server,
|
|
|
|
|
IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS) {
|
|
|
|
|
if (result == IDNA_CONTAINS_LDH)
|
|
|
|
|
err_quit("Illegal name for host: %s", server); /* foo@bar
|
|
|
|
|
* or
|
|
|
|
|
* similar
|
|
|
|
|
* errors */
|
|
|
|
|
err_quit("Illegal name for host: %s", server); /* foo@bar or
|
|
|
|
|
* similar errors */
|
|
|
|
|
else
|
|
|
|
|
err_quit("IDN error for host: %s %d", server,
|
|
|
|
|
result);
|
|
|
|
|
err_quit("IDN error for host: %s %d", server, result);
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(utf8_server, ace_server)) {
|
|
|
|
|
if (verbose)
|
|
|
|
@ -694,8 +661,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
if (plugin) {
|
|
|
|
|
if (verbose) {
|
|
|
|
|
printf("Running start() for the plugin %s...\n",
|
|
|
|
|
plugin_name);
|
|
|
|
|
printf("Running start() for the plugin %s...\n", plugin_name);
|
|
|
|
|
}
|
|
|
|
|
if (plugin_raw)
|
|
|
|
|
plugin_raw_start();
|
|
|
|
@ -712,15 +678,14 @@ main(argc, argv)
|
|
|
|
|
#ifdef SMTP
|
|
|
|
|
if (smtp) {
|
|
|
|
|
sendline = "QUIT\r\n"; /* Surprises some SMTP servers which log a
|
|
|
|
|
* frightening NOQUEUE. Anyone knows better?
|
|
|
|
|
* * * * * See bug #1512776 */
|
|
|
|
|
* frightening NOQUEUE. Anyone knows better? * * *
|
|
|
|
|
* * See bug #1512776 */
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef ICP
|
|
|
|
|
if (icp) {
|
|
|
|
|
if (res->ai_family == AF_INET) {
|
|
|
|
|
sendline =
|
|
|
|
|
make_icp_sendline(url, &(res->ai_addr), opcode, &length);
|
|
|
|
|
sendline = make_icp_sendline(url, &(res->ai_addr), opcode, &length);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -729,8 +694,7 @@ main(argc, argv)
|
|
|
|
|
* http://devel.squid-cache.org/projects.html#ipv6,
|
|
|
|
|
* for instance the following code.
|
|
|
|
|
*/
|
|
|
|
|
sendline =
|
|
|
|
|
make_icp_sendline(url, (void *) NULL, opcode, &length);
|
|
|
|
|
sendline = make_icp_sendline(url, (void *) NULL, opcode, &length);
|
|
|
|
|
/*
|
|
|
|
|
* - headerp->shostid = theOutICPAddr.s_addr; + ** FIXME ** we
|
|
|
|
|
* should get more unique data from IPv6 address +xmemcpy
|
|
|
|
@ -772,8 +736,7 @@ main(argc, argv)
|
|
|
|
|
#ifdef USE_SIGACTION
|
|
|
|
|
mysigaction.sa_handler = SIG_IGN;
|
|
|
|
|
sigemptyset(&mysigaction.sa_mask);
|
|
|
|
|
if ((sigaction(SIGPIPE, &mysigaction, NULL)) < 0); /* Ignore it
|
|
|
|
|
*/
|
|
|
|
|
if ((sigaction(SIGPIPE, &mysigaction, NULL)) < 0); /* Ignore it */
|
|
|
|
|
#else
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
#endif
|
|
|
|
@ -833,8 +796,7 @@ main(argc, argv)
|
|
|
|
|
protocol = IPPROTO_SCTP;
|
|
|
|
|
#endif
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
if ((sockfd =
|
|
|
|
|
socket(res->ai_family, res->ai_socktype, protocol)) < 0)
|
|
|
|
|
if ((sockfd = socket(res->ai_family, res->ai_socktype, protocol)) < 0)
|
|
|
|
|
err_sys("Can't open socket");
|
|
|
|
|
if (udp) {
|
|
|
|
|
struct addrinfo hints2, *res2;
|
|
|
|
@ -847,8 +809,7 @@ main(argc, argv)
|
|
|
|
|
if (error) {
|
|
|
|
|
err_sys("getaddrinfo error");
|
|
|
|
|
}
|
|
|
|
|
if (bind(sockfd, res2->ai_addr, res2->ai_addrlen) <
|
|
|
|
|
0) {
|
|
|
|
|
if (bind(sockfd, res2->ai_addr, res2->ai_addrlen) < 0) {
|
|
|
|
|
err_sys("bind error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -862,8 +823,7 @@ main(argc, argv)
|
|
|
|
|
if (setsockopt(sockfd,
|
|
|
|
|
SOL_SOCKET,
|
|
|
|
|
SO_PRIORITY,
|
|
|
|
|
(void *) &priority,
|
|
|
|
|
(socklen_t) sizeof(priority))) {
|
|
|
|
|
(void *) &priority, (socklen_t) sizeof(priority))) {
|
|
|
|
|
err_sys("Failed setting socket priority");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -877,10 +837,8 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
if (setsockopt(sockfd,
|
|
|
|
|
SOL_IP,
|
|
|
|
|
IP_TOS, (void *) &tos,
|
|
|
|
|
(socklen_t) sizeof(tos))) {
|
|
|
|
|
err_sys
|
|
|
|
|
("Failed setting IP type of service octet");
|
|
|
|
|
IP_TOS, (void *) &tos, (socklen_t) sizeof(tos))) {
|
|
|
|
|
err_sys("Failed setting IP type of service octet");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -906,8 +864,7 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (plugin_raw)
|
|
|
|
|
printf("Trying to call plugin %s...\n",
|
|
|
|
|
plugin_name);
|
|
|
|
|
printf("Trying to call plugin %s...\n", plugin_name);
|
|
|
|
|
else
|
|
|
|
|
printf
|
|
|
|
|
("Trying to call plugin %s for internet address %s %s...\n",
|
|
|
|
@ -919,10 +876,8 @@ main(argc, argv)
|
|
|
|
|
err_sys("I cannot flush");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if ((tcp || plugin) && timeout_requested) { /* echoping's
|
|
|
|
|
* timeout has a
|
|
|
|
|
* different
|
|
|
|
|
* semantic in TCP
|
|
|
|
|
if ((tcp || plugin) && timeout_requested) { /* echoping's timeout has a
|
|
|
|
|
* different semantic in TCP
|
|
|
|
|
* and UDP */
|
|
|
|
|
#ifdef USE_SIGACTION
|
|
|
|
|
mysigaction.sa_handler = to_alarm;
|
|
|
|
@ -952,10 +907,9 @@ main(argc, argv)
|
|
|
|
|
}
|
|
|
|
|
if (plugin) {
|
|
|
|
|
plugin_result = plugin_execute();
|
|
|
|
|
/* If plugin_result == -1, there is a temporary error and we
|
|
|
|
|
* did not get data, we must not use it in the average /
|
|
|
|
|
* median calculations. So, successes will not be
|
|
|
|
|
* incremented later. */
|
|
|
|
|
/* If plugin_result == -1, there is a temporary error and we did not
|
|
|
|
|
* get data, we must not use it in the average / median calculations.
|
|
|
|
|
* So, successes will not be incremented later. */
|
|
|
|
|
if (plugin_result == -2)
|
|
|
|
|
err_quit("");
|
|
|
|
|
} else {
|
|
|
|
@ -963,10 +917,8 @@ main(argc, argv)
|
|
|
|
|
/*
|
|
|
|
|
* Connect to the server.
|
|
|
|
|
*/
|
|
|
|
|
(void) gettimeofday(&conntv,
|
|
|
|
|
(struct timezone *) NULL);
|
|
|
|
|
if (connect(sockfd, res->ai_addr, res->ai_addrlen) <
|
|
|
|
|
0) {
|
|
|
|
|
(void) gettimeofday(&conntv, (struct timezone *) NULL);
|
|
|
|
|
if (connect(sockfd, res->ai_addr, res->ai_addrlen) < 0) {
|
|
|
|
|
if ((errno == EINTR) && (timeout_flag)) {
|
|
|
|
|
printf("Timeout while connecting\n");
|
|
|
|
|
close(sockfd);
|
|
|
|
@ -978,26 +930,20 @@ main(argc, argv)
|
|
|
|
|
#endif
|
|
|
|
|
} else
|
|
|
|
|
err_sys("Can't connect to server");
|
|
|
|
|
/* TODO: it would be better to continue: if
|
|
|
|
|
* -n was given, other iterations may
|
|
|
|
|
* succeed. A flag indicating success or
|
|
|
|
|
* error is probably necessary, it would
|
|
|
|
|
* replace the mess around 'if
|
|
|
|
|
* (!timeout_flag && (!plugin ||
|
|
|
|
|
* plugin_result >= 0))' */
|
|
|
|
|
/* TODO: it would be better to continue: if -n was given, other
|
|
|
|
|
* iterations may succeed. A flag indicating success or error is
|
|
|
|
|
* probably necessary, it would replace the mess around 'if
|
|
|
|
|
* (!timeout_flag && (!plugin || plugin_result >= 0))' */
|
|
|
|
|
} else {
|
|
|
|
|
if (tcp) {
|
|
|
|
|
(void) gettimeofday(&connectedtv,
|
|
|
|
|
(struct timezone
|
|
|
|
|
*) NULL);
|
|
|
|
|
(void) gettimeofday(&connectedtv, (struct timezone *) NULL);
|
|
|
|
|
temp = connectedtv;
|
|
|
|
|
tvsub(&temp, &conntv);
|
|
|
|
|
if (verbose) {
|
|
|
|
|
printf("Connected...\n");
|
|
|
|
|
printf
|
|
|
|
|
("TCP Latency: %d.%06d seconds\n",
|
|
|
|
|
(int) temp.tv_sec,
|
|
|
|
|
(int) temp.tv_usec);
|
|
|
|
|
(int) temp.tv_sec, (int) temp.tv_usec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1017,14 +963,12 @@ main(argc, argv)
|
|
|
|
|
if (SSL_connect(sslh) == -1)
|
|
|
|
|
if ((errno == EINTR)
|
|
|
|
|
&& (timeout_flag)) {
|
|
|
|
|
printf
|
|
|
|
|
("Timeout while starting SSL\n");
|
|
|
|
|
printf("Timeout while starting SSL\n");
|
|
|
|
|
close(sockfd);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (verbose)
|
|
|
|
|
printf("SSL connection using %s\n",
|
|
|
|
|
SSL_get_cipher(sslh));
|
|
|
|
|
printf("SSL connection using %s\n", SSL_get_cipher(sslh));
|
|
|
|
|
/*
|
|
|
|
|
* We could check the server's
|
|
|
|
|
* certificate or other funny things
|
|
|
|
@ -1033,40 +977,32 @@ main(argc, argv)
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef GNUTLS
|
|
|
|
|
if (ssl) {
|
|
|
|
|
tls_result =
|
|
|
|
|
gnutls_init(&session, GNUTLS_CLIENT);
|
|
|
|
|
tls_result = gnutls_init(&session, GNUTLS_CLIENT);
|
|
|
|
|
if (tls_result != 0)
|
|
|
|
|
err_sys
|
|
|
|
|
("Cannot create a new TLS session");
|
|
|
|
|
err_sys("Cannot create a new TLS session");
|
|
|
|
|
gnutls_set_default_priority(session);
|
|
|
|
|
gnutls_certificate_type_set_priority(session,
|
|
|
|
|
cert_type_priority);
|
|
|
|
|
gnutls_credentials_set(session,
|
|
|
|
|
GNUTLS_CRD_CERTIFICATE,
|
|
|
|
|
xcred);
|
|
|
|
|
gnutls_transport_set_ptr(session,
|
|
|
|
|
(gnutls_transport_ptr)
|
|
|
|
|
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred);
|
|
|
|
|
gnutls_transport_set_ptr(session, (gnutls_transport_ptr)
|
|
|
|
|
(long) sockfd);
|
|
|
|
|
tls_result = gnutls_handshake(session);
|
|
|
|
|
if (tls_result < 0) {
|
|
|
|
|
if ((errno == EINTR)
|
|
|
|
|
&& (timeout_flag)) {
|
|
|
|
|
printf
|
|
|
|
|
("Timeout while starting TLS\n");
|
|
|
|
|
printf("Timeout while starting TLS\n");
|
|
|
|
|
close(sockfd);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
err_sys
|
|
|
|
|
("Cannot start the TLS session: %s",
|
|
|
|
|
gnutls_strerror
|
|
|
|
|
(tls_result));
|
|
|
|
|
gnutls_strerror(tls_result));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (verbose)
|
|
|
|
|
printf
|
|
|
|
|
("TLS connection using \"%s\"\n",
|
|
|
|
|
gnutls_cipher_get_name
|
|
|
|
|
(gnutls_cipher_get(session)));
|
|
|
|
|
gnutls_cipher_get_name(gnutls_cipher_get(session)));
|
|
|
|
|
/*
|
|
|
|
|
* We could check the server's
|
|
|
|
|
* certificate or other funny things.
|
|
|
|
@ -1100,37 +1036,28 @@ main(argc, argv)
|
|
|
|
|
&& timeout_flag) {
|
|
|
|
|
printf
|
|
|
|
|
("Timeout while writing (%d byte(s) written so far)\n",
|
|
|
|
|
(nr ==
|
|
|
|
|
-1) ? 0 : nr);
|
|
|
|
|
(nr == -1) ? 0 : nr);
|
|
|
|
|
nr = n;
|
|
|
|
|
close(sockfd);
|
|
|
|
|
continue;
|
|
|
|
|
} else
|
|
|
|
|
err_sys
|
|
|
|
|
("writen error on TCP socket %d",
|
|
|
|
|
sockfd);
|
|
|
|
|
err_sys("writen error on TCP socket %d", sockfd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef OPENSSL
|
|
|
|
|
else {
|
|
|
|
|
if ((rc =
|
|
|
|
|
SSL_write(sslh, sendline,
|
|
|
|
|
n)) != n) {
|
|
|
|
|
if ((rc = SSL_write(sslh, sendline, n)) != n) {
|
|
|
|
|
if ((nr < 0 || nr != n)
|
|
|
|
|
&& timeout_flag) {
|
|
|
|
|
nr = n;
|
|
|
|
|
printf
|
|
|
|
|
("Timeout while writing\n");
|
|
|
|
|
printf("Timeout while writing\n");
|
|
|
|
|
close(sockfd);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
sslcode =
|
|
|
|
|
ERR_get_error();
|
|
|
|
|
sslcode = ERR_get_error();
|
|
|
|
|
err_sys
|
|
|
|
|
("SSL_write error on socket: %s",
|
|
|
|
|
ERR_error_string
|
|
|
|
|
(sslcode,
|
|
|
|
|
NULL));
|
|
|
|
|
ERR_error_string(sslcode, NULL));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1139,24 +1066,18 @@ main(argc, argv)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((rc =
|
|
|
|
|
gnutls_record_send(session,
|
|
|
|
|
sendline,
|
|
|
|
|
strlen
|
|
|
|
|
(sendline)))
|
|
|
|
|
gnutls_record_send(session, sendline, strlen(sendline)))
|
|
|
|
|
!= n) {
|
|
|
|
|
if ((nr < 0 || nr != n)
|
|
|
|
|
&& timeout_flag) {
|
|
|
|
|
nr = n;
|
|
|
|
|
printf
|
|
|
|
|
("Timeout while writing\n");
|
|
|
|
|
printf("Timeout while writing\n");
|
|
|
|
|
close(sockfd);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
err_sys
|
|
|
|
|
("gnutls_record_send error %d on socket: %s",
|
|
|
|
|
rc,
|
|
|
|
|
gnutls_strerror
|
|
|
|
|
(rc));
|
|
|
|
|
rc, gnutls_strerror(rc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1166,10 +1087,8 @@ main(argc, argv)
|
|
|
|
|
if (icp) {
|
|
|
|
|
if (sendto
|
|
|
|
|
(sockfd, sendline, length, 0,
|
|
|
|
|
res->ai_addr,
|
|
|
|
|
res->ai_addrlen) != length)
|
|
|
|
|
err_sys
|
|
|
|
|
("sendto error on socket");
|
|
|
|
|
res->ai_addr, res->ai_addrlen) != length)
|
|
|
|
|
err_sys("sendto error on socket");
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
/*
|
|
|
|
@ -1181,13 +1100,11 @@ main(argc, argv)
|
|
|
|
|
err_sys("send error on socket");
|
|
|
|
|
}
|
|
|
|
|
if (verbose) {
|
|
|
|
|
(void) gettimeofday(&sendtv,
|
|
|
|
|
(struct timezone *)
|
|
|
|
|
(void) gettimeofday(&sendtv, (struct timezone *)
|
|
|
|
|
NULL);
|
|
|
|
|
#ifdef ICP
|
|
|
|
|
if (icp)
|
|
|
|
|
printf("Sent (%d bytes)...\n",
|
|
|
|
|
length);
|
|
|
|
|
printf("Sent (%d bytes)...\n", length);
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
printf("Sent (%d bytes)...\n", n);
|
|
|
|
@ -1220,16 +1137,14 @@ main(argc, argv)
|
|
|
|
|
#endif
|
|
|
|
|
FD_SET(n, &mask);
|
|
|
|
|
if (select(n + 1, &mask, 0, 0, NULL) > 0) {
|
|
|
|
|
(void) gettimeofday(&recvtv,
|
|
|
|
|
(struct timezone *)
|
|
|
|
|
(void) gettimeofday(&recvtv, (struct timezone *)
|
|
|
|
|
NULL);
|
|
|
|
|
temp = recvtv;
|
|
|
|
|
tvsub(&temp, &sendtv);
|
|
|
|
|
if (verbose)
|
|
|
|
|
printf
|
|
|
|
|
("Application Latency: %d.%06d seconds\n",
|
|
|
|
|
(int) temp.tv_sec,
|
|
|
|
|
(int) temp.tv_usec);
|
|
|
|
|
(int) temp.tv_sec, (int) temp.tv_usec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((port_to_use == USE_ECHO) || (port_to_use == USE_CHARGEN)
|
|
|
|
@ -1238,8 +1153,7 @@ main(argc, argv)
|
|
|
|
|
if (!udp) {
|
|
|
|
|
if (!http && !smtp && !discard) {
|
|
|
|
|
/* Read from the server */
|
|
|
|
|
nr = readline(files, recvline, n,
|
|
|
|
|
stop_at_newlines);
|
|
|
|
|
nr = readline(files, recvline, n, stop_at_newlines);
|
|
|
|
|
} else if (discard) {
|
|
|
|
|
/* No reply, no read */
|
|
|
|
|
}
|
|
|
|
@ -1255,14 +1169,12 @@ main(argc, argv)
|
|
|
|
|
else
|
|
|
|
|
channel.tls = session;
|
|
|
|
|
#endif
|
|
|
|
|
nr = read_from_server(channel, ssl,
|
|
|
|
|
accept_http_redirects);
|
|
|
|
|
nr = read_from_server(channel, ssl, accept_http_redirects);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SMTP
|
|
|
|
|
else if (smtp) {
|
|
|
|
|
nr = smtp_read_response_from_server
|
|
|
|
|
(files);
|
|
|
|
|
nr = smtp_read_response_from_server(files);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -1281,12 +1193,10 @@ main(argc, argv)
|
|
|
|
|
#else
|
|
|
|
|
signal(SIGALRM, to_alarm);
|
|
|
|
|
#endif
|
|
|
|
|
timeout_flag = 0; /* for signal
|
|
|
|
|
* handler */
|
|
|
|
|
timeout_flag = 0; /* for signal handler */
|
|
|
|
|
#ifdef ICP
|
|
|
|
|
if (icp) {
|
|
|
|
|
nr = recv_icp(sockfd, recvline,
|
|
|
|
|
retcode);
|
|
|
|
|
nr = recv_icp(sockfd, recvline, retcode);
|
|
|
|
|
if (verbose) {
|
|
|
|
|
printf("%s\n", retcode);
|
|
|
|
|
}
|
|
|
|
@ -1308,10 +1218,8 @@ main(argc, argv)
|
|
|
|
|
nr = n;
|
|
|
|
|
printf("Timeout\n");
|
|
|
|
|
#ifdef FLUSH_OUTPUT
|
|
|
|
|
if (fflush((FILE *) NULL) !=
|
|
|
|
|
0) {
|
|
|
|
|
err_sys
|
|
|
|
|
("I cannot flush");
|
|
|
|
|
if (fflush((FILE *) NULL) != 0) {
|
|
|
|
|
err_sys("I cannot flush");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
@ -1373,21 +1281,18 @@ main(argc, argv)
|
|
|
|
|
} /* That's all, folks */
|
|
|
|
|
alarm(0);
|
|
|
|
|
#ifdef HAVE_TCP_INFO
|
|
|
|
|
/* Thanks to Perry Lorier <perry@coders.net> for the tip. See a
|
|
|
|
|
* longer paper in http://linuxgazette.net/136/pfeiffer.html */
|
|
|
|
|
/* Thanks to Perry Lorier <perry@coders.net> for the tip. See a longer paper
|
|
|
|
|
* in http://linuxgazette.net/136/pfeiffer.html */
|
|
|
|
|
if (tcp && verbose) {
|
|
|
|
|
if (getsockopt
|
|
|
|
|
(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
|
|
|
|
|
if (getsockopt(sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length)
|
|
|
|
|
!= -1) {
|
|
|
|
|
/* TODO: find out the meaning of the various fields
|
|
|
|
|
* inthe struct tcp_info (it seems documented only
|
|
|
|
|
* in the Linux kernel sources) and display stuff
|
|
|
|
|
* like reordering (see RFC 4737), window, lost
|
|
|
|
|
/* TODO: find out the meaning of the various fields inthe struct
|
|
|
|
|
* tcp_info (it seems documented only in the Linux kernel sources)
|
|
|
|
|
* and display stuff like reordering (see RFC 4737), window, lost
|
|
|
|
|
* packets, etc. */
|
|
|
|
|
printf
|
|
|
|
|
("Estimated TCP RTT: %.04f seconds (std. deviation %0.03f)\n",
|
|
|
|
|
tcpinfo.tcpi_rtt / 1000000.0,
|
|
|
|
|
tcpinfo.tcpi_rttvar / 1000000.0);
|
|
|
|
|
tcpinfo.tcpi_rtt / 1000000.0, tcpinfo.tcpi_rttvar / 1000000.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -1409,9 +1314,7 @@ main(argc, argv)
|
|
|
|
|
(void) gettimeofday(&newtv, (struct timezone *) NULL);
|
|
|
|
|
temp = newtv;
|
|
|
|
|
tvsub(&temp, &oldtv);
|
|
|
|
|
if (!timeout_flag && (!plugin || plugin_result >= 0)) { /* If it
|
|
|
|
|
* worked...
|
|
|
|
|
*/
|
|
|
|
|
if (!timeout_flag && (!plugin || plugin_result >= 0)) { /* If it worked... */
|
|
|
|
|
tvadd(&total, &temp);
|
|
|
|
|
|
|
|
|
|
/* Check */
|
|
|
|
@ -1419,8 +1322,7 @@ main(argc, argv)
|
|
|
|
|
if (port_to_use == USE_ECHO) {
|
|
|
|
|
if (strcmp(sendline, recvline) != 0) {
|
|
|
|
|
printf(" I wrote:\n%s\n", sendline);
|
|
|
|
|
printf(" and I got back:\n%s\n",
|
|
|
|
|
recvline);
|
|
|
|
|
printf(" and I got back:\n%s\n", recvline);
|
|
|
|
|
err_quit("Strange server");
|
|
|
|
|
}
|
|
|
|
|
if (verbose) {
|
|
|
|
@ -1441,11 +1343,8 @@ main(argc, argv)
|
|
|
|
|
* the size is lower than the
|
|
|
|
|
* length of CHARGENERATED
|
|
|
|
|
*/
|
|
|
|
|
printf(" I got back:\n%s\n",
|
|
|
|
|
recvline);
|
|
|
|
|
printf
|
|
|
|
|
(" instead of the most common:\n%s\n",
|
|
|
|
|
sendline);
|
|
|
|
|
printf(" I got back:\n%s\n", recvline);
|
|
|
|
|
printf(" instead of the most common:\n%s\n", sendline);
|
|
|
|
|
err_ret("Strange server");
|
|
|
|
|
}
|
|
|
|
|
if (verbose) {
|
|
|
|
@ -1520,14 +1419,11 @@ printstats()
|
|
|
|
|
printf("---\n");
|
|
|
|
|
if (successes < attempts)
|
|
|
|
|
printf("Warning: %d message(s) lost (%d %%)\n",
|
|
|
|
|
attempts - successes,
|
|
|
|
|
((attempts - successes) * 100) / attempts);
|
|
|
|
|
attempts - successes, ((attempts - successes) * 100) / attempts);
|
|
|
|
|
printf("Minimum time: %d.%06d seconds (%.0f bytes per sec.)\n",
|
|
|
|
|
(int) min.tv_sec, (int) min.tv_usec,
|
|
|
|
|
(double) size / tv2double(min));
|
|
|
|
|
(int) min.tv_sec, (int) min.tv_usec, (double) size / tv2double(min));
|
|
|
|
|
printf("Maximum time: %d.%06d seconds (%.0f bytes per sec.)\n",
|
|
|
|
|
(int) max.tv_sec, (int) max.tv_usec,
|
|
|
|
|
(double) size / tv2double(max));
|
|
|
|
|
(int) max.tv_sec, (int) max.tv_usec, (double) size / tv2double(max));
|
|
|
|
|
tvavg(&total, successes);
|
|
|
|
|
printf("Average time: %d.%06d seconds (%.0f bytes per sec.)\n",
|
|
|
|
|
(int) total.tv_sec, (int) total.tv_usec,
|
|
|
|
@ -1546,8 +1442,7 @@ printstats()
|
|
|
|
|
good_results[j++] = results[i].timevalue;
|
|
|
|
|
}
|
|
|
|
|
if (successes != j) /* Todo: bug! */
|
|
|
|
|
err_quit("successes (%d) is different from j (%d)",
|
|
|
|
|
successes, j);
|
|
|
|
|
err_quit("successes (%d) is different from j (%d)", successes, j);
|
|
|
|
|
qsort(good_results, successes, sizeof(struct timeval), tvcmp);
|
|
|
|
|
/*
|
|
|
|
|
* for (i = 1; i <= number; i++) { printf("---\nTime %d th:
|
|
|
|
@ -1573,8 +1468,7 @@ printstats()
|
|
|
|
|
(int) median.tv_sec, (int) median.tv_usec,
|
|
|
|
|
(double) size / tv2double(median));
|
|
|
|
|
if (n_stddev) {
|
|
|
|
|
tvstddevavg(&stddev, successes, total, results,
|
|
|
|
|
(double) n_stddev);
|
|
|
|
|
tvstddevavg(&stddev, successes, total, results, (double) n_stddev);
|
|
|
|
|
printf
|
|
|
|
|
("Average of values within %d standard deviation%s: %d.%06d\n",
|
|
|
|
|
n_stddev, (n_stddev == 1 ? "" : "s"),
|
|
|
|
|