summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2009-10-29 03:11:05 +0000
committerStef Walter <stef@memberwebs.com>2009-10-29 03:11:05 +0000
commite1cb7bdd2e79e3fc39f3764c2c9c8fd0cfdf55e8 (patch)
tree42c000fcc655bdefd99586e7ab8c9da926b7f379
parentf78fa42944de072c8e12ba9b6fe57b7ebe354868 (diff)
Skip local socket types that the OS doesn't support.
When binding to local addresses, certain OS configurations will return 'not supported' for various socket types, like ipv6. Skip those socket types when they come up.
-rw-r--r--common/snmp-engine.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/common/snmp-engine.c b/common/snmp-engine.c
index 0025d2f..1c29320 100644
--- a/common/snmp-engine.c
+++ b/common/snmp-engine.c
@@ -1036,17 +1036,26 @@ snmp_engine_init (const char **bindaddrs, int retries)
hints.ai_flags = AI_NUMERICSERV;
r = getaddrinfo (bindaddr, "0", &hints, &ai);
if (r != 0)
- errx (1, "couldn't resolve bind address: %s: %s", bindaddr, gai_strerror (r));
+ errx (1, "couldn't resolve bind address '%s': %s", bindaddr, gai_strerror (r));
fd = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (fd < 0)
- err (1, "couldn't open snmp socket");
+ if (fd < 0) {
+ if (errno == EPROTONOSUPPORT ||
+ errno == ENOPROTOOPT ||
+ errno == ESOCKTNOSUPPORT) {
+ warn ("couldn't create snmp socket for '%s'", bindaddr);
+ freeaddrinfo (ai);
+ continue;
+ } else {
+ err (1, "couldn't open snmp socket");
+ }
+ }
if (bind (fd, ai->ai_addr, ai->ai_addrlen) < 0)
err (1, "couldn't listen on port");
if (server_watch (fd, SERVER_READ, request_response, NULL) == -1)
- err (1, "couldn't listen on socket");
+ err (1, "couldn't watch port");
/* Stash this socket info */
sock = xcalloc (sizeof (struct socket));
@@ -1063,6 +1072,9 @@ snmp_engine_init (const char **bindaddrs, int retries)
freeaddrinfo (ai);
}
+ if (snmp_sockets == NULL)
+ errx (1, "no local addresses to listen on");
+
/* We fire off the resend timer every 1/5 second */
if (server_timer (200, request_resend_timer, NULL) == -1)
err(1, "couldn't setup timer");