diff --git a/include/config_parser.h b/include/config_parser.h index 1f5267e..394245a 100644 --- a/include/config_parser.h +++ b/include/config_parser.h @@ -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 diff --git a/src/client_forwarders.cpp b/src/client_forwarders.cpp index 442e70c..299e8db 100644 --- a/src/client_forwarders.cpp +++ b/src/client_forwarders.cpp @@ -225,13 +225,19 @@ void ClientForwarders::handleIncoming(const std::shared_ptr& socket, { clientLength = sizeof(sockaddr_in6); } - char controlBuf[256]; + struct msghdr message { const_cast(&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) { @@ -240,3 +246,4 @@ void ClientForwarders::handleIncoming(const std::shared_ptr& socket, } } // namespace dote + diff --git a/src/dote.cpp b/src/dote.cpp index a0db0ec..5a68671 100644 --- a/src/dote.cpp +++ b/src/dote.cpp @@ -49,26 +49,26 @@ bool Dote::listen(const ConfigParser& config) m_server = std::make_shared(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(serverConfig.address).sin_addr, ip, sizeof(ip)); + break; + + case AF_INET6: + inet_ntop(AF_INET6, &reinterpret_cast(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(serverConfig.address).sin_addr, ip, sizeof(ip)); - break; - - case AF_INET6: - inet_ntop(AF_INET6, &reinterpret_cast(serverConfig.address).sin6_addr, ip, sizeof(ip)); - break; - default: - ip[0] = '\0'; - break; - } Log::info << "Bound server " << ip; } } diff --git a/src/socket.cpp b/src/socket.cpp index 23e59e3..c784449 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -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