From e1cb7bdd2e79e3fc39f3764c2c9c8fd0cfdf55e8 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 29 Oct 2009 03:11:05 +0000 Subject: 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. --- common/snmp-engine.c | 20 ++++++++++++++++---- 1 file 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"); -- cgit v1.2.3