Line data Source code
1 : #include "fd_netdb.h" 2 : #include "fd_lookup.h" 3 : #include <errno.h> 4 : #include <fcntl.h> 5 : #include "../../util/log/fd_log.h" 6 : #include "../../util/io/fd_io.h" 7 : 8 : FD_TL int fd_etc_hosts_fd = -1; 9 : FD_TL int fd_etc_resolv_conf_fd = -1; 10 : 11 : fd_netdb_fds_t * 12 0 : fd_netdb_open_fds( fd_netdb_fds_t * fds ) { 13 0 : if( FD_UNLIKELY( fd_etc_hosts_fd>=0 || fd_etc_resolv_conf_fd>=0 ) ) { 14 0 : return NULL; 15 0 : } 16 : 17 0 : int f = open( "/etc/resolv.conf", O_RDONLY ); 18 0 : if( FD_UNLIKELY( f<0 ) ) { 19 0 : FD_LOG_ERR(( "open(/etc/resolv.conf) failed (%i-%s)", errno, fd_io_strerror( errno ) )); 20 0 : } 21 0 : fd_etc_resolv_conf_fd = f; 22 : 23 0 : f = open( "/etc/hosts", O_RDONLY ); 24 0 : if( FD_UNLIKELY( f<0 ) ) { 25 0 : FD_LOG_WARNING(( "open(/etc/hosts) failed (%i-%s)", errno, fd_io_strerror( errno ) )); 26 0 : } else { 27 0 : fd_etc_hosts_fd = f; 28 0 : } 29 : 30 0 : if( fds ) { 31 0 : *fds = (fd_netdb_fds_t) { 32 0 : .etc_resolv_conf = fd_etc_resolv_conf_fd, 33 0 : .etc_hosts = fd_etc_hosts_fd 34 0 : }; 35 0 : } 36 0 : return fds; 37 0 : }