summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-07-29 02:29:15 +0000
committerStef Walter <stef@memberwebs.com>2008-07-29 02:29:15 +0000
commit0a3d06dfa8f534c48109e3afd49a292c3947d0cd (patch)
treea5f03f6c30f1415bef857dd7fce55f6ade64f8cd
parent723785873edd5fc3c00fefc8894a2c2085676313 (diff)
- Add parameter to specify bind address.
-rw-r--r--ChangeLog3
-rw-r--r--common/snmp-engine.c18
-rw-r--r--common/snmp-engine.h2
-rw-r--r--daemon/rrdbotd.c10
-rw-r--r--doc/rrdbot-get.13
-rw-r--r--doc/rrdbotd.83
-rw-r--r--tools/rrdbot-get.c10
7 files changed, 36 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index f130d9f..fea42ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.9.2 [????]
+ - Add parameter to specify bind address.
+
0.9.1 [2008-07-07]
- Fix bug with table queries in rrdbot-get
- rrdbot-get now prints out unsigned integers properly.
diff --git a/common/snmp-engine.c b/common/snmp-engine.c
index 0bfb77d..0c1aa87 100644
--- a/common/snmp-engine.c
+++ b/common/snmp-engine.c
@@ -940,9 +940,9 @@ snmp_engine_sync (const char* host, const char* community, int version,
*/
void
-snmp_engine_init (int retries)
+snmp_engine_init (const char *bindaddr, int retries)
{
- struct sockaddr_in addr;
+ struct sockaddr_any addr;
snmp_retries = retries;
@@ -954,16 +954,18 @@ snmp_engine_init (int retries)
if (!snmp_preparing)
err (1, "out of memory");
+ memset (&addr, 0, sizeof(addr));
+ if (!bindaddr)
+ bindaddr = "0.0.0.0";
+ if (sock_any_pton (bindaddr, &addr, SANY_OPT_DEFPORT (0) | SANY_OPT_DEFANY) < 0)
+ err (1, "couldn't parse bind address: %s", bindaddr);
+
ASSERT (snmp_socket == -1);
- snmp_socket = socket (PF_INET, SOCK_DGRAM, 0);
+ snmp_socket = socket (SANY_TYPE (addr), SOCK_DGRAM, 0);
if (snmp_socket < 0)
err (1, "couldn't open snmp socket");
- /* Get a random IPv4 UDP socket for client use */
- memset (&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
-
- if (bind (snmp_socket, (struct sockaddr*)&addr, sizeof (addr)) < 0)
+ if (bind (snmp_socket, &SANY_ADDR (addr), SANY_LEN (addr)) < 0)
err (1, "couldn't listen on port");
if (server_watch (snmp_socket, SERVER_READ, request_response, NULL) == -1)
diff --git a/common/snmp-engine.h b/common/snmp-engine.h
index 36b2a3d..98a45e5 100644
--- a/common/snmp-engine.h
+++ b/common/snmp-engine.h
@@ -6,7 +6,7 @@
typedef void (*snmp_response) (int request, int code, struct snmp_value *value, void *data);
-void snmp_engine_init (int retries);
+void snmp_engine_init (const char *bind_address, int retries);
int snmp_engine_request (const char* host, const char* community, int version,
uint64_t interval, uint64_t timeout, int reqtype,
diff --git a/daemon/rrdbotd.c b/daemon/rrdbotd.c
index bbbc84b..573eb5f 100644
--- a/daemon/rrdbotd.c
+++ b/daemon/rrdbotd.c
@@ -205,6 +205,7 @@ int
main(int argc, char* argv[])
{
const char* pidfile = NULL;
+ const char *bind_address = NULL;
int daemonize = 1;
char ch;
char* t;
@@ -223,11 +224,16 @@ main(int argc, char* argv[])
g_state.timeout = DEFAULT_TIMEOUT;
/* Parse the arguments nicely */
- while((ch = getopt(argc, argv, "c:d:m:Mp:r:t:w:V")) != -1)
+ while((ch = getopt(argc, argv, "b:c:d:m:Mp:r:t:w:V")) != -1)
{
switch(ch)
{
+ /* Bind address */
+ case 'b':
+ bind_address = optarg;
+ break;
+
/* Config directory */
case 'c':
g_state.confdir = optarg;
@@ -305,7 +311,7 @@ main(int argc, char* argv[])
mib_uninit();
/* Rev up the main engine */
- snmp_engine_init(3);
+ snmp_engine_init(bind_address, 3);
rb_poll_engine_init();
if(daemonize)
diff --git a/doc/rrdbot-get.1 b/doc/rrdbot-get.1
index e9515d6..05837ed 100644
--- a/doc/rrdbot-get.1
+++ b/doc/rrdbot-get.1
@@ -44,6 +44,7 @@
.Nm
.Op Fl Mnr
.Op Fl m Ar mibdir
+.Op Fl s Ar srcaddr
.Op Fl t Ar timeout
.Ar snmp://community@host/oid
.Nm
@@ -68,6 +69,8 @@ Display MIB parsing warnings.
Display numeric OIDs.
.It Fl r
Recursively walk the SNMP values under the given OID.
+.It Fl s Ar srcaddr
+Source address to send SNMP packets from.
.It Fl t Ar timeout
The amount of time (in seconds) to wait for an SNMP response. Defaults to
5 seconds.
diff --git a/doc/rrdbotd.8 b/doc/rrdbotd.8
index 8217626..657e264 100644
--- a/doc/rrdbotd.8
+++ b/doc/rrdbotd.8
@@ -43,6 +43,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl M
+.Op Fl b Ar bindaddr
.Op Fl c Ar confdir
.Op Fl w Ar workdir
.Op Fl m Ar mibdir
@@ -72,6 +73,8 @@ configuration files are described in:
.Sh OPTIONS
The options are as follows.
.Bl -tag -width Fl
+.It Fl b Ar bindaddr
+Address to bind to and send SNMP packets from.
.It Fl c Ar confdir
The directory in which configuration files are stored. See below for info
on the various file locations.
diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c
index 0f84578..9b038dd 100644
--- a/tools/rrdbot-get.c
+++ b/tools/rrdbot-get.c
@@ -413,6 +413,7 @@ version()
int
main (int argc, char* argv[])
{
+ char *bind_address = NULL;
char ch;
char* t;
@@ -421,7 +422,7 @@ main (int argc, char* argv[])
ctx.timeout = DEFAULT_TIMEOUT;
/* Parse the arguments nicely */
- while ((ch = getopt (argc, argv, "m:Mnrt:vV")) != -1) {
+ while ((ch = getopt (argc, argv, "m:Mnrs:t:vV")) != -1) {
switch (ch)
{
@@ -445,6 +446,11 @@ main (int argc, char* argv[])
ctx.recursive = 1;
break;
+ /* local source address */
+ case 's':
+ bind_address = optarg;
+ break;
+
/* The timeout */
case 't':
ctx.timeout = strtoul (optarg, &t, 10);
@@ -478,7 +484,7 @@ main (int argc, char* argv[])
usage ();
server_init ();
- snmp_engine_init (MAX_RETRIES);
+ snmp_engine_init (bind_address, MAX_RETRIES);
parse_argument (argv[0]);