demux: mp4: set bitmap mask when possible
[vlc.git] / src / posix / getaddrinfo.c
blob4863beada4f09c92cc6a472f7fa122f2c05efeeb
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <assert.h>
26 #include <stdio.h>
27 #include <netdb.h>
29 #include <vlc_common.h>
30 #include <vlc_interrupt.h>
31 #include <vlc_network.h>
33 struct vlc_gai_req
35 const char *name;
36 const char *service;
37 const struct addrinfo *hints;
38 struct addrinfo *result;
39 int error;
40 vlc_sem_t done;
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,
49 &req->result);
50 vlc_sem_post(&req->done);
51 return NULL;
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 =
60 .name = name,
61 .service = NULL,
62 .hints = hints,
64 char portbuf[6];
65 vlc_thread_t th;
67 if (port != 0)
69 if ((size_t)snprintf(portbuf, sizeof (portbuf), "%u",
70 port) >= sizeof (portbuf))
71 return EAI_NONAME;
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);
81 return EAI_SYSTEM;
84 vlc_sem_wait_i11e(&req.done);
86 vlc_cancel(th);
87 vlc_join(th, NULL);
88 vlc_sem_destroy(&req.done);
90 *res = req.result;
91 return req.error;