Skip to content

Commit

Permalink
fix: raw_name_data not being used properly
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleCouponDay committed Feb 6, 2022
1 parent ef6f923 commit 11e3a88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ std::vector<char> Protocol::receive_bytes(SOCKET handle, raw_name_data& expected
sockaddr addr;
socklen_t addr_len = sizeof(sockaddr_in);
std::vector<char> data(500, (char)0, std::allocator<char>());
int result = ::recvfrom(handle, data.data(), (int)data.size(), 0, &expected_endpoint.name, &expected_endpoint.name_len);
int result = ::recvfrom(handle, data.data(), (int)data.size(), 0, &addr, &addr_len);
throw_if_socket_error(result, "Failed to receive UDP bytes with: " + get_last_error(), LINE_CONTEXT);

raw_name_data incoming{ addr, addr_len };
if (incoming != expected_endpoint && expected_endpoint.initialized == false)
if (incoming != expected_endpoint && expected_endpoint.initialized == true)
{
auto readable = convert_to_readable(incoming);
auto message = "Receiving UDP data from an undesired endpoint (" + readable.ip_address + ":" + readable.port + ")";
Expand All @@ -101,6 +101,8 @@ std::vector<char> Protocol::receive_bytes(SOCKET handle, raw_name_data& expected
auto message = "Receiving (UDP) data failed: " + get_last_error();
throw_new_exception(message, LINE_CONTEXT);
}
if (expected_endpoint.initialized == false)
std::memcpy(&expected_endpoint, &incoming, sizeof(raw_name_data));
expected_endpoint.initialized = true;
data.resize(result);
return data;
Expand Down
1 change: 0 additions & 1 deletion src/ptop_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ std::vector<char> PtopSocket::receive_bytes()
return _protocol.receive_bytes(_handle, _endpoint);
}


bool PtopSocket::send_udp_bytes(udp_bytes bytes)
{
return _protocol.send_bytes(_handle, bytes.endpoint, bytes.bytes);
Expand Down

0 comments on commit 11e3a88

Please sign in to comment.