diff options
Diffstat (limited to 'web/attachments/264034-nagios-plugins_bind.patch')
-rw-r--r-- | web/attachments/264034-nagios-plugins_bind.patch | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/web/attachments/264034-nagios-plugins_bind.patch b/web/attachments/264034-nagios-plugins_bind.patch new file mode 100644 index 0000000..208ae96 --- /dev/null +++ b/web/attachments/264034-nagios-plugins_bind.patch | |||
@@ -0,0 +1,137 @@ | |||
1 | diff -ur nagiosplug-trunk/plugins/check_http.c nagiosplug/plugins/check_http.c | ||
2 | --- nagiosplug-trunk/plugins/check_http.c 2008-01-28 16:20:49.000000000 +0100 | ||
3 | +++ nagiosplug/plugins/check_http.c 2008-01-28 17:03:51.000000000 +0100 | ||
4 | @@ -97,6 +97,7 @@ | ||
5 | char server_port_text[6] = ""; | ||
6 | char server_type[6] = "http"; | ||
7 | char *server_address; | ||
8 | +char *client_address = NULL; | ||
9 | char *host_name; | ||
10 | char *server_url; | ||
11 | char *user_agent; | ||
12 | @@ -188,6 +189,7 @@ | ||
13 | {"ssl", no_argument, 0, 'S'}, | ||
14 | {"post", required_argument, 0, 'P'}, | ||
15 | {"IP-address", required_argument, 0, 'I'}, | ||
16 | + {"bind-address", required_argument, 0, 'B'}, | ||
17 | {"url", required_argument, 0, 'u'}, | ||
18 | {"port", required_argument, 0, 'p'}, | ||
19 | {"authorization", required_argument, 0, 'a'}, | ||
20 | @@ -228,7 +230,7 @@ | ||
21 | } | ||
22 | |||
23 | while (1) { | ||
24 | - c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); | ||
25 | + c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:B:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); | ||
26 | if (c == -1 || c == EOF) | ||
27 | break; | ||
28 | |||
29 | @@ -328,6 +330,9 @@ | ||
30 | case 'I': /* Server IP-address */ | ||
31 | server_address = strdup (optarg); | ||
32 | break; | ||
33 | + case 'B': /* Bind address */ | ||
34 | + client_address = strdup (optarg); | ||
35 | + break; | ||
36 | case 'u': /* URL path */ | ||
37 | server_url = strdup (optarg); | ||
38 | server_url_length = strlen (server_url); | ||
39 | @@ -732,7 +737,7 @@ | ||
40 | int result = STATE_UNKNOWN; | ||
41 | |||
42 | /* try to connect to the host at the given port number */ | ||
43 | - if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) | ||
44 | + if (my_tcp_bind_connect (server_address, server_port, &sd, client_address) != STATE_OK) | ||
45 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); | ||
46 | #ifdef HAVE_SSL | ||
47 | if (use_ssl == TRUE) { | ||
48 | @@ -1241,6 +1246,9 @@ | ||
49 | printf (" %s\n", _("Append a port to include it in the header (eg: example.com:5000)")); | ||
50 | printf (" %s\n", "-I, --IP-address=ADDRESS"); | ||
51 | printf (" %s\n", _("IP address or name (use numeric address if possible to bypass DNS lookup).")); | ||
52 | + printf (" %s\n", "-B, --bind-address=ADDRESS"); | ||
53 | + printf (" %s\n", _("IP address or name on the local machine to be used as the source address")); | ||
54 | + printf (" %s\n", _("of the connection.")); | ||
55 | printf (" %s\n", "-p, --port=INTEGER"); | ||
56 | printf (" %s", _("Port number (default: ")); | ||
57 | printf ("%d)\n", HTTP_PORT); | ||
58 | diff -ur nagiosplug-trunk/plugins/netutils.c nagiosplug/plugins/netutils.c | ||
59 | --- nagiosplug-trunk/plugins/netutils.c 2008-01-28 16:20:49.000000000 +0100 | ||
60 | +++ nagiosplug/plugins/netutils.c 2008-01-28 17:33:48.000000000 +0100 | ||
61 | @@ -163,12 +163,14 @@ | ||
62 | |||
63 | /* opens a tcp or udp connection to a remote host or local socket */ | ||
64 | int | ||
65 | -np_net_connect (const char *host_name, int port, int *sd, int proto) | ||
66 | +np_net_connect (const char *host_name, int port, int *sd, int proto, ...) | ||
67 | { | ||
68 | + va_list ap; | ||
69 | struct addrinfo hints; | ||
70 | - struct addrinfo *r, *res; | ||
71 | + struct addrinfo *r, *res, *rb; | ||
72 | struct sockaddr_un su; | ||
73 | char port_str[6], host[MAX_HOST_ADDRESS_LENGTH]; | ||
74 | + char *bindaddress; | ||
75 | size_t len; | ||
76 | int socktype, result; | ||
77 | |||
78 | @@ -200,6 +202,28 @@ | ||
79 | } | ||
80 | |||
81 | r = res; | ||
82 | + | ||
83 | + va_start(ap, proto); | ||
84 | + bindaddress = va_arg(ap, char *); | ||
85 | + va_end(ap); | ||
86 | + if (bindaddress) { | ||
87 | + memset (&hints, 0, sizeof (hints)); | ||
88 | + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ | ||
89 | + hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ | ||
90 | + hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */ | ||
91 | + hints.ai_protocol = 0; /* Any protocol */ | ||
92 | + hints.ai_canonname = NULL; | ||
93 | + hints.ai_addr = NULL; | ||
94 | + hints.ai_next = NULL; | ||
95 | + | ||
96 | + result = getaddrinfo (bindaddress, NULL, &hints, &res); | ||
97 | + if (result != 0) { | ||
98 | + printf ("%s\n", gai_strerror (result)); | ||
99 | + return STATE_UNKNOWN; | ||
100 | + } | ||
101 | + rb = res; | ||
102 | + } | ||
103 | + | ||
104 | while (r) { | ||
105 | /* attempt to create a socket */ | ||
106 | *sd = socket (r->ai_family, socktype, r->ai_protocol); | ||
107 | @@ -210,6 +234,15 @@ | ||
108 | return STATE_UNKNOWN; | ||
109 | } | ||
110 | |||
111 | + /* attempt to bind to source IP */ | ||
112 | + if (bindaddress) { | ||
113 | + result = bind(*sd, rb->ai_addr, rb->ai_addrlen); | ||
114 | + if (result != 0) { | ||
115 | + printf ("%s\n", _("Unable to bind to source address")); | ||
116 | + return STATE_UNKNOWN; | ||
117 | + } | ||
118 | + } | ||
119 | + | ||
120 | /* attempt to open a connection */ | ||
121 | result = connect (*sd, r->ai_addr, r->ai_addrlen); | ||
122 | |||
123 | diff -ur nagiosplug-trunk/plugins/netutils.h nagiosplug/plugins/netutils.h | ||
124 | --- nagiosplug-trunk/plugins/netutils.h 2008-01-28 16:20:49.000000000 +0100 | ||
125 | +++ nagiosplug/plugins/netutils.h 2008-01-28 17:27:30.000000000 +0100 | ||
126 | @@ -64,7 +64,10 @@ | ||
127 | /* my_connect and wrapper macros */ | ||
128 | #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP) | ||
129 | #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP) | ||
130 | -int np_net_connect(const char *address, int port, int *sd, int proto); | ||
131 | +#define my_tcp_bind_connect(addr, port, s, bind_addr) np_net_connect(addr, port, s, IPPROTO_TCP, bind_addr) | ||
132 | +#define my_ucp_bind_connect(addr, port, s, bind_addr) np_net_connect(addr, port, s, IPPROTO_TCP, bind_addr) | ||
133 | + | ||
134 | +int np_net_connect(const char *address, int port, int *sd, int proto, ...); | ||
135 | |||
136 | /* send_request and wrapper macros */ | ||
137 | #define send_tcp_request(s, sbuf, rbuf, rsize) \ | ||