*/
#include "Python.h"
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+
+#if defined(HAVE_GETHOSTBYNAME_R) && defined(HAVE_GETHOSTBYNAME_R_3_ARG)
+/* XXX Somebody please submit code for the 3-arg version! */
+#undef HAVE_GETHOSTBYNAME_R
+#endif
+
+#if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS)
+#define USE_GETHOSTBYNAME_LOCK
+#endif
+
+#ifdef USE_GETHOSTBYNAME_LOCK
#include "pythread.h"
#endif
/* Lock to allow python interpreter to continue, but only allow one
thread to be in gethostbyname */
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_type_lock gethostbyname_lock;
#endif
char buf[1001];
int buf_len = (sizeof buf) - 1;
int errnop;
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
int result;
#endif
#endif /* HAVE_GETHOSTBYNAME_R */
}
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &hp, &errnop);
#else
hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
-#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
- PyThread_acquire_lock(gethostbyname_lock,1);
+#ifdef USE_GETHOSTBYNAME_LOCK
+ PyThread_acquire_lock(gethostbyname_lock, 1);
#endif
hp = gethostbyname(name);
#endif /* HAVE_GETHOSTBYNAME_R */
#else
PyErr_SetString(PySocket_Error, "host not found");
#endif
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(gethostbyname_lock);
#endif
return -1;
}
memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length);
h_length = hp->h_length;
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(gethostbyname_lock);
#endif
return h_length;
char buf[16384];
int buf_len = (sizeof buf) - 1;
int errnop;
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
int result;
#endif
#endif /* HAVE_GETHOSTBYNAME_R */
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &errnop);
#else
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
-#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
- PyThread_acquire_lock(gethostbyname_lock,1);
+#ifdef USE_GETHOSTBYNAME_LOCK
+ PyThread_acquire_lock(gethostbyname_lock, 1);
#endif
h = gethostbyname(name);
#endif /* HAVE_GETHOSTBYNAME_R */
Py_END_ALLOW_THREADS
- ret = gethost_common(h,&addr);
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+ ret = gethost_common(h, &addr);
+#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(gethostbyname_lock);
#endif
return ret;
struct sockaddr_in addr;
char *ip_num;
struct hostent *h;
+ PyObject *ret;
#ifdef HAVE_GETHOSTBYNAME_R
struct hostent hp_allocated;
char buf[16384];
int buf_len = (sizeof buf) - 1;
int errnop;
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
int result;
#endif
#endif /* HAVE_GETHOSTBYNAME_R */
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
-#if defined(linux) && (__GLIBC__ >= 2)
+#ifdef HAVE_GETHOSTBYNAME_R_6_ARG
result = gethostbyaddr_r((char *)&addr.sin_addr,
sizeof(addr.sin_addr),
AF_INET, &hp_allocated, buf, buf_len,
&hp_allocated, buf, buf_len, &errnop);
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
-#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
- PyThread_acquire_lock(gethostbyname_lock,1);
+#ifdef USE_GETHOSTBYNAME_LOCK
+ PyThread_acquire_lock(gethostbyname_lock, 1);
#endif
h = gethostbyaddr((char *)&addr.sin_addr,
sizeof(addr.sin_addr),
AF_INET);
-#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
- PyThread_release_lock(gethostbyname_lock);
-#endif
#endif /* HAVE_GETHOSTBYNAME_R */
Py_END_ALLOW_THREADS
- return gethost_common(h,&addr);
+ ret = gethost_common(h, &addr);
+#ifdef USE_GETHOSTBYNAME_LOCK
+ PyThread_release_lock(gethostbyname_lock);
+#endif
+ return ret;
}
static char gethostbyaddr_doc[] =
#endif
/* Initialize gethostbyname lock */
-#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
+#ifdef USE_GETHOSTBYNAME_LOCK
gethostbyname_lock = PyThread_allocate_lock();
#endif
}