X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_url_api.c;h=9e87bae42496e3bc887b8eaac8d1f4f8abcd2db4;hb=6e3dd5adc6b835d7706c440507e8d1301ec9cbb6;hp=3fbf008e5329dfe63ac4e23f4086051be5e22f9e;hpb=edc84b40eb2c5be04492fa98fec5833a030782eb;p=m6w6%2Fext-http diff --git a/http_url_api.c b/http_url_api.c index 3fbf008..9e87bae 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -69,7 +69,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( } else if (purl->scheme) { furl.scheme = purl->scheme; #if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - } else if (port && (se = getservbyport(port, "tcp"))) { + } else if (port && (se = getservbyport(htons(port), "tcp"))) { furl.scheme = (scheme = estrdup(se->s_name)); #endif } else { @@ -83,14 +83,14 @@ PHP_HTTP_API char *_http_absolute_url_ex( } else if (strncmp(furl.scheme, "http", 4)) { #if defined(PHP_WIN32) || defined(HAVE_NETDB_H) if ((se = getservbyname(furl.scheme, "tcp"))) { - furl.port = se->s_port; + furl.port = ntohs(se->s_port); } #endif } else { furl.port = (furl.scheme[4] == 's') ? 443 : 80; } - if (host) { + if (host && host_len) { furl.host = (char *) host; } else if (purl->host) { furl.host = purl->host; @@ -134,7 +134,11 @@ PHP_HTTP_API char *_http_absolute_url_ex( HTTP_URI_STRLCATL(URL, full_len, furl.host); if ( (!strcmp(furl.scheme, "http") && (furl.port != 80)) || - (!strcmp(furl.scheme, "https") && (furl.port != 443))) { + (!strcmp(furl.scheme, "https") && (furl.port != 443)) +#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) + || ((se = getservbyname(furl.scheme, "tcp")) && (ntohs(se->s_port) != furl.port)) +#endif + ) { char port_string[8] = {0}; snprintf(port_string, 7, ":%u", furl.port); HTTP_URI_STRLCATL(URL, full_len, port_string);