Skip to content
Snippets Groups Projects
Commit 6a74d043 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #8444: Added debug messages when binding sockets to interfaces

parent 540e6719
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <netdb.h> #include <netdb.h>
#include <dirent.h> #include <dirent.h>
#include <net/if.h> #include <net/if.h>
#include <arpa/inet.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
...@@ -112,10 +113,12 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p ...@@ -112,10 +113,12 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p
// emitted through this interface. // emitted through this interface.
// //
// Requires CAP_NET_RAW (or root) // Requires CAP_NET_RAW (or root)
struct ifreq ifr; LOG_DEBUG_STR("Binding socket " << description << " to interface " << bind_local_iface);
struct ifreq ifr;
memset(&ifr, 0, sizeof ifr); memset(&ifr, 0, sizeof ifr);
snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", bind_local_iface.c_str()); snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", bind_local_iface.c_str());
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr) < 0) if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr) < 0)
try { try {
THROW_SYSCALL("setsockopt(SO_BINDTODEVICE)"); THROW_SYSCALL("setsockopt(SO_BINDTODEVICE)");
...@@ -127,6 +130,7 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p ...@@ -127,6 +130,7 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p
if (mode == Client) { if (mode == Client) {
if (bind_local_iface != "") { if (bind_local_iface != "") {
struct sockaddr sa = getInterfaceIP(bind_local_iface); struct sockaddr sa = getInterfaceIP(bind_local_iface);
LOG_DEBUG_STR("Binding socket " << description << " to IP " << inet_ntoa(((struct sockaddr_in*)&sa)->sin_addr) << " of interface " << bind_local_iface);
if (bind(fd, &sa, sizeof sa) < 0) if (bind(fd, &sa, sizeof sa) < 0)
THROW_SYSCALL(str(boost::format("bind [%s]") % description)); THROW_SYSCALL(str(boost::format("bind [%s]") % description));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment