cvs: php4 /sapi/thttpd thttpd.c
| From: | Sascha Schumann | Date: | Mon, 23 Sep 2002 00:49:13 +0000 |
| Subject: | cvs: php4 /sapi/thttpd thttpd.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-14155@lists.php.net to get a copy of this message | ||
sas Sun Sep 22 20:49:13 2002 EDT
Modified files:
/php4/sapi/thttpd thttpd.c
Log:
Use generic getnameinfo for address-to-name translation, if available.
This adds support for IPv6 addresses.
Index: php4/sapi/thttpd/thttpd.c
diff -u php4/sapi/thttpd/thttpd.c:1.68 php4/sapi/thttpd/thttpd.c:1.69
--- php4/sapi/thttpd/thttpd.c:1.68 Wed Sep 18 17:57:35 2002
+++ php4/sapi/thttpd/thttpd.c Sun Sep 22 20:49:12 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: thttpd.c,v 1.68 2002/09/18 21:57:35 zeev Exp $ */
+/* $Id: thttpd.c,v 1.69 2002/09/23 00:49:12 sas Exp $ */
#include "php.h"
#include "SAPI.h"
@@ -34,6 +34,11 @@
#include <stdlib.h>
#include <unistd.h>
+#ifdef HAVE_GETNAMEINFO
+#include <sys/socket.h>
+#include <netdb.h>
+#endif
+
typedef struct {
httpd_conn *hc;
int read_post_data;
@@ -277,6 +282,7 @@
{
char buf[BUF_SIZE + 1];
char *p;
+ int sa_len;
php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array
TSRMLS_CC);
php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array TSRMLS_CC);
@@ -290,11 +296,22 @@
} else {
php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array
TSRMLS_CC);
}
-
+
+#ifdef HAVE_GETNAMEINFO
+ switch (TG(hc)->client_addr.sa.sa_family) {
+ case AF_INET: sa_len = sizeof(struct sockaddr_in); break;
+ case AF_INET6: sa_len = sizeof(struct sockaddr_in6); break;
+ default: sa_len = 0;
+ }
+
+ if (getnameinfo(&TG(hc)->client_addr.sa, sa_len, buf, sizeof(buf), 0, 0, NI_NUMERICHOST) ==
0) {
+#else
p = inet_ntoa(TG(hc)->client_addr.sa_in.sin_addr);
+
/* string representation of IPs are never larger than 512 bytes */
if (p) {
memcpy(buf, p, strlen(p) + 1);
+#endif
ADD_STRING("REMOTE_ADDR");
ADD_STRING("REMOTE_HOST");
}