summaryrefslogtreecommitdiff
path: root/hostmux/mux.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-01-27 23:08:56 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-01-27 23:08:56 +0100
commit0973d57d2a0ef04a97c405470689453ae939f498 (patch)
tree8cacd8ea20da1172878d314c9e47abbe09fba417 /hostmux/mux.c
parent0e023ff2146d086d10c63b8e19bd263ce40d05fe (diff)
Add canonicalize option to hostmux
Taking the canonical name makes very little sense nowadays with a lot of services behind the same IP but virtual hostnames. * hostmux/hostmux.h (hostmux): Add canonicalize field. * hostmux/hostmux.c (options, parse_opt): Add -C/--canonicalize option. * hostmux/mux.c (lookup_host): Only call getaddrinfo if canonicalize is true, pass NULL as HE to lookup_addrinfo otherwise. (lookup_addrinfo): When !HE, use name given by user.
Diffstat (limited to 'hostmux/mux.c')
-rw-r--r--hostmux/mux.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/hostmux/mux.c b/hostmux/mux.c
index 737240af..81d3961f 100644
--- a/hostmux/mux.c
+++ b/hostmux/mux.c
@@ -283,7 +283,7 @@ lookup_addrinfo (struct hostmux *mux, const char *host, struct addrinfo *he,
return ENOMEM;
nm->name = strdup (host);
- if (strcmp (host, he->ai_canonname) == 0)
+ if (!he || strcmp (host, he->ai_canonname) == 0)
nm->canon = nm->name;
else
nm->canon = strdup (he->ai_canonname);
@@ -340,12 +340,17 @@ lookup_host (struct hostmux *mux, const char *host, struct node **node)
if (was_cached)
return 0;
- h_err = getaddrinfo (host, NULL, &hints, &ai);
- if (! h_err)
+ if (mux->canonicalize)
{
- h_err = lookup_addrinfo (mux, host, ai, node);
- freeaddrinfo (ai);
+ h_err = getaddrinfo (host, NULL, &hints, &ai);
+ if (! h_err)
+ {
+ h_err = lookup_addrinfo (mux, host, ai, node);
+ freeaddrinfo (ai);
+ }
}
+ else
+ h_err = lookup_addrinfo (mux, host, NULL, node);
return h_err;
}