L
L
LoliDeveloper2021-06-14 15:13:46
Computer networks
LoliDeveloper, 2021-06-14 15:13:46

Why is the UDP client on VirtualBox-Ubuntu not receiving datagrams from the UDP-server-Windows?

My client sends a datagram to the server and waits for a response. The datagram arrives generally fine, but when the server sends a sign that it received the datagram, it does not reach the client. The client is on VirtualBox-Ubuntu. When I start the client and the server on Windows, everything is ok. Maybe there is some Linux subtlety here? Here is how I send the response back:

//приём датаграммы от клиента
int received = recvfrom(ls[i], datagram, sizeof(datagram), 
0, (struct sockaddr*) &addr, &addrlen); 
if (received > 0) {
    //отправка датаграммы, которая говорит что всё хорошо
    sendto(ls[i], datagram, 4, 0, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)); 
    //получается что я отправляю на тот же addr. Когда я запускаю клиента на винде то всё хорошо
}


Through WireShark, it shows that everything is coming to the correct port and sent from the correct port. I don't really understand what the problem is

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-14
@LoliDeveloper

while ((sel = select(s, &rfd, NULL, NULL, &time_val)) <= 0) {
                        res = sendto(s, dns_datagram, data_curlen, flags, (struct sockaddr*) &addr,
                                sizeof(struct sockaddr_in));
                        if (res < 0) {
                                printf("res = %d\nError. Server offline?\n", res);
                                printf("sel = %d\n", sel); // out 0
                        }
                        FD_ZERO(&rfd);
                        FD_SET(s, &rfd);
                }

First, why is the condition <=0 and not ==0? A return of -1 means an error, and should not be swallowed. Timeout is exactly 0.
And I see a cant in the first argument of select.
nfds This argument should be set to the highest-numbered file
descriptor in any of the three sets, plus 1 . The
indicated file descriptors in each set are checked, up to
this limit (but see BUGS).

Those. you need to transfer s+1 there.
And yes, MSDN writes:
nfds Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.

That's why it works under Windows.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question