From 63499c15ae3c6c0a34b85d593d5743e8a7eb7447 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 10 Aug 2011 13:55:42 +0000 Subject: [PATCH] fix parsing of IP-Urls - need to point inet_pton() to the rightly casted pointer in case of non-IPv6 - set the port using hton() - set the protocol depending on our findings --- libcitadel/lib/urlhandling.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libcitadel/lib/urlhandling.c b/libcitadel/lib/urlhandling.c index 5259d8228..cfadf345f 100644 --- a/libcitadel/lib/urlhandling.c +++ b/libcitadel/lib/urlhandling.c @@ -112,7 +112,24 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) } if (pPort != NULL) url->Port = atol(pPort); - url->IsIP = inet_pton(url->af, url->Host, &url->Addr.sin6_addr); + if (url->IPv6) + { + url->IsIP = inet_pton(AF_INET6, url->Host, &url->Addr.sin6_addr); + if (url->IsIP) + { + url->Addr.sin6_port = htons(url->Port); + url->Addr.sin6_port = AF_INET6; + } + } + else + { + url->IsIP = inet_pton(AF_INET, url->Host, &((struct sockaddr_in *)&(url->Addr))->sin_addr); + if (url->IsIP) + { + ((struct sockaddr_in *)&(url->Addr))->sin_port = htons(url->Port); + ((struct sockaddr_in *)&(url->Addr))->sin_family = AF_INET; + } + } *Url = url; return 1; } -- 2.39.2