Skip to content

Commit

Permalink
More verbose logging when unable to bind and fix issue with interface…
Browse files Browse the repository at this point in the history
…s on macOS.
  • Loading branch information
chrisstaite committed Dec 7, 2020
1 parent 6570281 commit d3352c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
5 changes: 1 addition & 4 deletions include/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class ConfigParser
sockaddr_storage address;
};

/// \brief Parse the configuration
///
/// \param argc The number of arguments in argv
/// \param argv The parameters passed in
/// \brief Setup for configuration parsing
ConfigParser();

/// \brief Parse the configuration
Expand Down
13 changes: 10 additions & 3 deletions src/client_forwarders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,19 @@ void ClientForwarders::handleIncoming(const std::shared_ptr<Socket>& socket,
{
clientLength = sizeof(sockaddr_in6);
}
char controlBuf[256];

struct msghdr message {
const_cast<sockaddr_storage*>(&client),
clientLength, iov, 1, controlBuf, 0, 0
clientLength, iov, 1, nullptr, 0, 0
};

addSourceAddress(message, server, interface);
// Only set the source address if interface is given
char controlBuf[256];
if (interface != -1)
{
message.msg_control = controlBuf;
addSourceAddress(message, server, interface);
}

if (sendmsg(socket->get(), &message, 0) == -1)
{
Expand All @@ -240,3 +246,4 @@ void ClientForwarders::handleIncoming(const std::shared_ptr<Socket>& socket,
}

} // namespace dote

28 changes: 14 additions & 14 deletions src/dote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ bool Dote::listen(const ConfigParser& config)
m_server = std::make_shared<Server>(m_loop, m_forwarders);
for (const auto& serverConfig : config.servers())
{
char ip[64];
switch(serverConfig.address.ss_family) {
case AF_INET:
inet_ntop(AF_INET, &reinterpret_cast<const struct sockaddr_in&>(serverConfig.address).sin_addr, ip, sizeof(ip));
break;

case AF_INET6:
inet_ntop(AF_INET6, &reinterpret_cast<const struct sockaddr_in6&>(serverConfig.address).sin6_addr, ip, sizeof(ip));
break;
default:
ip[0] = '\0';
break;
}
if (!m_server->addServer(serverConfig))
{
Log::err << "Unable to bind to server port";
Log::err << "Unable to bind to server port " << ip;
result = false;
}
else
{
char ip[64];
switch(serverConfig.address.ss_family) {
case AF_INET:
inet_ntop(AF_INET, &reinterpret_cast<const struct sockaddr_in&>(serverConfig.address).sin_addr, ip, sizeof(ip));
break;

case AF_INET6:
inet_ntop(AF_INET6, &reinterpret_cast<const struct sockaddr_in6&>(serverConfig.address).sin6_addr, ip, sizeof(ip));
break;
default:
ip[0] = '\0';
break;
}
Log::info << "Bound server " << ip;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ bool Socket::enablePacketInfo()
if (m_domain == PF_INET)
{
#ifdef __APPLE__
proto = IP_PKTINFO;
proto = IPPROTO_IP;
#else
proto = SOL_IP;
#endif
Expand Down

0 comments on commit d3352c3

Please sign in to comment.