diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/netliba/v6/udp_socket.h | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/netliba/v6/udp_socket.h')
-rw-r--r-- | library/cpp/netliba/v6/udp_socket.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/library/cpp/netliba/v6/udp_socket.h b/library/cpp/netliba/v6/udp_socket.h new file mode 100644 index 0000000000..bd95b8bcd0 --- /dev/null +++ b/library/cpp/netliba/v6/udp_socket.h @@ -0,0 +1,59 @@ +#pragma once + +#include <util/generic/ptr.h> +#include <util/generic/utility.h> +#include <library/cpp/netliba/socket/socket.h> + +namespace NNetliba { + bool IsLocalIPv4(ui32 ip); + bool IsLocalIPv6(ui64 network, ui64 iface); + bool InitLocalIPList(); + + enum { + UDP_LOW_LEVEL_HEADER_SIZE = 4, + }; + + using NNetlibaSocket::EFragFlag; + using NNetlibaSocket::FF_ALLOW_FRAG; + using NNetlibaSocket::FF_DONT_FRAG; + + class TNetSocket: public TNonCopyable { + TIntrusivePtr<NNetlibaSocket::ISocket> s; + ui32 PortCrc; + mutable int Tos; + + public: + enum ESendError { + SEND_OK, + SEND_BUFFER_OVERFLOW, + SEND_NO_ROUTE_TO_HOST, + }; + TNetSocket() + : PortCrc(0) + , Tos(0) + { + } + ~TNetSocket() { + } + + void Open(int port); + void Open(const TIntrusivePtr<NNetlibaSocket::ISocket>& socket); + void Close(); + void SendSelfFakePacket() const; + bool IsValid() const { + return s.Get() ? s->IsValid() : false; + } + int GetNetworkOrderPort() const { + return s->GetNetworkOrderPort(); + } + ESendError SendTo(const char* buf, int size, const sockaddr_in6& toAddress, const EFragFlag frag) const; + bool RecvFrom(char* buf, int* size, sockaddr_in6* fromAddress) const; + void Wait(float timeoutSec) const; + void SetTOS(int n) const; + + // obtaining icmp host unreachable in convoluted way + bool Connect(const sockaddr_in6& addr); + void SendEmptyPacket(); + bool IsHostUnreachable(); + }; +} |