Open gperciva opened 3 months ago
This is an alternate solution to #407. (The commit message was tweaked accordingly.)
Examples of message:
$ ./spipe/spipe -t ":1234" -k /dev/null
spipe: No hostname in ":1234"
spipe: Error resolving socket address: :1234
$ ./spipe/spipe -t :1234 -k /dev/null
spipe: No hostname in ":1234"
spipe: Error resolving socket address: :1234
Ok, this adds a more helpful error message, but doesn't solve the problem that spiped -e -s '[127.0.0.1]:12345' -t ':12346' -k /COPYRIGHT -D
daemonizes before it performs a DNS lookup and then spews error messages forever.
Can you write a sock_validate
function which checks if an address is syntactically valid (i.e. if it might work) without actually doing the address resolution? Then we can call that from spiped
.
Oh! Oops, ok, I get it now. Will do.
Updated.
I also added a check for opt_b
.
A source or destination address of the form ":1234" is parsed as a hostname of "" which is guaranteed to never work. While we don't want to give special error messages for all possible invalid addresses, this particular case can easily be produced from a broken shell script (with a hostname variable accidentally not set), so it's worth having a special error message.
Suggested by: Ross Richardson