Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ping_test: fix argc corruption and make output configurable

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
commit d84b95d979964e211f7a47e2d7761203b7d469ef 1 parent f38c86b
@fabbione authored
Showing with 31 additions and 2 deletions.
  1. +31 −2 libknet/ping_test.c
View
33 libknet/ping_test.c
@@ -27,6 +27,7 @@ static int knet_sock[2];
static knet_handle_t knet_h;
static struct knet_handle_crypto_cfg knet_handle_crypto_cfg;
static uint8_t loglevel = KNET_LOG_INFO;
+static uint8_t use_stdout = 0;
static char *src_host = NULL;
static char *src_port = NULL;
@@ -40,9 +41,16 @@ static in_port_t tok_inport(char *str)
return (in_port_t) value;
}
-static int tok_inaddrport(char *str, struct sockaddr_in *addr)
+static int tok_inaddrport(char *strin, struct sockaddr_in *addr)
{
char *strhost, *strport, *tmp = NULL;
+ char *str;
+
+ str = strdup(strin);
+ if (!str) {
+ printf("no mem?\n");
+ exit(1);
+ }
strhost = strtok_r(str, ":", &tmp);
if (!src_host)
@@ -63,6 +71,7 @@ static int tok_inaddrport(char *str, struct sockaddr_in *addr)
src_port = strdup(strport);
addr->sin_port = htons(tok_inport(strport));
}
+ free(str);
return inet_aton(strhost, &addr->sin_addr);
}
@@ -74,6 +83,18 @@ static void print_usage(char *name)
printf("example: %s 127.0.0.1:50000 127.0.0.1:50000 debug\n", name);
}
+static void set_log(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < argc; i++) {
+ if (!strncmp(argv[i], "stdout", 6)) {
+ use_stdout = 1;
+ break;
+ }
+ }
+}
+
static void set_debug(int argc, char *argv[])
{
int i;
@@ -229,6 +250,7 @@ int main(int argc, char *argv[])
uint16_t host_ids[KNET_MAX_HOST];
size_t host_ids_entries = 0;
int has_crypto = 0;
+ int logfd;
if (argc < 3) {
print_usage(argv[0]);
@@ -252,9 +274,16 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ set_log(argc, argv);
+ if (use_stdout) {
+ logfd = 1;
+ } else {
+ logfd = logpipefd[1];
+ }
+
set_debug(argc, argv);
- if ((knet_h = knet_handle_new(1, knet_sock[0], logpipefd[1], loglevel)) == NULL) {
+ if ((knet_h = knet_handle_new(1, knet_sock[0], logfd, loglevel)) == NULL) {
printf("Unable to create new knet_handle_t\n");
exit(EXIT_FAILURE);
}
Please sign in to comment.
Something went wrong with that request. Please try again.