Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Modules/socketmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -6041,7 +6041,7 @@ sock_decode_hostname(const char *name)

static PyObject *
gethost_common(socket_state *state, struct hostent *h, struct sockaddr *addr,
size_t alen, int af)
size_t alen, int af, int h_error)
{
char **pch;
PyObject *rtn_tuple = (PyObject *)NULL;
Expand All@@ -6052,7 +6052,7 @@ gethost_common(socket_state *state, struct hostent *h, struct sockaddr *addr,

if (h == NULL) {
/* Let's get real error message to return */
set_herror(state, h_errno);
set_herror(state, h_error);
return NULL;
}

Expand DownExpand Up@@ -6188,6 +6188,7 @@ static PyObject *
socket_gethostbyname_ex(PyObject *self, PyObject *args)
{
char *name;
int h_error;
struct hostent *h;
sock_addr_t addr;
struct sockaddr *sa;
Expand All@@ -6199,7 +6200,6 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
#else
char buf[16384];
int buf_len = (sizeof buf) - 1;
int errnop;
#endif
#ifdef HAVE_GETHOSTBYNAME_R_3_ARG
int result;
Expand All@@ -6218,14 +6218,14 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
gethostbyname_r(name, &hp_allocated, buf, buf_len,
&h, &errnop);
gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &h_error);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h_error);
#else /* HAVE_GETHOSTBYNAME_R_3_ARG */
memset((void *) &data, '\0', sizeof(data));
result = gethostbyname_r(name, &hp_allocated, &data);
h = (result != 0) ? NULL : &hp_allocated;
h_error = h_errno;
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
Expand All@@ -6235,6 +6235,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
h = gethostbyname(name);
_Py_COMP_DIAG_POP
h_error = h_errno;
#endif /* HAVE_GETHOSTBYNAME_R */
Py_END_ALLOW_THREADS
/* Some C libraries would require addr.__ss_family instead of
Expand All@@ -6243,7 +6244,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
access sa_family. */
sa = SAS2SA(&addr);
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr),
sa->sa_family);
sa->sa_family, h_error);
#ifdef USE_GETHOSTBYNAME_LOCK
PyMutex_Unlock(&netdb_lock);
#endif
Expand DownExpand Up@@ -6282,7 +6283,6 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
to maintain this alignment. */
_Py_ALIGNED_DEF(8, char) buf[16384];
int buf_len = (sizeof buf) - 1;
int errnop;
#endif
#ifdef HAVE_GETHOSTBYNAME_R_3_ARG
int result;
Expand All@@ -6291,6 +6291,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
const char *ap;
int al;
int af;
int h_error;

if (!PyArg_ParseTuple(args, "et:gethostbyaddr", "idna", &ip_num))
return NULL;
Expand DownExpand Up@@ -6323,16 +6324,14 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
gethostbyaddr_r(ap, al, af,
&hp_allocated, buf, buf_len,
&h, &errnop);
gethostbyaddr_r(ap, al, af, &hp_allocated, buf, buf_len, &h, &h_error);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyaddr_r(ap, al, af,
&hp_allocated, buf, buf_len, &errnop);
h = gethostbyaddr_r(ap, al, af, &hp_allocated, buf, buf_len, &h_error);
#else /* HAVE_GETHOSTBYNAME_R_3_ARG */
memset((void *) &data, '\0', sizeof(data));
result = gethostbyaddr_r(ap, al, af, &hp_allocated, &data);
h = (result != 0) ? NULL : &hp_allocated;
h_error = h_errno;
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
Expand All@@ -6342,9 +6341,10 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
h = gethostbyaddr(ap, al, af);
_Py_COMP_DIAG_POP
h_error = h_errno;
#endif /* HAVE_GETHOSTBYNAME_R */
Py_END_ALLOW_THREADS
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af);
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af, h_error);
#ifdef USE_GETHOSTBYNAME_LOCK
PyMutex_Unlock(&netdb_lock);
#endif
Expand Down
Loading