1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
--- nagios-plugins-1.4.15/plugins/check_http.c 2011-11-28 16:35:25.000000000 +0000
+++ nagios-plugins-1.4.15.new/plugins/check_http.c 2011-11-28 13:26:56.000000000 +0000
@@ -90,10 +90,12 @@
int specify_port = FALSE;
int server_port = HTTP_PORT;
+int virtual_port = 0;
char server_port_text[6] = "";
char server_type[6] = "http";
char *server_address;
char *host_name;
+int host_name_length;
char *server_url;
char *user_agent;
int server_url_length;
@@ -334,11 +336,25 @@
case 'H': /* Host Name (virtual host) */
host_name = strdup (optarg);
if (host_name[0] == '[') {
- if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */
- server_port = atoi (p + 2);
+ if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */
+ virtual_port = atoi (p + 2);
+ /* cut off the port */
+ host_name_length = strlen (host_name) - strlen (p) - 1;
+ free (host_name);
+ host_name = strndup (optarg, host_name_length);
+ if (specify_port == FALSE)
+ server_port = virtual_port;
+ }
} else if ((p = strchr (host_name, ':')) != NULL
- && strchr (++p, ':') == NULL) /* IPv4:port or host:port */
- server_port = atoi (p);
+ && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */
+ virtual_port = atoi (p);
+ /* cut off the port */
+ host_name_length = strlen (host_name) - strlen (p) - 1;
+ free (host_name);
+ host_name = strndup (optarg, host_name_length);
+ if (specify_port == FALSE)
+ server_port = virtual_port;
+ }
break;
case 'I': /* Server IP-address */
server_address = strdup (optarg);
@@ -484,6 +500,9 @@
if (http_method == NULL)
http_method = strdup ("GET");
+ if (virtual_port == 0)
+ virtual_port = server_port;
+
return TRUE;
}
@@ -829,11 +848,11 @@
* 14.23). Some server applications/configurations cause trouble if the
* (default) port is explicitly specified in the "Host:" header line.
*/
- if ((use_ssl == FALSE && server_port == HTTP_PORT) ||
- (use_ssl == TRUE && server_port == HTTPS_PORT))
+ if ((use_ssl == FALSE && virtual_port == HTTP_PORT) ||
+ (use_ssl == TRUE && virtual_port == HTTPS_PORT))
asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
else
- asprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port);
+ asprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port);
}
/* optionally send any other header tag */
@@ -1255,6 +1274,9 @@
MAX_PORT, server_type, server_address, server_port, server_url,
display_html ? "</A>" : "");
+ /* reset virtual port */
+ virtual_port = server_port;
+
if (verbose)
printf (_("Redirection to %s://%s:%d%s\n"), server_type,
host_name ? host_name : server_address, server_port, server_url);
|