Add --resolve=HOST:IP option to override hostname DNS resolution

Motivation: to use wget spider mode in CI pipeline with overriding the hostname DNS resolution without changes to /etc/hosts. --resolve is inspired with a similar option in curl (which cannot be used for the same purpose due to lack of spider mode).

Example of usage: wget --resolve=domain.com:127.0.0.1 --spider -r -nd -nv domain.com/

I do appreciate any suggestion on improving this patch.

Note: Due to the possibility to disable IPv6 with a preprocessor flag, this patch has to support the case with IPv4 only addresses parsing.

Below is a commit message:

* src/host.c: add a pair of functions to parse IP v4/6 address to
  address_list, and a function to store mapping hostname to address
  in cache. Due to possibility to compile without IPv6 support there's
  a need to have separate address parsing implementations for IP v4/v6.
  (cache_host_ip): parse address and call cache_store to save mapping
  (parse_ipv6_address_list): validate ip with is_valid_ipv6_address
  and is_valid_ipv4_address, then parse it with inet_pton. Return
  address_list.
  (parse_ipv4_address_list): check if the address is IPv4 and
  parse it with inet_aton. Return address_list.
* src/host.h: Prototype for cache_host_ip.
* src/init.c: Add new commandline option --resolve=HOST:IP.
  (struct host_ip): store a pair host and ip.
  (split_host_ip): split HOST:IP string to host_ip struct.
  (cmd_spec_resolve_host): call cache_host_ip or display error.
  (test_resolve_argument_parse): unit test for parsing --resolve
  arguments.
* src/main.c: add --resolve option with its metainfo in option_data
  and display an error when DNS cache is disabled at the same time
  when --resolve is specified.
  (print_help): add help on --resolve
  (main): display an error and exit when dns cache is disabled and
  --resolve is specified at the same time.
* src/options.h: add resolve flag to check if --resolve is used.
* testenv/Test--resolve.py: test for --resolve.
* tests/Makefile.am: enable Test--resolve.px test.
* tests/Test--resolve.px: add test for --resolve.
* tests/unit-tests.c (all-tests): enable test
  test_resolve_argument_parse
* tests/unit-tests.h: prototype for test_resolve_argument_parse

Merge request reports

Loading