refactored addr print, using AI_PASSIVE now
This commit is contained in:
parent
5144cbd789
commit
fbe860c6a5
@ -15,7 +15,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! Debugging preprocessor define.
|
//! Debugging preprocessor define.
|
||||||
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
#define FSFW_UDP_RECV_WIRETAPPING_ENABLED 0
|
||||||
|
|
||||||
UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId,
|
UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId,
|
||||||
object_id_t tmtcUnixUdpBridge, size_t maxRecvSize,
|
object_id_t tmtcUnixUdpBridge, size_t maxRecvSize,
|
||||||
@ -66,10 +66,13 @@ ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) {
|
|||||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000);
|
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
#if FSFW_UDP_RECV_WIRETAPPING_ENABLED == 1
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived <<
|
sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived <<
|
||||||
" bytes received" << std::endl;
|
" bytes received" << std::endl;
|
||||||
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 */
|
||||||
|
|
||||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||||
@ -84,7 +87,7 @@ ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) {
|
|||||||
ReturnValue_t UdpTcPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
ReturnValue_t UdpTcPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||||
store_address_t storeId;
|
store_address_t storeId;
|
||||||
|
|
||||||
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
#if FSFW_UDP_RECV_WIRETAPPING_ENABLED == 1
|
||||||
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
|||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_DGRAM;
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
hints.ai_protocol = IPPROTO_UDP;
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
|
hints.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
/* Set up UDP socket:
|
/* Set up UDP socket:
|
||||||
https://en.wikipedia.org/wiki/Getaddrinfo
|
https://en.wikipedia.org/wiki/Getaddrinfo
|
||||||
@ -95,6 +96,10 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
|
tcpip::printAddress(addrResult->ai_addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
||||||
if(retval != 0) {
|
if(retval != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -121,10 +126,8 @@ ReturnValue_t UdpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
/* The target address can be set by different threads so this lock ensures thread-safety */
|
/* The target address can be set by different threads so this lock ensures thread-safety */
|
||||||
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
||||||
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
char ipAddress [15];
|
tcpip::printAddress(&clientAddress);
|
||||||
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
|
||||||
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int bytesSent = sendto(
|
int bytesSent = sendto(
|
||||||
@ -152,13 +155,11 @@ void UdpTmTcBridge::checkAndSetClientAddress(sockaddr& newAddress) {
|
|||||||
/* The target address can be set by different threads so this lock ensures thread-safety */
|
/* The target address can be set by different threads so this lock ensures thread-safety */
|
||||||
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
||||||
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
char ipAddress [15];
|
tcpip::printAddress(&newAddress);
|
||||||
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
tcpip::printAddress(&clientAddress);
|
||||||
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
|
||||||
sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
|
||||||
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
registerCommConnect();
|
registerCommConnect();
|
||||||
|
|
||||||
/* Set new IP address to reply to */
|
/* Set new IP address to reply to */
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "tcpipCommon.h"
|
#include "tcpipCommon.h"
|
||||||
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||||
|
|
||||||
void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string &protStr,
|
void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string &protStr,
|
||||||
std::string &srcString) {
|
std::string &srcString) {
|
||||||
@ -34,3 +35,37 @@ void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std:
|
|||||||
srcString = "unknown call";
|
srcString = "unknown call";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tcpip::printAddress(struct sockaddr* addr) {
|
||||||
|
char ipAddress[INET6_ADDRSTRLEN] = {};
|
||||||
|
const char* stringPtr = NULL;
|
||||||
|
switch(addr->sa_family) {
|
||||||
|
case AF_INET: {
|
||||||
|
struct sockaddr_in *addrIn = reinterpret_cast<struct sockaddr_in*>(addr);
|
||||||
|
stringPtr = inet_ntop(AF_INET, &(addrIn->sin_addr), ipAddress, INET_ADDRSTRLEN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AF_INET6: {
|
||||||
|
struct sockaddr_in6 *addrIn = reinterpret_cast<struct sockaddr_in6*>(addr);
|
||||||
|
stringPtr = inet_ntop(AF_INET6, &(addrIn->sin6_addr), ipAddress, INET6_ADDRSTRLEN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
if(stringPtr == NULL) {
|
||||||
|
sif::debug << "Could not convert IP address to text representation, error code "
|
||||||
|
<< errno << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::debug << "IP Address Sender: " << ipAddress << std::endl;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(stringPtr == NULL) {
|
||||||
|
sif::printDebug("Could not convert IP address to text representation, error code %d\n",
|
||||||
|
errno);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::printDebug("IP Address Sender: %s\n", ipAddress);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
#include "../../timemanager/clockDefinitions.h"
|
#include "../../timemanager/clockDefinitions.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace tcpip {
|
namespace tcpip {
|
||||||
|
|
||||||
const char* const DEFAULT_SERVER_PORT = "7301";
|
const char* const DEFAULT_SERVER_PORT = "7301";
|
||||||
@ -28,8 +35,8 @@ enum class ErrorSources {
|
|||||||
void determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string& protStr,
|
void determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string& protStr,
|
||||||
std::string& srcString);
|
std::string& srcString);
|
||||||
|
|
||||||
|
void printAddress(struct sockaddr* addr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSFW_OSAL_COMMON_TCPIPCOMMON_H_ */
|
#endif /* FSFW_OSAL_COMMON_TCPIPCOMMON_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user