Skip to content

Commit e8b7e6a

Browse files
indutnyrvagg
authored andcommitted
deps: sync with upstream c-ares/c-ares@2bae2d5
PR-URL: #5090 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
1 parent e55dea9 commit e8b7e6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+958
-451
lines changed

deps/cares/include/ares.h

+44-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define ARES__H
2020

2121
#include "ares_version.h" /* c-ares version defines */
22+
#include "ares_build.h" /* c-ares build definitions */
23+
#include "ares_rules.h" /* c-ares rules enforcement */
2224

2325
/*
2426
* Define WIN32 when build target is Win32 API
@@ -29,9 +31,6 @@
2931
# define WIN32
3032
#endif
3133

32-
/* Data type definition of ares_socklen_t. */
33-
typedef unsigned ares_socklen_t;
34-
3534
#include <sys/types.h>
3635

3736
/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
@@ -297,6 +296,13 @@ typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
297296

298297
CARES_EXTERN int ares_library_init(int flags);
299298

299+
CARES_EXTERN int ares_library_init_mem(int flags,
300+
void *(*amalloc)(size_t size),
301+
void (*afree)(void *ptr),
302+
void *(*arealloc)(void *ptr, size_t size));
303+
304+
CARES_EXTERN int ares_library_initialized(void);
305+
300306
CARES_EXTERN void ares_library_cleanup(void);
301307

302308
CARES_EXTERN const char *ares_version(int *version);
@@ -338,6 +344,9 @@ CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
338344
ares_sock_create_callback callback,
339345
void *user_data);
340346

347+
CARES_EXTERN int ares_set_sortlist(ares_channel channel,
348+
const char *sortstr);
349+
341350
CARES_EXTERN void ares_send(ares_channel channel,
342351
const unsigned char *qbuf,
343352
int qlen,
@@ -473,8 +482,17 @@ struct ares_txt_reply {
473482
struct ares_txt_reply *next;
474483
unsigned char *txt;
475484
size_t length; /* length excludes null termination */
476-
unsigned char record_start; /* 1 - if start of new record
477-
* 0 - if a chunk in the same record */
485+
};
486+
487+
/* NOTE: This structure is a superset of ares_txt_reply
488+
*/
489+
struct ares_txt_ext {
490+
struct ares_txt_ext *next;
491+
unsigned char *txt;
492+
size_t length;
493+
/* 1 - if start of new record
494+
* 0 - if a chunk in the same record */
495+
unsigned char record_start;
478496
};
479497

480498
struct ares_naptr_reply {
@@ -540,6 +558,10 @@ CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
540558
int alen,
541559
struct ares_txt_reply** txt_out);
542560

561+
CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf,
562+
int alen,
563+
struct ares_txt_ext** txt_out);
564+
543565
CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
544566
int alen,
545567
struct ares_naptr_reply** naptr_out);
@@ -556,7 +578,6 @@ CARES_EXTERN void ares_free_data(void *dataptr);
556578

557579
CARES_EXTERN const char *ares_strerror(int code);
558580

559-
/* TODO: Hold port here as well. */
560581
struct ares_addr_node {
561582
struct ares_addr_node *next;
562583
int family;
@@ -566,15 +587,32 @@ struct ares_addr_node {
566587
} addr;
567588
};
568589

590+
struct ares_addr_port_node {
591+
struct ares_addr_port_node *next;
592+
int family;
593+
union {
594+
struct in_addr addr4;
595+
struct ares_in6_addr addr6;
596+
} addr;
597+
int udp_port;
598+
int tcp_port;
599+
};
600+
569601
CARES_EXTERN int ares_set_servers(ares_channel channel,
570602
struct ares_addr_node *servers);
603+
CARES_EXTERN int ares_set_servers_ports(ares_channel channel,
604+
struct ares_addr_port_node *servers);
571605

572606
/* Incomming string format: host[:port][,host[:port]]... */
573607
CARES_EXTERN int ares_set_servers_csv(ares_channel channel,
574608
const char* servers);
609+
CARES_EXTERN int ares_set_servers_ports_csv(ares_channel channel,
610+
const char* servers);
575611

576612
CARES_EXTERN int ares_get_servers(ares_channel channel,
577613
struct ares_addr_node **servers);
614+
CARES_EXTERN int ares_get_servers_ports(ares_channel channel,
615+
struct ares_addr_port_node **servers);
578616

579617
CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst,
580618
ares_socklen_t size);

deps/cares/include/ares_build.h

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* ares_build.h. Generated from ares_build.h.in by configure. */
2+
#ifndef __CARES_BUILD_H
3+
#define __CARES_BUILD_H
4+
5+
6+
/* Copyright (C) 2009 by Daniel Stenberg et al
7+
*
8+
* Permission to use, copy, modify, and distribute this software and its
9+
* documentation for any purpose and without fee is hereby granted, provided
10+
* that the above copyright notice appear in all copies and that both that
11+
* copyright notice and this permission notice appear in supporting
12+
* documentation, and that the name of M.I.T. not be used in advertising or
13+
* publicity pertaining to distribution of the software without specific,
14+
* written prior permission. M.I.T. makes no representations about the
15+
* suitability of this software for any purpose. It is provided "as is"
16+
* without express or implied warranty.
17+
*/
18+
19+
/* ================================================================ */
20+
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
21+
/* ================================================================ */
22+
23+
/*
24+
* NOTE 1:
25+
* -------
26+
*
27+
* Nothing in this file is intended to be modified or adjusted by the
28+
* c-ares library user nor by the c-ares library builder.
29+
*
30+
* If you think that something actually needs to be changed, adjusted
31+
* or fixed in this file, then, report it on the c-ares development
32+
* mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
33+
*
34+
* This header file shall only export symbols which are 'cares' or 'CARES'
35+
* prefixed, otherwise public name space would be polluted.
36+
*
37+
* NOTE 2:
38+
* -------
39+
*
40+
* Right now you might be staring at file ares_build.h.in or ares_build.h,
41+
* this is due to the following reason:
42+
*
43+
* On systems capable of running the configure script, the configure process
44+
* will overwrite the distributed ares_build.h file with one that is suitable
45+
* and specific to the library being configured and built, which is generated
46+
* from the ares_build.h.in template file.
47+
*
48+
*/
49+
50+
/* ================================================================ */
51+
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
52+
/* ================================================================ */
53+
54+
#ifdef CARES_SIZEOF_LONG
55+
# error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
56+
Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
57+
#endif
58+
59+
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
60+
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
61+
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
62+
#endif
63+
64+
#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
65+
# error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
66+
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
67+
#endif
68+
69+
/* ================================================================ */
70+
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
71+
/* ================================================================ */
72+
73+
/* Configure process defines this to 1 when it finds out that system */
74+
/* header file ws2tcpip.h must be included by the external interface. */
75+
76+
#ifdef WIN32
77+
# define CARES_PULL_WS2TCPIP_H 1
78+
#else
79+
# define CARES_PULL_SYS_TYPES_H 1
80+
# define CARES_PULL_SYS_SOCKET_H 1
81+
#endif
82+
83+
/* #undef CARES_PULL_WS2TCPIP_H */
84+
#ifdef CARES_PULL_WS2TCPIP_H
85+
# ifndef WIN32_LEAN_AND_MEAN
86+
# define WIN32_LEAN_AND_MEAN
87+
# endif
88+
# include <windows.h>
89+
# include <winsock2.h>
90+
# include <ws2tcpip.h>
91+
#endif
92+
93+
/* Configure process defines this to 1 when it finds out that system */
94+
/* header file sys/types.h must be included by the external interface. */
95+
#ifdef CARES_PULL_SYS_TYPES_H
96+
# include <sys/types.h>
97+
#endif
98+
99+
/* Configure process defines this to 1 when it finds out that system */
100+
/* header file sys/socket.h must be included by the external interface. */
101+
#ifdef CARES_PULL_SYS_SOCKET_H
102+
# include <sys/socket.h>
103+
#endif
104+
105+
/* The size of `long', as computed by sizeof. */
106+
/* #undef CARES_SIZEOF_LONG */
107+
108+
/* Integral data type used for ares_socklen_t. */
109+
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
110+
111+
/* The size of `ares_socklen_t', as computed by sizeof. */
112+
#define CARES_SIZEOF_ARES_SOCKLEN_T 4
113+
114+
/* Data type definition of ares_socklen_t. */
115+
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
116+
117+
#endif /* __CARES_BUILD_H */
File renamed without changes.

deps/cares/src/ares__close_sockets.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ void ares__close_sockets(ares_channel channel, struct server_state *server)
3030
sendreq = server->qhead;
3131
server->qhead = sendreq->next;
3232
if (sendreq->data_storage != NULL)
33-
free(sendreq->data_storage);
34-
free(sendreq);
33+
ares_free(sendreq->data_storage);
34+
ares_free(sendreq);
3535
}
3636
server->qtail = NULL;
3737

3838
/* Reset any existing input buffer. */
3939
if (server->tcp_buffer)
40-
free(server->tcp_buffer);
40+
ares_free(server->tcp_buffer);
4141
server->tcp_buffer = NULL;
4242
server->tcp_lenbuf_pos = 0;
4343

deps/cares/src/ares__get_hostent.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
9494
p++;
9595
if (!*p)
9696
/* Ignore line if reached end of line. */
97-
continue;
97+
continue; /* LCOV_EXCL_LINE: trailing whitespace already stripped */
9898

9999
/* Pointer to start of host name. */
100100
txthost = p;
@@ -164,7 +164,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
164164
*/
165165

166166
/* Allocate memory for the hostent structure. */
167-
hostent = malloc(sizeof(struct hostent));
167+
hostent = ares_malloc(sizeof(struct hostent));
168168
if (!hostent)
169169
break;
170170

@@ -173,16 +173,16 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
173173
hostent->h_addr_list = NULL;
174174

175175
/* Copy official host name. */
176-
hostent->h_name = strdup(txthost);
176+
hostent->h_name = ares_strdup(txthost);
177177
if (!hostent->h_name)
178178
break;
179179

180180
/* Copy network address. */
181-
hostent->h_addr_list = malloc(2 * sizeof(char *));
181+
hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
182182
if (!hostent->h_addr_list)
183183
break;
184184
hostent->h_addr_list[1] = NULL;
185-
hostent->h_addr_list[0] = malloc(addrlen);
185+
hostent->h_addr_list[0] = ares_malloc(addrlen);
186186
if (!hostent->h_addr_list[0])
187187
break;
188188
if (addr.family == AF_INET)
@@ -191,7 +191,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
191191
memcpy(hostent->h_addr_list[0], &addr.addrV6, sizeof(addr.addrV6));
192192

193193
/* Copy aliases. */
194-
hostent->h_aliases = malloc((naliases + 1) * sizeof(char *));
194+
hostent->h_aliases = ares_malloc((naliases + 1) * sizeof(char *));
195195
if (!hostent->h_aliases)
196196
break;
197197
alias = hostent->h_aliases;
@@ -207,7 +207,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
207207
while (*q && ISSPACE(*q))
208208
q++;
209209
*p = '\0';
210-
if ((*alias = strdup(txtalias)) == NULL)
210+
if ((*alias = ares_strdup(txtalias)) == NULL)
211211
break;
212212
alias++;
213213
txtalias = *q ? q : NULL;
@@ -221,7 +221,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
221221
hostent->h_length = aresx_uztoss(addrlen);
222222

223223
/* Free line buffer. */
224-
free(line);
224+
ares_free(line);
225225

226226
/* Return hostent successfully */
227227
*host = hostent;
@@ -231,28 +231,28 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
231231

232232
/* If allocated, free line buffer. */
233233
if (line)
234-
free(line);
234+
ares_free(line);
235235

236236
if (status == ARES_SUCCESS)
237237
{
238238
/* Memory allocation failure; clean up. */
239239
if (hostent)
240240
{
241241
if (hostent->h_name)
242-
free((char *) hostent->h_name);
242+
ares_free((char *) hostent->h_name);
243243
if (hostent->h_aliases)
244244
{
245245
for (alias = hostent->h_aliases; *alias; alias++)
246-
free(*alias);
247-
free(hostent->h_aliases);
246+
ares_free(*alias);
247+
ares_free(hostent->h_aliases);
248248
}
249249
if (hostent->h_addr_list)
250250
{
251251
if (hostent->h_addr_list[0])
252-
free(hostent->h_addr_list[0]);
253-
free(hostent->h_addr_list);
252+
ares_free(hostent->h_addr_list[0]);
253+
ares_free(hostent->h_addr_list);
254254
}
255-
free(hostent);
255+
ares_free(hostent);
256256
}
257257
return ARES_ENOMEM;
258258
}

deps/cares/src/ares__read_line.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
3636

3737
if (*buf == NULL)
3838
{
39-
*buf = malloc(128);
39+
*buf = ares_malloc(128);
4040
if (!*buf)
4141
return ARES_ENOMEM;
4242
*bufsize = 128;
@@ -59,10 +59,11 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
5959
continue;
6060

6161
/* Allocate more space. */
62-
newbuf = realloc(*buf, *bufsize * 2);
62+
newbuf = ares_realloc(*buf, *bufsize * 2);
6363
if (!newbuf)
6464
{
65-
free(*buf);
65+
ares_free(*buf);
66+
*buf = NULL;
6667
return ARES_ENOMEM;
6768
}
6869
*buf = newbuf;

deps/cares/src/ares__timeval.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct timeval ares__tvnow(void)
5656
*/
5757
#ifdef HAVE_GETTIMEOFDAY
5858
else
59-
(void)gettimeofday(&now, NULL);
59+
(void)gettimeofday(&now, NULL); /* LCOV_EXCL_LINE */
6060
#else
6161
else {
6262
now.tv_sec = (long)time(NULL);

deps/cares/src/ares_create_query.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
130130
return ARES_EBADNAME;
131131

132132
*buflen = len + HFIXEDSZ + QFIXEDSZ + (max_udp_size ? EDNSFIXEDSZ : 0);
133-
*buf = malloc(*buflen);
133+
*buf = ares_malloc(*buflen);
134134
if (!*buf)
135135
return ARES_ENOMEM;
136136

0 commit comments

Comments
 (0)