Fix sending on Posix

This commit is contained in:
Pascal Serrarens 2025-02-26 09:35:46 +01:00
parent 59006540e6
commit e7990cf00a

@ -92,11 +92,10 @@ void Participant::Receive() {
bool Participant::Send(RemoteParticipant* remoteParticipant, int bufferSize) {
#if defined(__unix__) || defined(__APPLE__)
// Set up the destination address
// char ip_str[INET_ADDRSTRLEN];
// inet_ntop(AF_INET, &(remote_addr.sin_addr), ip_str, INET_ADDRSTRLEN);
std::cout << "Send to " << ip_str << ":" << ntohs(remote_addr.sin_port)
<< "\n";
// std::cout << "Send to " << remoteParticipant->ipAddress << ":" << ntohs(remoteParticipant->port)
// << "\n";
// Set up the destination address
struct sockaddr_in dest_addr;
memset(&dest_addr, 0, sizeof(dest_addr));
dest_addr.sin_family = AF_INET;
@ -104,9 +103,9 @@ bool Participant::Send(RemoteParticipant* remoteParticipant, int bufferSize) {
dest_addr.sin_addr.s_addr = inet_addr(remoteParticipant->ipAddress);
// Send the message
int sent_bytes = sendto(sock, this->buffer, bufferSize, 0, (struct sockaddr*)&remote_addr, sizeof(remote_addr));
int sent_bytes = sendto(sock, this->buffer, bufferSize, 0, (struct sockaddr*)&dest_addr, sizeof(dest_addr));
if (sent_bytes < 0) {
std::cerr << "sendto failed with error: " << sent_bytes << std::endl;
std::cerr << "sendto failed with error: " << sent_bytes << " " << strerror(errno) << std::endl;
close(sock);
return false;
}