Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmcurl/lib/hostip6.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
#include "curl_setup.h"
25
26
/***********************************************************************
27
 * Only for IPv6-enabled builds
28
 **********************************************************************/
29
#ifdef CURLRES_IPV6
30
31
#ifdef HAVE_NETINET_IN_H
32
#include <netinet/in.h>
33
#endif
34
#ifdef HAVE_NETDB_H
35
#include <netdb.h>
36
#endif
37
#ifdef HAVE_ARPA_INET_H
38
#include <arpa/inet.h>
39
#endif
40
#ifdef __VMS
41
#include <in.h>
42
#include <inet.h>
43
#endif
44
45
#include "urldata.h"
46
#include "cfilters.h"
47
#include "curl_addrinfo.h"
48
#include "curl_trc.h"
49
#include "hostip.h"
50
#include "url.h"
51
#include "curlx/inet_pton.h"
52
#include "connect.h"
53
54
#ifdef CURLRES_SYNCH
55
56
/*
57
 * Curl_sync_getaddrinfo() when built IPv6-enabled (non-threading and
58
 * non-ares version).
59
 *
60
 * Returns name information about the given hostname and port number. If
61
 * successful, the 'addrinfo' is returned and the fourth argument will point
62
 * to memory we need to free after use. That memory *MUST* be freed with
63
 * Curl_freeaddrinfo(), nothing else.
64
 */
65
struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data,
66
                                            uint8_t dns_queries,
67
                                            const char *hostname,
68
                                            uint16_t port,
69
                                            uint8_t transport)
70
0
{
71
0
  struct addrinfo hints;
72
0
  struct Curl_addrinfo *res;
73
0
  int error;
74
0
  char sbuf[12];
75
0
  char *sbufptr = NULL;
76
0
#ifndef USE_RESOLVE_ON_IPS
77
0
  char addrbuf[128];
78
0
#endif
79
0
  int pf = PF_INET;
80
81
0
  if(dns_queries & CURL_DNSQ_AAAA)
82
0
    pf = PF_UNSPEC;
83
84
0
  memset(&hints, 0, sizeof(hints));
85
0
  hints.ai_family = pf;
86
0
  hints.ai_socktype = (transport == TRNSPRT_TCP) ?
87
0
    SOCK_STREAM : SOCK_DGRAM;
88
89
0
#ifndef USE_RESOLVE_ON_IPS
90
  /*
91
   * The AI_NUMERICHOST must not be set to get synthesized IPv6 address from
92
   * an IPv4 address on iOS and macOS.
93
   */
94
0
  if((curlx_inet_pton(AF_INET, hostname, addrbuf) == 1) ||
95
0
     (curlx_inet_pton(AF_INET6, hostname, addrbuf) == 1)) {
96
    /* the given address is numerical only, prevent a reverse lookup */
97
0
    hints.ai_flags = AI_NUMERICHOST;
98
0
  }
99
0
#endif
100
101
0
  if(port) {
102
0
    curl_msnprintf(sbuf, sizeof(sbuf), "%d", port);
103
0
    sbufptr = sbuf;
104
0
  }
105
106
0
  error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &res);
107
0
  if(error) {
108
0
    infof(data, "getaddrinfo(3) failed for %s:%d", hostname, port);
109
0
    return NULL;
110
0
  }
111
112
0
  if(port) {
113
0
    Curl_addrinfo_set_port(res, port);
114
0
  }
115
116
0
  return res;
117
0
}
118
#endif /* CURLRES_SYNCH */
119
120
#endif /* CURLRES_IPV6 */