MEDIUM: tools: make str2sa_range() optionally return the FQDN
The function does a bunch of things among which resolving environment
variables, skipping address family specifiers and trimming port ranges.
It is the only one which sees the complete host name before trying to
resolve it. The DNS resolving code needs to know the original hostname,
so we modify this function to optionally provide it to the caller.
Note that the function itself doesn't know if the host part was a host
or an address, but str2ip() knows that and can be asked not to try to
resolve. So we first try to parse the address without resolving and
try again with resolving enabled. This way we know if the address is
explicit or needs some kind of resolution.
diff --git a/src/server.c b/src/server.c
index 340a310..0e5c079 100644
--- a/src/server.c
+++ b/src/server.c
@@ -904,7 +904,7 @@
* - IP:+N => port=+N, relative
* - IP:-N => port=-N, relative
*/
- sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL);
+ sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@@ -1189,7 +1189,7 @@
int port1, port2;
struct protocol *proto;
- sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL);
+ sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL);
if (!sk) {
Alert("parsing [%s:%d] : '%s' : %s\n",
file, linenum, args[cur_arg], errmsg);
@@ -1397,7 +1397,7 @@
}
newsrv->conn_src.opts |= CO_SRC_BIND;
- sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL);
+ sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL, NULL);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
@@ -1497,7 +1497,7 @@
struct sockaddr_storage *sk;
int port1, port2;
- sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL);
+ sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);