diff --git a/daemon.c b/daemon.c
index 360635eb1c14608b44568ce39d969eb8822e688d..6c2bd977131752e05d3ac545af0d977d6d7ca672 100644 (file)
--- a/daemon.c
+++ b/daemon.c
return dup;
}
return dup;
}
+static void parse_host_and_port(char *hostport, char **host,
+ char **port)
+{
+ if (*hostport == '[') {
+ char *end;
+
+ end = strchr(hostport, ']');
+ if (!end)
+ die("Invalid reqeuest ('[' without ']')");
+ *end = '\0';
+ *host = hostport + 1;
+ if (!end[1])
+ *port = NULL;
+ else if (end[1] == ':')
+ *port = end + 2;
+ else
+ die("Garbage after end of host part");
+ } else {
+ *host = hostport;
+ *port = strrchr(hostport, ':');
+ if (*port) {
+ *port = '\0';
+ ++*port;
+ }
+ }
+}
+
/*
* Read the host as supplied by the client connection.
*/
/*
* Read the host as supplied by the client connection.
*/
vallen = strlen(val) + 1;
if (*val) {
/* Split <host>:<port> at colon. */
vallen = strlen(val) + 1;
if (*val) {
/* Split <host>:<port> at colon. */
- char *host = val;
- char *port = strrchr(host, ':');
+ char *host;
+ char *port;
+ parse_host_and_port(val, &host, &port);
if (port) {
if (port) {
- *port = 0;
- port++;
free(tcp_port);
tcp_port = xstrdup(port);
}
free(tcp_port);
tcp_port = xstrdup(port);
}