@@ -90,7 +90,8 @@ static void natural_mask(struct apattern *pat);
90
90
!defined(ANDROID ) && !defined(__ANDROID__ ) && !defined(CARES_USE_LIBRESOLV )
91
91
static int config_domain (ares_channel channel , char * str );
92
92
static int config_lookup (ares_channel channel , const char * str ,
93
- const char * bindch , const char * filech );
93
+ const char * bindch , const char * altbindch ,
94
+ const char * filech );
94
95
static char * try_config (char * s , const char * opt , char scc );
95
96
#endif
96
97
@@ -164,6 +165,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
164
165
channel -> sock_state_cb_data = NULL ;
165
166
channel -> sock_create_cb = NULL ;
166
167
channel -> sock_create_cb_data = NULL ;
168
+ channel -> sock_config_cb = NULL ;
169
+ channel -> sock_config_cb_data = NULL ;
167
170
168
171
channel -> last_server = 0 ;
169
172
channel -> last_timeout_processed = (time_t )now .tv_sec ;
@@ -291,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
291
294
/* Now clone the options that ares_save_options() doesn't support. */
292
295
(* dest )-> sock_create_cb = src -> sock_create_cb ;
293
296
(* dest )-> sock_create_cb_data = src -> sock_create_cb_data ;
297
+ (* dest )-> sock_config_cb = src -> sock_config_cb ;
298
+ (* dest )-> sock_config_cb_data = src -> sock_config_cb_data ;
294
299
295
300
strncpy ((* dest )-> local_dev_name , src -> local_dev_name ,
296
301
sizeof (src -> local_dev_name ));
@@ -1025,11 +1030,6 @@ static int get_DNS_AdaptersAddresses(char **outptr)
1025
1030
}
1026
1031
else if (namesrvr .sa -> sa_family == AF_INET6 )
1027
1032
{
1028
- /* Windows apparently always reports some IPv6 DNS servers that
1029
- * prefixed with fec0:0:0:ffff. These ususally do not point to
1030
- * working DNS servers, so we ignore them. */
1031
- if (strncmp (txtaddr , "fec0:0:0:ffff:" , 14 ) == 0 )
1032
- continue ;
1033
1033
if (memcmp (& namesrvr .sa6 -> sin6_addr , & ares_in6addr_any ,
1034
1034
sizeof (namesrvr .sa6 -> sin6_addr )) == 0 )
1035
1035
continue ;
@@ -1269,7 +1269,7 @@ static int init_by_resolv_conf(ares_channel channel)
1269
1269
if ((p = try_config (line , "domain" , ';' )) && update_domains )
1270
1270
status = config_domain (channel , p );
1271
1271
else if ((p = try_config (line , "lookup" , ';' )) && !channel -> lookups )
1272
- status = config_lookup (channel , p , "bind" , "file" );
1272
+ status = config_lookup (channel , p , "bind" , NULL , "file" );
1273
1273
else if ((p = try_config (line , "search" , ';' )) && update_domains )
1274
1274
status = set_search (channel , p );
1275
1275
else if ((p = try_config (line , "nameserver" , ';' )) &&
@@ -1310,8 +1310,7 @@ static int init_by_resolv_conf(ares_channel channel)
1310
1310
ARES_SUCCESS )
1311
1311
{
1312
1312
if ((p = try_config (line , "hosts:" , '\0' )) && !channel -> lookups )
1313
- /* ignore errors */
1314
- (void )config_lookup (channel , p , "dns" , "files" );
1313
+ (void )config_lookup (channel , p , "dns" , "resolve" , "files" );
1315
1314
}
1316
1315
fclose (fp );
1317
1316
}
@@ -1320,15 +1319,16 @@ static int init_by_resolv_conf(ares_channel channel)
1320
1319
switch (error ) {
1321
1320
case ENOENT :
1322
1321
case ESRCH :
1323
- status = ARES_EOF ;
1324
1322
break ;
1325
1323
default :
1326
1324
DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
1327
1325
error , strerror (error )));
1328
1326
DEBUGF (fprintf (stderr , "Error opening file: %s\n" ,
1329
1327
"/etc/nsswitch.conf" ));
1330
- status = ARES_EFILE ;
1331
1328
}
1329
+
1330
+ /* ignore error, maybe we will get luck in next if clause */
1331
+ status = ARES_EOF ;
1332
1332
}
1333
1333
}
1334
1334
@@ -1341,7 +1341,7 @@ static int init_by_resolv_conf(ares_channel channel)
1341
1341
{
1342
1342
if ((p = try_config (line , "order" , '\0' )) && !channel -> lookups )
1343
1343
/* ignore errors */
1344
- (void )config_lookup (channel , p , "bind" , "hosts" );
1344
+ (void )config_lookup (channel , p , "bind" , NULL , "hosts" );
1345
1345
}
1346
1346
fclose (fp );
1347
1347
}
@@ -1350,15 +1350,16 @@ static int init_by_resolv_conf(ares_channel channel)
1350
1350
switch (error ) {
1351
1351
case ENOENT :
1352
1352
case ESRCH :
1353
- status = ARES_EOF ;
1354
1353
break ;
1355
1354
default :
1356
1355
DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
1357
1356
error , strerror (error )));
1358
1357
DEBUGF (fprintf (stderr , "Error opening file: %s\n" ,
1359
1358
"/etc/host.conf" ));
1360
- status = ARES_EFILE ;
1361
1359
}
1360
+
1361
+ /* ignore error, maybe we will get luck in next if clause */
1362
+ status = ARES_EOF ;
1362
1363
}
1363
1364
}
1364
1365
@@ -1371,7 +1372,7 @@ static int init_by_resolv_conf(ares_channel channel)
1371
1372
{
1372
1373
if ((p = try_config (line , "hosts=" , '\0' )) && !channel -> lookups )
1373
1374
/* ignore errors */
1374
- (void )config_lookup (channel , p , "bind" , "local" );
1375
+ (void )config_lookup (channel , p , "bind" , NULL , "local" );
1375
1376
}
1376
1377
fclose (fp );
1377
1378
}
@@ -1380,14 +1381,15 @@ static int init_by_resolv_conf(ares_channel channel)
1380
1381
switch (error ) {
1381
1382
case ENOENT :
1382
1383
case ESRCH :
1383
- status = ARES_EOF ;
1384
1384
break ;
1385
1385
default :
1386
1386
DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
1387
1387
error , strerror (error )));
1388
1388
DEBUGF (fprintf (stderr , "Error opening file: %s\n" , "/etc/svc.conf" ));
1389
- status = ARES_EFILE ;
1390
1389
}
1390
+
1391
+ /* ignore error, default value will be chosen for `channel->lookups` */
1392
+ status = ARES_EOF ;
1391
1393
}
1392
1394
}
1393
1395
@@ -1591,11 +1593,15 @@ static int config_domain(ares_channel channel, char *str)
1591
1593
#endif
1592
1594
1593
1595
static int config_lookup (ares_channel channel , const char * str ,
1594
- const char * bindch , const char * filech )
1596
+ const char * bindch , const char * altbindch ,
1597
+ const char * filech )
1595
1598
{
1596
1599
char lookups [3 ], * l ;
1597
1600
const char * vqualifier p ;
1598
1601
1602
+ if (altbindch == NULL )
1603
+ altbindch = bindch ;
1604
+
1599
1605
/* Set the lookup order. Only the first letter of each work
1600
1606
* is relevant, and it has to be "b" for DNS or "f" for the
1601
1607
* host file. Ignore everything else.
@@ -1604,8 +1610,8 @@ static int config_lookup(ares_channel channel, const char *str,
1604
1610
p = str ;
1605
1611
while (* p )
1606
1612
{
1607
- if ((* p == * bindch || * p == * filech ) && l < lookups + 2 ) {
1608
- if (* p == * bindch ) * l ++ = 'b' ;
1613
+ if ((* p == * bindch || * p == * altbindch || * p == * filech ) && l < lookups + 2 ) {
1614
+ if (* p == * bindch || * p == * altbindch ) * l ++ = 'b' ;
1609
1615
else * l ++ = 'f' ;
1610
1616
}
1611
1617
while (* p && !ISSPACE (* p ) && (* p != ',' ))
@@ -2090,6 +2096,14 @@ void ares_set_socket_callback(ares_channel channel,
2090
2096
channel -> sock_create_cb_data = data ;
2091
2097
}
2092
2098
2099
+ void ares_set_socket_configure_callback (ares_channel channel ,
2100
+ ares_sock_config_callback cb ,
2101
+ void * data )
2102
+ {
2103
+ channel -> sock_config_cb = cb ;
2104
+ channel -> sock_config_cb_data = data ;
2105
+ }
2106
+
2093
2107
int ares_set_sortlist (ares_channel channel , const char * sortstr )
2094
2108
{
2095
2109
int nsort = 0 ;
0 commit comments