File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ cfg_if::cfg_if! {
6262const HTTP_SERVER_DEFAULT_PASSWORD : & str = "password" ;
6363const HTTP_SERVER_DEFAULT_USERNAME : & str = "admin" ;
6464const HTTP_SERVER_DEFAULT_WWW_ROOT : & str = "/usr/share/smartdns/wwwroot" ;
65- const HTTP_SERVER_DEFAULT_IP : & str = "http://[::]:6080" ;
65+ const HTTP_SERVER_DEFAULT_IPV6 : & str = "http://[::]:6080" ;
66+ const HTTP_SERVER_DEFAULT_IP : & str = "http://0.0.0.0:6080" ;
6667
6768#[ derive( Clone ) ]
6869pub struct HttpServerConfig {
@@ -77,8 +78,15 @@ pub struct HttpServerConfig {
7778
7879impl HttpServerConfig {
7980 pub fn new ( ) -> Self {
81+
82+ let host_ip = if utils:: is_ipv6_supported ( ) {
83+ HTTP_SERVER_DEFAULT_IPV6 . to_string ( )
84+ } else {
85+ HTTP_SERVER_DEFAULT_IP . to_string ( )
86+ } ;
87+
8088 HttpServerConfig {
81- http_ip : HTTP_SERVER_DEFAULT_IP . to_string ( ) ,
89+ http_ip : host_ip ,
8290 http_root : HTTP_SERVER_DEFAULT_WWW_ROOT . to_string ( ) ,
8391 username : HTTP_SERVER_DEFAULT_USERNAME . to_string ( ) ,
8492 password : utils:: hash_password ( HTTP_SERVER_DEFAULT_PASSWORD , Some ( 1000 ) ) . unwrap ( ) ,
Original file line number Diff line number Diff line change @@ -97,3 +97,12 @@ pub fn is_dir_writable(path: &str) -> bool {
9797 let path = std:: ffi:: CString :: new ( path) . unwrap ( ) ;
9898 unsafe { libc:: access ( path. as_ptr ( ) , libc:: W_OK ) == 0 }
9999}
100+
101+ pub fn is_ipv6_supported ( ) -> bool {
102+ let sock = unsafe { libc:: socket ( libc:: AF_INET6 , libc:: SOCK_STREAM , 0 ) } ;
103+ if sock < 0 {
104+ return false ;
105+ }
106+ unsafe { libc:: close ( sock) } ;
107+ true
108+ }
You can’t perform that action at this time.
0 commit comments