baresip / re

Generic library for real-time communications with async IO support
BSD 3-Clause "New" or "Revised" License
132 stars 81 forks source link

test: udp_listen NULL #1100

Closed alfredh closed 5 months ago

alfredh commented 5 months ago

DRAFT

How should we handle if local address to udp_listen is NULL? Example:

udp_listen(us, NULL, handler, arg);

For example Windows fails with:

Process completed with exit code 10014.
sreimers commented 5 months ago

Process completed with exit code 10014.

Means: WSAEFAULT

The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a [sockaddr](https://learn.microsoft.com/en-us/windows/desktop/winsock/sockaddr-2) structure, is smaller than the sizeof(sockaddr).

Does this error belongs to socket or bind call?

alfredh commented 5 months ago

The error comes from calling udp_send.

The problem is that when calling udp_listen with local=NULL, it will not bind to a specific address or AF. Most of the time it binds to IPv6 socket.

Some platforms have the IPV6ONLY option enabled (e.g. MacOS, Windows, FreeBSD) so it will not work to send a packet to IPv4 host here.

alfredh commented 5 months ago

I am not sure its worth fixing this.

One option is to read the IPV6ONLY flag in case local=NULL.