BSD compatibility: add missing include for AF_INET
[citadel.git] / libcitadel / lib / urlhandling.c
index 5259d8228c6b69a416c47fbb1f23828daf86c983..131cafa6ec4efed449a330320a661b8ea4baf7d6 100644 (file)
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include "libcitadel.h"
+#include <sys/socket.h>
 
 /**
  * @defgroup URLHandling ParsedURL object to handle connection data
@@ -112,7 +113,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;
 }