summaryrefslogtreecommitdiffstats
path: root/polyp/polyplib-context.c
diff options
context:
space:
mode:
Diffstat (limited to 'polyp/polyplib-context.c')
-rw-r--r--polyp/polyplib-context.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c
index a15e4257..63b42eb3 100644
--- a/polyp/polyplib-context.c
+++ b/polyp/polyplib-context.c
@@ -336,11 +336,15 @@ finish:
static struct sockaddr *resolve_server(const char *server, size_t *len) {
struct sockaddr *sa;
struct addrinfo hints, *result = NULL;
- char *port;
+ char *port, host[256];
assert(server && len);
+ snprintf(host, sizeof(host), "%s", server);
+ host[strcspn(host, ":")] = 0;
+
if ((port = strrchr(server, ':')))
port++;
+
if (!port)
port = DEFAULT_PORT;
@@ -349,7 +353,7 @@ static struct sockaddr *resolve_server(const char *server, size_t *len) {
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- if (getaddrinfo(server, port, &hints, &result) != 0)
+ if (getaddrinfo(host, port, &hints, &result) != 0)
return NULL;
assert(result);