Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP sendto removal + error when UDP for hostnames #2414

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/mavsdk/core/tcp_client_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,11 @@ bool TcpClientConnection::send_message(const mavlink_message_t& message)
auto flags = MSG_NOSIGNAL;
#endif

const auto send_len = sendto(
_socket_fd.get(),
reinterpret_cast<char*>(buffer),
buffer_len,
flags,
reinterpret_cast<const sockaddr*>(&dest_addr),
sizeof(dest_addr));
const auto send_len =
send(_socket_fd.get(), reinterpret_cast<const char*>(buffer), buffer_len, flags);

if (send_len != buffer_len) {
LogErr() << "sendto failure: " << GET_ERROR(errno);
LogErr() << "send failure: " << GET_ERROR(errno);
_is_ok = false;
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions src/mavsdk/core/udp_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ ConnectionResult UdpConnection::setup_port()

struct sockaddr_in addr {};
addr.sin_family = AF_INET;
inet_pton(AF_INET, _local_ip.c_str(), &(addr.sin_addr));
if (inet_pton(AF_INET, _local_ip.c_str(), &(addr.sin_addr)) != 1) {
LogErr() << "inet_pton failure for address: " << _local_ip;
return ConnectionResult::SocketError;
}
addr.sin_port = htons(_local_port_number);

if (bind(_socket_fd.get(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) != 0) {
Expand Down Expand Up @@ -129,7 +132,11 @@ bool UdpConnection::send_message(const mavlink_message_t& message)
struct sockaddr_in dest_addr {};
dest_addr.sin_family = AF_INET;

inet_pton(AF_INET, remote.ip.c_str(), &dest_addr.sin_addr.s_addr);
if (inet_pton(AF_INET, remote.ip.c_str(), &dest_addr.sin_addr.s_addr) != 1) {
LogErr() << "inet_pton failure for address: " << remote.ip;
send_successful = false;
continue;
}
dest_addr.sin_port = htons(remote.port_number);

uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
Expand Down
Loading