Ipv6 support.
Changes to support Ipv6.
Change-Id: I0f1e991e79e7b1fe7f6f4890cef85049cb23b4c3
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/slp_server.cpp b/slp_server.cpp
index e307dab..29c3a2f 100644
--- a/slp_server.cpp
+++ b/slp_server.cpp
@@ -16,7 +16,7 @@
*/
int slp::udp::Server::run()
{
- struct sockaddr_in in {};
+ struct sockaddr_in6 serverAddr {};
sd_event* event = nullptr;
@@ -68,18 +68,17 @@
goto finish;
}
- fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
+ fd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (fd < 0)
{
r = -errno;
goto finish;
}
- in.sin_family = AF_INET;
- in.sin_port = htons(this->port);
- in.sin_addr.s_addr = INADDR_ANY;
+ serverAddr.sin6_family = AF_INET6;
+ serverAddr.sin6_port = htons(this->port);
- if (bind(fd, (struct sockaddr*)&in, sizeof(in)) < 0)
+ if (bind(fd, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0)
{
r = -errno;
goto finish;
diff --git a/sock_channel.cpp b/sock_channel.cpp
index ef86029..34adf3a 100644
--- a/sock_channel.cpp
+++ b/sock_channel.cpp
@@ -15,7 +15,7 @@
std::string Channel::getRemoteAddress() const
{
char tmp[INET_ADDRSTRLEN] = { 0 };
- inet_ntop(AF_INET, &address.inAddr.sin_addr, tmp, sizeof(tmp));
+ inet_ntop(AF_INET6, &address.inAddr.sin6_addr, tmp, sizeof(tmp));
return std::string(tmp);
}
@@ -154,3 +154,4 @@
}
} // namespace udpsocket
+
diff --git a/sock_channel.hpp b/sock_channel.hpp
index e992564..1bd047e 100644
--- a/sock_channel.hpp
+++ b/sock_channel.hpp
@@ -24,7 +24,7 @@
union
{
sockaddr sockAddr;
- sockaddr_in inAddr;
+ sockaddr_in6 inAddr;
};
size_t addrSize;
};
@@ -65,7 +65,7 @@
*/
auto getPort() const
{
- return address.inAddr.sin_port;
+ return address.inAddr.sin6_port;
}
/**