Skip to content

Commit c70531a

Browse files
committed
Log IP address rather than key for UDPOutput errors
1 parent 5d5dbb8 commit c70531a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/channeloutput/UDPOutput.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ int UDPOutput::SendMessages(unsigned int socketKey, SendSocketInfo* socketInfo,
509509
}
510510
++errCount;
511511
if (errCount >= 10) {
512-
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (key: %X Socket: %d output count: %d/%d) with error: %d %s\n",
513-
socketKey, sendSocket,
512+
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (IP: %s Socket: %d output count: %d/%d) with error: %d %s\n",
513+
HexToIP(socketKey).c_str(), sendSocket,
514514
outputCount, msgCount,
515515
errno,
516516
strerror(errno));
@@ -553,8 +553,8 @@ void UDPOutput::BackgroundOutputWork() {
553553
i.socketInfo->errCount++;
554554

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

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

650650
// failed to send all messages or it took more than 100ms to send them
651-
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (key: %X output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
652-
msgs.first,
651+
LogErr(VB_CHANNELOUT, "sendmmsg() failed for UDP output (IP: %s output count: %d/%d time: %u ms errCount: %d) with error: %d %s\n",
652+
HexToIP(msgs.first).c_str(),
653653
outputCount, msgs.second.size(), diff, socketInfo->errCount,
654654
errno,
655655
strerror(errno));
@@ -860,3 +860,16 @@ void UDPOutput::StoppingOutput() {
860860
}
861861
}
862862
}
863+
864+
std::string UDPOutput::HexToIP(unsigned int hex) {
865+
// Extract each byte in LSB order
866+
uint8_t octet1 = hex & 0xFF; // Least significant byte
867+
uint8_t octet2 = (hex >> 8) & 0xFF;
868+
uint8_t octet3 = (hex >> 16) & 0xFF;
869+
uint8_t octet4 = (hex >> 24) & 0xFF; // Most significant byte
870+
871+
return std::to_string(octet1) + "." +
872+
std::to_string(octet2) + "." +
873+
std::to_string(octet3) + "." +
874+
std::to_string(octet4);
875+
}

src/channeloutput/UDPOutput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class UDPOutput : public ChannelOutput {
147147

148148
void PingControllers(bool failedOnly);
149149
std::atomic_int failedCount;
150+
std::string HexToIP(unsigned int hex);
150151

151152
class WorkItem {
152153
public:

0 commit comments

Comments
 (0)