Use automatic server address if listen_on value is ''

This commit is contained in:
YOKOTA Hiroshi 2023-11-21 00:24:30 +09:00
parent dc4ba2e18b
commit 091404eb0d
4 changed files with 12 additions and 6 deletions

View File

@ -17,10 +17,10 @@ from calibre.utils.smtp import config as email_config
def local_url_for_content_server():
from calibre.srv.opts import server_config
from calibre.utils.network import is_ipv6_addr
from calibre.utils.network import is_ipv6_addr, get_fallback_server_addr
opts = server_config()
interface = opts.listen_on or '0.0.0.0'
interface = opts.listen_on or get_fallback_server_addr()
addr_map = {'0.0.0.0': '127.0.0.1',
'::': '::1'}

View File

@ -1299,11 +1299,11 @@ class ConfigWidget(ConfigWidgetBase):
self.stopping_msg.accept()
def test_server(self):
from calibre.utils.network import is_ipv6_addr
from calibre.utils.network import is_ipv6_addr, get_fallback_server_addr
prefix = self.advanced_tab.get('url_prefix') or ''
protocol = 'https' if self.advanced_tab.has_ssl else 'http'
lo = self.advanced_tab.get('listen_on') or '0.0.0.0'
lo = self.advanced_tab.get('listen_on') or get_fallback_server_addr()
addr_map = {'0.0.0.0': '127.0.0.1',
'::': '::1'}

View File

@ -11,7 +11,6 @@ from collections import OrderedDict, namedtuple
from functools import partial
from itertools import zip_longest
from operator import attrgetter
from socket import has_dualstack_ipv6
from calibre.constants import config_dir
from calibre.utils.localization import _
@ -111,7 +110,7 @@ raw_options = (
' there are more than this number of items. Set to zero to disable.'),
_('The interface on which to listen for connections'),
'listen_on', '::' if has_dualstack_ipv6() else '0.0.0.0',
'listen_on', '',
_('The default is to listen on all available IPv6 and IPv4 interfaces. You can change this to, for'
' example, "127.0.0.1" to only listen for connections from the local machine, or'
' to "::" to listen to all incoming IPv6 and IPv4 connections.'),

View File

@ -116,3 +116,10 @@ def is_ipv6_addr(addr):
return True
except OSError:
return False
def get_fallback_server_addr():
from socket import has_dualstack_ipv6
if has_dualstack_ipv6():
return '::'
else:
return '0.0.0.0'