Add addr in error msg if stun sock sent with error

Before:
```
(stun_port.cc:596): sendto : [0x00000041] No route to host
```

After:
```
(stun_port.cc:598): UDP send of 20 bytes to host stun1.l.google.com:19302 (74.125.200.127:19302) failed with error 65 : [0x00000041] No route to host
```

Bug: None
Change-Id: Ibcd487e97b37677225814562df30af66f655cddb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215000
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Yura Yaroshevich <yura.yaroshevich@gmail.com>
Cr-Commit-Position: refs/heads/master@{#33694}
This commit is contained in:
Yura Yaroshevich 2021-04-12 15:56:08 +03:00 committed by Commit Bot
parent 3928e8fdb1
commit 9ff75a6206
3 changed files with 22 additions and 2 deletions

View File

@ -306,7 +306,9 @@ int UDPPort::SendTo(const void* data,
if (send_error_count_ < kSendErrorLogLimit) {
++send_error_count_;
RTC_LOG(LS_ERROR) << ToString() << ": UDP send of " << size
<< " bytes failed with error " << error_;
<< " bytes to host " << addr.ToSensitiveString() << " ("
<< addr.ToResolvedSensitiveString()
<< ") failed with error " << error_;
}
} else {
send_error_count_ = 0;
@ -593,7 +595,11 @@ void UDPPort::OnSendPacket(const void* data, size_t size, StunRequest* req) {
options.info_signaled_after_sent.packet_type = rtc::PacketType::kStunMessage;
CopyPortInformationToPacketInfo(&options.info_signaled_after_sent);
if (socket_->SendTo(data, size, sreq->server_addr(), options) < 0) {
RTC_LOG_ERR_EX(LERROR, socket_->GetError()) << "sendto";
RTC_LOG_ERR_EX(LERROR, socket_->GetError())
<< "UDP send of " << size << " bytes to host "
<< sreq->server_addr().ToSensitiveString() << " ("
<< sreq->server_addr().ToResolvedSensitiveString()
<< ") failed with error " << error_;
}
stats_.stun_binding_requests_sent++;
}

View File

@ -178,6 +178,16 @@ std::string SocketAddress::ToSensitiveString() const {
return sb.str();
}
std::string SocketAddress::ToResolvedSensitiveString() const {
if (IsUnresolvedIP()) {
return "";
}
char buf[1024];
rtc::SimpleStringBuilder sb(buf);
sb << ipaddr().ToSensitiveString() << ":" << port();
return sb.str();
}
bool SocketAddress::FromString(const std::string& str) {
if (str.at(0) == '[') {
std::string::size_type closebracket = str.rfind(']');

View File

@ -124,6 +124,10 @@ class RTC_EXPORT SocketAddress {
// Same as ToString but anonymizes it by hiding the last part.
std::string ToSensitiveString() const;
// Returns hostname:port string if address is resolved, otherwise returns
// empty string.
std::string ToResolvedSensitiveString() const;
// Parses hostname:port and [hostname]:port.
bool FromString(const std::string& str);