for (Iface::AddressCollection::iterator addr = unicasts.begin();
addr != unicasts.end(); ++addr) {
- sock = openSocket(iface->getName(), *addr, port);
- if (sock < 0) {
- const char* errstr = strerror(errno);
- isc_throw(SocketConfigError, "failed to open unicast socket on "
- << *addr << " on interface " << iface->getName()
- << ", reason: " << errstr);
+ try {
+ openSocket(iface->getName(), *addr, port);
-
+ } catch (const Exception& ex) {
+ IFACEMGR_ERROR(SocketConfigError, error_handler,
+ "Failed to open unicast socket on interface "
+ << iface->getName() << ", reason: "
+ << ex.what());
+ continue;
}
count++;
continue;
}
- sock = openSocket(iface->getName(), *addr, port);
- if (sock < 0) {
- const char* errstr = strerror(errno);
- isc_throw(SocketConfigError, "failed to open link-local socket on "
- << *addr << " on interface "
- << iface->getName() << ", reason: " << errstr);
- }
-
- // Binding socket to unicast address and then joining multicast group
- // works well on Mac OS (and possibly other BSDs), but does not work
- // on Linux.
- if ( !joinMulticast(sock, iface->getName(),
- string(ALL_DHCP_RELAY_AGENTS_AND_SERVERS))) {
- close(sock);
- isc_throw(SocketConfigError, "Failed to join "
- << ALL_DHCP_RELAY_AGENTS_AND_SERVERS
- << " multicast group.");
+ // Open socket and join multicast group only if the interface
+ // is multicast-capable.
+ // @todo The DHCPv6 requires multicast so we may want to think
+ // whether we want to open the socket on a multicast-incapable
+ // interface or not. For now, we prefer to be liberal and allow
+ // it for some odd use cases which may utilize non-multicast
+ // interfaces. Perhaps a warning should be emitted if the
+ // interface is not a multicast one.
+
+ // The sock variable will hold a socket descriptor. It may be
+ // used to close a socket if the function fails to bind to
+ // multicast address on Linux systems. Because we only bind
+ // a socket to multicast address on Linux, on other systems
+ // the sock variable will be initialized but unused. We have
+ // to suppress the cppcheck warning which shows up on non-Linux
+ // systems.
+ // cppcheck-suppress variableScope
+ int sock;
+ try {
+ // cppcheck-suppress unreadVariable
+ sock = openSocket(iface->getName(), *addr, port,
+ iface->flag_multicast_);
+
+ } catch (const Exception& ex) {
+ IFACEMGR_ERROR(SocketConfigError, error_handler,
+ "Failed to open link-local socket on "
+ " interface " << iface->getName() << ": "
+ << ex.what());
+ continue;
-
}
count++;