port unreachable errors on Linux.
See https://sourceware.org/bugzilla/show_bug.cgi?id=24047
return flags & O_NONBLOCK;
}
+bool setReceiveSocketErrors(int sock, int af)
+{
+#ifdef __linux__
+ int tmp = 1, ret;
+ if (af == AF_INET) {
+ ret = setsockopt(sock, IPPROTO_IP, IP_RECVERR, &tmp, sizeof(tmp));
+ } else {
+ ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVERR, &tmp, sizeof(tmp));
+ }
+ if (ret < 0) {
+ throw PDNSException(string("Setsockopt failed: ") + strerror(errno));
+ }
+#endif
+ return true;
+}
+
// Closes a socket.
int closesocket( int socket )
{
bool setTCPNoDelay(int sock);
bool setReuseAddr(int sock);
bool isNonBlocking(int sock);
+bool setReceiveSocketErrors(int sock, int af);
int closesocket(int fd);
bool setCloseOnExec(int sock);
uint64_t udpErrorStats(const std::string& str);
if(!tries)
throw PDNSException("Resolver binding to local query client socket on "+sin.toString()+": "+stringerror());
+ setReceiveSocketErrors(ret, family);
setNonBlocking(ret);
return ret;
}