Commit f786ba42 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[805] Socket options and tests for them

Added the v6 only flag for IPv6 sockets. Both reuse address and this
flags get tested.
parent 01d2bc6d
......@@ -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;
}
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment