Skip to content

Commit

Permalink
Log IP address rather than key for UDPOutput errors
Browse files Browse the repository at this point in the history
  • Loading branch information
darylc committed Jan 1, 2025
1 parent 5d5dbb8 commit c70531a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/channeloutput/UDPOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ int UDPOutput::SendMessages(unsigned int socketKey, SendSocketInfo* socketInfo,
}
++errCount;
if (errCount >= 10) {
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (key: %X Socket: %d output count: %d/%d) with error: %d %s\n",
socketKey, sendSocket,
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (IP: %s Socket: %d output count: %d/%d) with error: %d %s\n",
HexToIP(socketKey).c_str(), sendSocket,
outputCount, msgCount,
errno,
strerror(errno));
Expand Down Expand Up @@ -553,8 +553,8 @@ void UDPOutput::BackgroundOutputWork() {
i.socketInfo->errCount++;

// failed to send all messages or it took more than 100ms to send them
LogErr(VB_CHANNELOUT, "%s() failed for UDP output (key: %X output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
blockingOutput ? "sendmsg" : "sendmmsg", i.id,
LogErr(VB_CHANNELOUT, "%s() failed for UDP output (IP: %s output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
blockingOutput ? "sendmsg" : "sendmmsg", HexToIP(i.id).c_str(),
outputCount, i.msgs.size(), diff, i.socketInfo->errCount,
errno,
strerror(errno));
Expand Down Expand Up @@ -618,8 +618,8 @@ int UDPOutput::SendData(unsigned char* channelData) {
socketInfo->errCount++;

// failed to send all messages or it took more than 100ms to send them
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (key: %X output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
msgs.first,
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (IP: %s output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
HexToIP(msgs.first).c_str(),
outputCount, msgs.second.size(), diff, socketInfo->errCount,
errno,
strerror(errno));
Expand Down Expand Up @@ -648,8 +648,8 @@ int UDPOutput::SendData(unsigned char* channelData) {
socketInfo->errCount++;

// failed to send all messages or it took more than 100ms to send them
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (key: %X output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
msgs.first,
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (IP: %s output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
HexToIP(msgs.first).c_str(),
outputCount, msgs.second.size(), diff, socketInfo->errCount,
errno,
strerror(errno));
Expand Down Expand Up @@ -860,3 +860,16 @@ void UDPOutput::StoppingOutput() {
}
}
}

std::string UDPOutput::HexToIP(unsigned int hex) {
// Extract each byte in LSB order
uint8_t octet1 = hex & 0xFF; // Least significant byte
uint8_t octet2 = (hex >> 8) & 0xFF;
uint8_t octet3 = (hex >> 16) & 0xFF;
uint8_t octet4 = (hex >> 24) & 0xFF; // Most significant byte

return std::to_string(octet1) + "." +
std::to_string(octet2) + "." +
std::to_string(octet3) + "." +
std::to_string(octet4);
}
1 change: 1 addition & 0 deletions src/channeloutput/UDPOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class UDPOutput : public ChannelOutput {

void PingControllers(bool failedOnly);
std::atomic_int failedCount;
std::string HexToIP(unsigned int hex);

class WorkItem {
public:
Expand Down

0 comments on commit c70531a

Please sign in to comment.