diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-01-27 11:53:25 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-01-27 11:53:25 +0000 |
commit | 0716ab15017139cada7be0aa030b6283a22e6779 (patch) | |
tree | f1532b8ef3b8915d950be4101714fcc193c14404 /plugins/check_http.c | |
parent | a305b2be1d979a6ba8b548e12b9e2aa40cf4c306 (diff) | |
download | monitoring-plugins-0716ab15017139cada7be0aa030b6283a22e6779.tar.gz |
do not pass host if none is provided
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@254 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 5da5750a..be18ce7d 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -196,7 +196,7 @@ int server_port = HTTP_PORT; char server_port_text[6] = ""; char server_type[6] = "http"; /*@null@*/ char *server_address = NULL; -/*@null@*/ char *host_name = NULL; +char *host_name = ""; /*@null@*/ char *server_url = NULL; int server_url_length = 0; int server_expect_yn = 0; @@ -401,7 +401,7 @@ process_arguments (int argc, char **argv) break; /* Note: H, I, and u must be malloc'd or will fail on redirects */ case 'H': /* Host Name (virtual host) */ - host_name = strscpy (host_name, optarg); + asprintf (&host_name, "%s", optarg); break; case 'I': /* Server IP-address */ server_address = strscpy (server_address, optarg); @@ -464,19 +464,21 @@ process_arguments (int argc, char **argv) c = optind; - if (server_address == NULL && host_name == NULL) { server_address = strscpy (NULL, argv[c]); - host_name = strscpy (NULL, argv[c++]); + if (server_address == NULL) { + if (c < argc) { + server_address = strscpy (NULL, argv[c++]); + } + else if (strcmp (host_name ,"") == 0) { + usage ("check_http: you must specify a server address\n"); + } } - if (server_address == NULL && host_name == NULL) - usage ("check_http: you must specify a host name\n"); + if (strcmp (host_name ,"") == 0 && c < argc) + asprintf (&host_name, "%s", argv[c++]); if (server_address == NULL) server_address = strscpy (NULL, host_name); - if (host_name == NULL) - host_name = strscpy (NULL, server_address); - if (http_method == NULL) http_method = strscpy (http_method, "GET"); @@ -631,8 +633,6 @@ check_http (void) terminate (STATE_CRITICAL, "Unable to open TCP socket"); asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); send (sd, buf, strlen (buf), 0); - - /* optionally send the host header info */ if (strcmp (host_name, "")) { @@ -664,7 +664,7 @@ check_http (void) send (sd, http_post_data, strlen (http_post_data), 0); } else { - /* send a newline so the server knows we're done with the request */ + /* or just a newline so the server knows we're done with the request */ asprintf (&buf, "\r\n"); send (sd, buf, strlen (buf), 0); } |