1 /*****************************************************************************
2 * posix/getaddrinfo.c: interruptible DNS resolution for POSIX
3 *****************************************************************************
4 * Copyright (C) 2016 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_interrupt.h>
31 #include <vlc_network.h>
37 const struct addrinfo
*hints
;
38 struct addrinfo
*result
;
43 static void *vlc_gai_thread(void *data
)
45 struct vlc_gai_req
*req
= data
;
47 req
->error
= EAI_SYSTEM
;
48 req
->error
= getaddrinfo(req
->name
, req
->service
, req
->hints
,
50 vlc_sem_post(&req
->done
);
54 int vlc_getaddrinfo_i11e(const char *name
, unsigned port
,
55 const struct addrinfo
*hints
,
56 struct addrinfo
**res
)
58 struct vlc_gai_req req
=
69 if ((size_t)snprintf(portbuf
, sizeof (portbuf
), "%u",
70 port
) >= sizeof (portbuf
))
73 req
.service
= portbuf
;
76 vlc_sem_init(&req
.done
, 0);
78 if (vlc_clone(&th
, vlc_gai_thread
, &req
, VLC_THREAD_PRIORITY_LOW
))
80 vlc_sem_destroy(&req
.done
);
84 vlc_sem_wait_i11e(&req
.done
);
88 vlc_sem_destroy(&req
.done
);