Finished implementing, now for the testing phase.
This commit is contained in:
@@ -25,12 +25,12 @@ namespace ehs
|
||||
{
|
||||
}
|
||||
|
||||
UDP::UDP(const AddrType addrType)
|
||||
: BaseUDP(addrType), hdl(EHS_INVALID_SOCKET)
|
||||
UDP::UDP(const IP version)
|
||||
: BaseUDP(version), hdl(EHS_INVALID_SOCKET)
|
||||
{
|
||||
if (addrType == AddrType::IPV6)
|
||||
if (version == IP::V6)
|
||||
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
else if (addrType == AddrType::IPV4)
|
||||
else if (version == IP::V4)
|
||||
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
else
|
||||
return;
|
||||
@@ -96,33 +96,32 @@ namespace ehs
|
||||
bound = false;
|
||||
}
|
||||
|
||||
void UDP::Bind(const AddrType type, const Str_8& address, const UInt_16 port)
|
||||
void UDP::Bind(const Endpoint &endpoint)
|
||||
{
|
||||
if (!IsValid() || bound)
|
||||
return;
|
||||
|
||||
if (type == AddrType::IPV6)
|
||||
Bind_v6(address, port);
|
||||
else if (type == AddrType::IPV4)
|
||||
Bind_v4(address, port);
|
||||
if (endpoint.version == IP::V6)
|
||||
Bind_v6(endpoint.address, endpoint.port);
|
||||
else if (endpoint.version == IP::V4)
|
||||
Bind_v4(endpoint.address, endpoint.port);
|
||||
|
||||
this->address = address;
|
||||
this->port = port;
|
||||
localEndpoint = endpoint;
|
||||
|
||||
bound = true;
|
||||
}
|
||||
|
||||
UInt_64 UDP::Send(const AddrType type, const Str_8& address, const UInt_16 port, const Byte *const data, const UInt_64 size)
|
||||
UInt_64 UDP::Send(const Endpoint &endpoint, const Byte *const data, const UInt_64 size)
|
||||
{
|
||||
if (type == AddrType::IPV6)
|
||||
return Send_v6(address, port, data, size);
|
||||
else if (type == AddrType::IPV4)
|
||||
return Send_v4(address, port, data, size);
|
||||
if (endpoint.version == IP::V6)
|
||||
return Send_v6(endpoint.address, endpoint.port, data, size);
|
||||
else if (endpoint.version == IP::V4)
|
||||
return Send_v4(endpoint.address, endpoint.port, data, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt_64 UDP::Receive(AddrType* const type, Str_8* const address, UInt_16* const port, Byte* const data, const UInt_64 size)
|
||||
UInt_64 UDP::Receive(Endpoint *endpoint, Byte* const data, const UInt_64 size)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
@@ -161,9 +160,7 @@ namespace ehs
|
||||
return received;
|
||||
}
|
||||
|
||||
*type = AddrType::IPV6;
|
||||
*address = tmpAddr;
|
||||
*port = ntohs(remote.sin6_port);
|
||||
*endpoint = {IP::V6, tmpAddr, remote.sin6_port};
|
||||
}
|
||||
else if (addrLen == sizeof(sockaddr_in))
|
||||
{
|
||||
@@ -178,9 +175,7 @@ namespace ehs
|
||||
return received;
|
||||
}
|
||||
|
||||
*type = AddrType::IPV4;
|
||||
*address = tmpAddr;
|
||||
*port = ntohs(((sockaddr_in*)&remote)->sin_port);
|
||||
*endpoint = {IP::V4, tmpAddr, ntohs(((sockaddr_in*)&remote)->sin_port)};
|
||||
}
|
||||
|
||||
return received;
|
||||
@@ -205,7 +200,7 @@ namespace ehs
|
||||
|
||||
void UDP::SetIPv6Only(const bool value)
|
||||
{
|
||||
if (type != AddrType::IPV6)
|
||||
if (localEndpoint.version != IP::V6)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
||||
return;
|
||||
@@ -229,7 +224,7 @@ namespace ehs
|
||||
|
||||
bool UDP::IsIPv6Only() const
|
||||
{
|
||||
if (type != AddrType::IPV6)
|
||||
if (localEndpoint.version != IP::V6)
|
||||
return false;
|
||||
|
||||
if (!IsValid())
|
||||
|
Reference in New Issue
Block a user