You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by hg...@apache.org on 2003/07/24 10:17:10 UTC
cvs commit: jakarta-tomcat-connectors/jk/native/common jk_connect.h jk_ajp12_worker.c jk_ajp_common.c jk_connect.c
hgomez 2003/07/24 01:17:10
Modified: jk/native/common jk_connect.h jk_ajp12_worker.c
jk_ajp_common.c jk_connect.c
Log:
Make use of APR gethostbyname equivalent when APR is available.
Remove AS/400 specific code and fix some short to int in port.
We'll use integer everywhere and cast to short only in jk_resolve
Revision Changes Path
1.4 +2 -2 jakarta-tomcat-connectors/jk/native/common/jk_connect.h
Index: jk_connect.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jk_connect.h 25 Jun 2002 07:06:59 -0000 1.3
+++ jk_connect.h 24 Jul 2003 08:17:10 -0000 1.4
@@ -76,7 +76,7 @@
#endif /* __cplusplus */
int jk_resolve(char *host,
- short port,
+ int port,
struct sockaddr_in *rc);
int jk_open_socket(struct sockaddr_in *addr,
1.11 +2 -2 jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c
Index: jk_ajp12_worker.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- jk_ajp12_worker.c 16 May 2003 00:36:18 -0000 1.10
+++ jk_ajp12_worker.c 24 Jul 2003 08:17:10 -0000 1.11
@@ -213,7 +213,7 @@
p->name, host, port);
if(port > 1024 && host) {
- if(jk_resolve(host, (short)port, &p->worker_inet_addr)) {
+ if(jk_resolve(host, port, &p->worker_inet_addr)) {
return JK_TRUE;
}
jk_log(l, JK_LOG_ERROR, "In jk_worker_t::validate, resolve failed\n");
1.38 +2 -2 jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c
Index: jk_ajp_common.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- jk_ajp_common.c 15 Jul 2003 12:15:17 -0000 1.37
+++ jk_ajp_common.c 24 Jul 2003 08:17:10 -0000 1.38
@@ -1366,7 +1366,7 @@
p->name, host, port);
if(port > 1024 && host) {
- if(jk_resolve(host, (short)port, &p->worker_inet_addr)) {
+ if(jk_resolve(host, port, &p->worker_inet_addr)) {
return JK_TRUE;
}
jk_log(l, JK_LOG_ERROR,
1.9 +39 -19 jakarta-tomcat-connectors/jk/native/common/jk_connect.c
Index: jk_connect.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jk_connect.c 17 Feb 2003 16:59:47 -0000 1.8
+++ jk_connect.c 24 Jul 2003 08:17:10 -0000 1.9
@@ -95,18 +95,24 @@
#include <novsock2.h>
#endif
+#ifdef HAVE_APR
+#include "apr_network_io.h"
+#include "apr_errno.h"
+#include "apr_general.h"
+#endif
+
/** resolve the host IP */
int jk_resolve(char *host,
- short port,
+ int port,
struct sockaddr_in *rc)
{
int x;
- u_long laddr;
-#ifdef AS400
- memset(rc, 0, sizeof(struct sockaddr_in));
-#endif
+ /* TODO: Should be updated for IPV6 support. */
+ /* for now use the correct type, in_addr_t */
+ in_addr_t laddr;
+
rc->sin_port = htons((short)port);
rc->sin_family = AF_INET;
@@ -117,26 +123,40 @@
}
}
+ /* If we found also characters we shoud make name to IP resolution */
if(host[x] != '\0') {
-#ifdef AS400
- /* If we found also characters we use gethostbyname_r()*/
- struct hostent hostentry;
- struct hostent *hoste = &hostentry;
- struct hostent_data hd;
- memset( &hd, 0, sizeof(struct hostent_data) );
- if ( (gethostbyname_r( host, hoste, &hd )) != 0 ) {
- return JK_FALSE;
- }
-#else /* If we found also characters we use gethostbyname()*/
- /* XXX : WARNING : We should really use gethostbyname_r in multi-threaded env */
- /* take a look at APR which handle gethostbyname in apr/network_io/unix/sa_common.c */
+
+#ifdef HAVE_APR
+ apr_pool_t *context;
+ apr_sockaddr_t *remote_sa;
+ char *remote_ipaddr;
+
+ /* May be we could avoid to recreate it each time ? */
+ if (apr_pool_create(&context, NULL) != APR_SUCCESS)
+ return JK_FALSE;
+
+ if (apr_sockaddr_info_get(&remote_sa, host, APR_UNSPEC, (apr_port_t)port, 0, context)
+ != APR_SUCCESS)
+ return JK_FALSE;
+
+ apr_sockaddr_ip_get(&remote_ipaddr, remote_sa);
+ laddr = inet_addr(remote_ipaddr);
+
+ /* May be we could avoid to delete it each time ? */
+ apr_pool_destroy(context);
+
+#else /* HAVE_APR */
+
+ /* XXX : WARNING : We should really use gethostbyname_r in multi-threaded env */
+ /* Fortunatly when APR is available, ie under Apache 2.0, we use it */
struct hostent *hoste = gethostbyname(host);
if(!hoste) {
return JK_FALSE;
}
-#endif
laddr = ((struct in_addr *)hoste->h_addr_list[0])->s_addr;
+
+#endif /* HAVE_APR */
} else {
/* If we found only digits we use inet_addr() */
laddr = inet_addr(host);
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org