From: Michal 'vorner' Vaner Date: Fri, 6 Jan 2012 14:25:23 +0000 (+0100) Subject: [805] Socket options and tests for them X-Git-Tag: trac2351_base~304^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f786ba4251dac7a4feb71a604cfdf27003305ddf;p=thirdparty%2Fkea.git [805] Socket options and tests for them Added the v6 only flag for IPv6 sockets. Both reuse address and this flags get tested. --- diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 420fde7c7f..c33d9c3445 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -39,6 +39,10 @@ get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { return -2; // This is part of the binding process, so it's a bind error } + if (bind_addr->sa_family == AF_INET6 && + setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) { + return -2; // This is part of the binding process, so it's a bind error + } if (bind(sock, bind_addr, addr_len) == -1) { return -2; } diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 73cbf48df6..58f9217e7e 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -59,6 +59,15 @@ namespace { #SOCK_TYPE " and family " #ADDR_FAMILY ", failed with " \ << socket << " and error " << strerror(errno); \ CHECK_SOCK(ADDR_TYPE, socket); \ + int on; \ + socklen_t len(sizeof(on)); \ + ASSERT_EQ(0, getsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &on, &len));\ + ASSERT_EQ(1, on); \ + if (ADDR_FAMILY == AF_INET6) { \ + ASSERT_EQ(0, getsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY, &on, \ + &len)); \ + ASSERT_EQ(1, on); \ + } \ EXPECT_EQ(0, close(socket)); \ } while (0)