-
Notifications
You must be signed in to change notification settings - Fork 84
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
sip/transp: add win32 local transport addr fallback #1001
Conversation
@cspiel1 on windows https://github.com/baresip/re/blob/main/src/sip/transp.c#L795-L796 (btw. looks like connh err is ignored and overriden by secure path).
https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname |
/**
* Get local network address of TCP Connection
*
* @param tc TCP Connection
* @param local Returned local network address
*
* @return 0 if success, otherwise errorcode
*/
int tcp_conn_local_get(const struct tcp_conn *tc, struct sa *local)
{
int err;
if (!tc || !local)
return EINVAL;
sa_init(local, AF_UNSPEC);
err = getsockname(tc->fdc, &local->u.sa, &local->len);
if (err < 0) {
err = RE_ERRNO_SOCK;
DEBUG_WARNING("conn local get: getsockname(): %m\n", err);
}
return err;
} This only works if the TCP connection is "connected". |
01d3908
to
82c456c
Compare
tcp_conn_local_get function does not always return information about the host address when the socket has been bound to an unspecified address. fixes baresip/baresip#2797
So, this PR is only a workaround where a fallback address is assigned? Should we add some kind of wait condition for the TCP connection? |
Looks like pjsip does a similiar fallback, so not sure if there is a reliable way (other than waiting for tcp_estab_handler): /* Update (again) local address, just in case local address currently
* set is different now that asynchronous connect() is started.
*/
addr_len = sizeof(local_addr);
if (pj_sock_getsockname(sock, &local_addr, &addr_len)==PJ_SUCCESS) {
pj_sockaddr *tp_addr = &tcp->base.local_addr;
/* Some systems (like old Win32 perhaps) may not set local address
* properly before socket is fully connected.
*/
if (pj_sockaddr_cmp(tp_addr, &local_addr) &&
pj_sockaddr_has_addr(&local_addr) &&
pj_sockaddr_get_port(&local_addr) != 0)
{
pj_sockaddr_cp(tp_addr, &local_addr);
sockaddr_to_host_port(tcp->base.pool, &tcp->base.local_name,
&local_addr);
}
} |
tcp_conn_local_get
function does not always return information about the host address when the socket has been bound to an unspecified address.fixes baresip/baresip#2797