Coverage Report

Created: 2026-08-13 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/src/posix/getaddrinfo.c
Line
Count
Source
1
/*****************************************************************************
2
 * posix/getaddrinfo.c: interruptible DNS resolution for POSIX
3
 *****************************************************************************
4
 * Copyright (C) 2016 Rémi Denis-Courmont
5
 *
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.
10
 *
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.
15
 *
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
 *****************************************************************************/
20
21
#ifdef HAVE_CONFIG_H
22
# include "config.h"
23
#endif
24
25
#include <assert.h>
26
#include <stdio.h>
27
#include <netdb.h>
28
29
#include <vlc_common.h>
30
#include <vlc_interrupt.h>
31
#include <vlc_network.h>
32
33
struct vlc_gai_req
34
{
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;
41
};
42
43
static void *vlc_gai_thread(void *data)
44
{
45
    vlc_thread_set_name("vlc-getaddrinfo");
46
47
    struct vlc_gai_req *req = data;
48
49
    req->error = EAI_SYSTEM;
50
    req->error = getaddrinfo(req->name, req->service, req->hints, req->result);
51
    vlc_sem_post(&req->done);
52
    return NULL;
53
}
54
55
int vlc_getaddrinfo_i11e(const char *name, unsigned port,
56
                         const struct addrinfo *hints,
57
                         struct addrinfo **res)
58
0
{
59
0
    struct vlc_gai_req req =
60
0
    {
61
0
        .name = name,
62
0
        .service = NULL,
63
0
        .hints = hints,
64
0
        .result = res,
65
0
    };
66
0
    char portbuf[6];
67
0
    vlc_thread_t th;
68
69
0
    if (port != 0)
70
0
    {
71
0
        if ((size_t)snprintf(portbuf, sizeof (portbuf), "%u",
72
0
                             port) >= sizeof (portbuf))
73
0
            return EAI_NONAME;
74
75
0
        req.service = portbuf;
76
0
    }
77
78
0
    vlc_sem_init(&req.done, 0);
79
80
0
    if (vlc_clone(&th, vlc_gai_thread, &req))
81
0
        return EAI_SYSTEM;
82
83
0
    vlc_sem_wait_i11e(&req.done);
84
85
0
    vlc_cancel(th);
86
0
    vlc_join(th, NULL);
87
88
0
    return req.error;
89
0
}