@@ -90,7 +90,8 @@ static void natural_mask(struct apattern *pat);
9090 !defined(ANDROID ) && !defined(__ANDROID__ ) && !defined(CARES_USE_LIBRESOLV )
9191static int config_domain (ares_channel channel , char * str );
9292static 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 );
9495static char * try_config (char * s , const char * opt , char scc );
9596#endif
9697
@@ -164,6 +165,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
164165 channel -> sock_state_cb_data = NULL ;
165166 channel -> sock_create_cb = NULL ;
166167 channel -> sock_create_cb_data = NULL ;
168+ channel -> sock_config_cb = NULL ;
169+ channel -> sock_config_cb_data = NULL ;
167170
168171 channel -> last_server = 0 ;
169172 channel -> last_timeout_processed = (time_t )now .tv_sec ;
@@ -291,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
291294 /* Now clone the options that ares_save_options() doesn't support. */
292295 (* dest )-> sock_create_cb = src -> sock_create_cb ;
293296 (* 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 ;
294299
295300 strncpy ((* dest )-> local_dev_name , src -> local_dev_name ,
296301 sizeof (src -> local_dev_name ));
@@ -1025,11 +1030,6 @@ static int get_DNS_AdaptersAddresses(char **outptr)
10251030 }
10261031 else if (namesrvr .sa -> sa_family == AF_INET6 )
10271032 {
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 ;
10331033 if (memcmp (& namesrvr .sa6 -> sin6_addr , & ares_in6addr_any ,
10341034 sizeof (namesrvr .sa6 -> sin6_addr )) == 0 )
10351035 continue ;
@@ -1269,7 +1269,7 @@ static int init_by_resolv_conf(ares_channel channel)
12691269 if ((p = try_config (line , "domain" , ';' )) && update_domains )
12701270 status = config_domain (channel , p );
12711271 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" );
12731273 else if ((p = try_config (line , "search" , ';' )) && update_domains )
12741274 status = set_search (channel , p );
12751275 else if ((p = try_config (line , "nameserver" , ';' )) &&
@@ -1310,8 +1310,7 @@ static int init_by_resolv_conf(ares_channel channel)
13101310 ARES_SUCCESS )
13111311 {
13121312 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" );
13151314 }
13161315 fclose (fp );
13171316 }
@@ -1320,15 +1319,16 @@ static int init_by_resolv_conf(ares_channel channel)
13201319 switch (error ) {
13211320 case ENOENT :
13221321 case ESRCH :
1323- status = ARES_EOF ;
13241322 break ;
13251323 default :
13261324 DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
13271325 error , strerror (error )));
13281326 DEBUGF (fprintf (stderr , "Error opening file: %s\n" ,
13291327 "/etc/nsswitch.conf" ));
1330- status = ARES_EFILE ;
13311328 }
1329+
1330+ /* ignore error, maybe we will get luck in next if clause */
1331+ status = ARES_EOF ;
13321332 }
13331333 }
13341334
@@ -1341,7 +1341,7 @@ static int init_by_resolv_conf(ares_channel channel)
13411341 {
13421342 if ((p = try_config (line , "order" , '\0' )) && !channel -> lookups )
13431343 /* ignore errors */
1344- (void )config_lookup (channel , p , "bind" , "hosts" );
1344+ (void )config_lookup (channel , p , "bind" , NULL , "hosts" );
13451345 }
13461346 fclose (fp );
13471347 }
@@ -1350,15 +1350,16 @@ static int init_by_resolv_conf(ares_channel channel)
13501350 switch (error ) {
13511351 case ENOENT :
13521352 case ESRCH :
1353- status = ARES_EOF ;
13541353 break ;
13551354 default :
13561355 DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
13571356 error , strerror (error )));
13581357 DEBUGF (fprintf (stderr , "Error opening file: %s\n" ,
13591358 "/etc/host.conf" ));
1360- status = ARES_EFILE ;
13611359 }
1360+
1361+ /* ignore error, maybe we will get luck in next if clause */
1362+ status = ARES_EOF ;
13621363 }
13631364 }
13641365
@@ -1371,7 +1372,7 @@ static int init_by_resolv_conf(ares_channel channel)
13711372 {
13721373 if ((p = try_config (line , "hosts=" , '\0' )) && !channel -> lookups )
13731374 /* ignore errors */
1374- (void )config_lookup (channel , p , "bind" , "local" );
1375+ (void )config_lookup (channel , p , "bind" , NULL , "local" );
13751376 }
13761377 fclose (fp );
13771378 }
@@ -1380,14 +1381,15 @@ static int init_by_resolv_conf(ares_channel channel)
13801381 switch (error ) {
13811382 case ENOENT :
13821383 case ESRCH :
1383- status = ARES_EOF ;
13841384 break ;
13851385 default :
13861386 DEBUGF (fprintf (stderr , "fopen() failed with error: %d %s\n" ,
13871387 error , strerror (error )));
13881388 DEBUGF (fprintf (stderr , "Error opening file: %s\n" , "/etc/svc.conf" ));
1389- status = ARES_EFILE ;
13901389 }
1390+
1391+ /* ignore error, default value will be chosen for `channel->lookups` */
1392+ status = ARES_EOF ;
13911393 }
13921394 }
13931395
@@ -1591,11 +1593,15 @@ static int config_domain(ares_channel channel, char *str)
15911593#endif
15921594
15931595static 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 )
15951598{
15961599 char lookups [3 ], * l ;
15971600 const char * vqualifier p ;
15981601
1602+ if (altbindch == NULL )
1603+ altbindch = bindch ;
1604+
15991605 /* Set the lookup order. Only the first letter of each work
16001606 * is relevant, and it has to be "b" for DNS or "f" for the
16011607 * host file. Ignore everything else.
@@ -1604,8 +1610,8 @@ static int config_lookup(ares_channel channel, const char *str,
16041610 p = str ;
16051611 while (* p )
16061612 {
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' ;
16091615 else * l ++ = 'f' ;
16101616 }
16111617 while (* p && !ISSPACE (* p ) && (* p != ',' ))
@@ -2090,6 +2096,14 @@ void ares_set_socket_callback(ares_channel channel,
20902096 channel -> sock_create_cb_data = data ;
20912097}
20922098
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+
20932107int ares_set_sortlist (ares_channel channel , const char * sortstr )
20942108{
20952109 int nsort = 0 ;
0 commit comments