OSDN Git Service

Experimental: support ipv6.
[ntch/develop.git] / src / net / nt_http.c
index 7429640..339165b 100644 (file)
@@ -559,13 +559,38 @@ static nt_http_header_tp nt_http_init_header(const char *url)
                host[len] = '\0';
        }
 
+#ifdef NT_NET_IPV6
+       if(nt_is_ipv6_addr(host, &cptr)){
+               if(!ssl){
+                       *cptr = '\0';
+                       cptr++;
+                       memmove(host, host+1, cptr - host);
+               }else{
+                       cptr++;
+               }
+               if(*cptr == ':'){
+                       port = atoi(cptr+1);
+                       port = (port == 0) ? -1 : port;
+                       *cptr = '\0';
+               }
+               port = atoi(cptr);
+               port = (port == 0) ? -1 : port;
+       }else{
+               cptr = strchr(host, ':');
+               if(cptr != NULL && strlen(cptr+1) > 0){
+                       port = atoi(cptr+1);
+                       port = (port == 0) ? -1 : port;
+                       *cptr = '\0';
+               }
+       }
+#else
        cptr = strrchr(host, ':');
        if(cptr != NULL && strlen(cptr) > 0){
                port = atoi(cptr);
                port = (port == 0) ? -1 : port;
                *cptr = '\0';
        }
-
+#endif
        headerp = calloc(1, sizeof(nt_http_header_t));
        if(headerp == NULL){
                free(host);