ntpdig needlessly fails when IPv6 is disabled

Forwarding from: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=971523

Steps to reproduce:

  1. Disable IPv6. For example: sysctl -w net.ipv6.conf.all.disable_ipv6=1 ; sysctl -w net.ipv6.conf.default.disable_ipv6=1
  2. ntpdig -d 2.pool.ntp.org and/or ntpdig -dc 2.pool.ntp.org

Expected result: ntpdig should do what it can with IPv4. Skipping the IPv6 addresses would be ideal. Trying them with a timeout is acceptable. (This is what happens on my Debian test system with IPv6 enabled but no actual IPv6.) Crashing is bad.

Actual result:

I get:

$ ntpdig -d 2.pool.ntp.org
ntpdig: querying 23.157.160.168 (2.pool.ntp.org)
ntpdig: querying 171.66.97.126 (2.pool.ntp.org)
ntpdig: querying 99.104.170.138 (2.pool.ntp.org)
ntpdig: querying 45.79.1.70 (2.pool.ntp.org)
ntpdig: querying 2001:4998:58:183a::1001 (2.pool.ntp.org)
ntpdig: socket error on transmission: [Errno 99] Cannot assign requested address

The user reported a slightly different error: [Errno 101] Network is unreachable