fix parsing of IP-Urls
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 10 Aug 2011 13:55:42 +0000 (13:55 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 10 Aug 2011 13:55:42 +0000 (13:55 +0000)
  - 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

index 5259d8228c6b69a416c47fbb1f23828daf86c983..cfadf345f5cf154eb1b9f4582afa36b6688465a0 100644 (file)
@@ -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;
 }