]> arthur.barton.de Git - bup.git/commit
bup-web: handle 4 item getsockname() result for IPv6 sockets
authorChristian Brabandt <cb@256bit.org>
Tue, 29 Dec 2020 14:19:48 +0000 (15:19 +0100)
committerRob Browning <rlb@defaultvalue.org>
Thu, 31 Dec 2020 20:35:05 +0000 (14:35 -0600)
commit770082f40e64c1113d33b6d7e8beb12079e4e9b4
tree5e115c8d116f869590dbd654de2d1a40894174e8
parent13bada8e93ba38be4770fc3773d9569a759d775d
bup-web: handle 4 item getsockname() result for IPv6 sockets

So bup-web will create a new network socket to listen on for HTTP
connections and it may use either IPv4 or IPv6 (or both) addresses,
depending on the configuration of the system. This is done using the
tornado.netutil.bind_sockets().

Currently, bup-web does not restrict the address family to either
AF_INET/AF_INET6 and according to the documentation of
[tornado](https://www.tornadoweb.org/en/stable/netutil.html?highlight=netutil#tornado.netutil.bind_sockets)
it will use both address families and listen for connections on IPv4 and
IPv6 addresses.

> Family may be set to either socket.AF_INET or socket.AF_INET6 to
> restrict to IPv4 or IPv6 addresses, otherwise both will be used if
> available.

However, when your system has only IPv6 enabled, the print() statement
may fail with:

Traceback (most recent call last):
  File "/opt/bup/lib/bup/cmd/bup-web", line 310, in <module>
    print('Serving HTTP on %s:%d...' % sockets[0].getsockname())
TypeError: not all arguments converted during string formatting

For systems that have IPv4 as well as IPv6 enabled, it may or may not
fail, depending on whether the first returned socket by getsockname() is
for AF_INET6 or AF_INET4

The reason is, getsockname() for a AF_INET6 connections returns a tuple with
4 items: `(host, port, flowinfo, scope_id)`, while for AF_INET4
addresses, it contains only `(host, port)`.

Since we are only interested in the first 2 items, make sure to return
only the first 2 items, which are `host` and `port` for IPv4 (AF_INET)
and IPv6 (AF_INET6).

Signed-off-by: Christian Brabandt <cb@256bit.org>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
[rlb@defaultvalue.org: adjust commit summary]
lib/cmd/web-cmd.py