certnanny / sscep

SSCEP is a command line client for the SCEP protocol
Other
175 stars 92 forks source link

Try connecting with all resolved addresses #152

Closed pjasicek closed 2 years ago

pjasicek commented 2 years ago

There are instances where the host machine does not have IPv6 connectivity and DNS returns both IPv6 and IPv4 addresses. The order of the returned addresses is random - first entry might be IPv6 and second entry might be IPv4, e.g.:

$ nslookup example.scepserver.com                                                            
Server:    127.0.0.1                                                                         
Address 1: 127.0.0.1 localhost.localdomain                                                   

Name:      example.scepserver.com                                                            
Address 1: 64:ff9b::aaaa:bbbb                                                                
Address 2: 123.123.123.123

In this case, the code only tried resolving Address 1, which resulted with failure, because the host machine did not have IPv6 connectivity:

cannot connect: Network is unreachable

This commit changes the behaviour by iterating over all returned resolved addresses and trying to connect to all of them until it eventually succeeds or fails if none of the addresses could be connected to.

gotthardp commented 2 years ago

Thanks!