summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2018-01-08 21:46:35 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2018-01-08 22:19:02 +0100
commitbf6d507bb2c4a353461cca9706da764ab1c246d8 (patch)
tree370cadc611d9bfa03ab57c3ea9e55e6c422cfc3d /degesch.c
parent099a49e6d5b79662eaa5c8367726302e639d5715 (diff)
downloadxK-bf6d507bb2c4a353461cca9706da764ab1c246d8.tar.gz
xK-bf6d507bb2c4a353461cca9706da764ab1c246d8.tar.xz
xK-bf6d507bb2c4a353461cca9706da764ab1c246d8.zip
degesch: fix IPv6:port in irc_split_host_port()
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/degesch.c b/degesch.c
index 841bea3..ad4c33e 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5642,25 +5642,27 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
refresh_prompt (s->ctx);
}
+/// Unwrap IPv6 addresses in format_host_port_pair() format
static void
irc_split_host_port (char *s, char **host, char **port)
{
- // FIXME: this won't work if this is an IPv6 address w/o a port
- char *colon = strrchr (s, ':');
+ *host = s;
+ *port = "6667";
+
+ char *right_bracket = strchr (s, ']');
+ if (s[0] == '[' && right_bracket)
+ {
+ *right_bracket = '\0';
+ *host = s + 1;
+ s = right_bracket + 1;
+ }
+
+ char *colon = strchr (s, ':');
if (colon)
{
*colon = '\0';
- *port = ++colon;
+ *port = colon + 1;
}
- else
- *port = "6667";
-
- // Unwrap IPv6 addresses in format_host_port_pair() format
- size_t host_end = strlen (s) - 1;
- if (*s == '[' && s[host_end] == ']')
- s++[host_end] = '\0';
-
- *host = s;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -