Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9db2f57

Browse files
committed
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
1 parent b5c61a8 commit 9db2f57

3 files changed

Lines changed: 335 additions & 335 deletions

File tree

Modules/socketmodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ PySocket_gethostbyname_ex(PyObject *self, PyObject *args)
18941894
char *name;
18951895
struct hostent *h;
18961896
struct sockaddr_storage addr;
1897+
struct sockaddr *sa;
18971898
PyObject *ret;
18981899
#ifdef HAVE_GETHOSTBYNAME_R
18991900
struct hostent hp_allocated;
@@ -1931,7 +1932,10 @@ PySocket_gethostbyname_ex(PyObject *self, PyObject *args)
19311932
h = gethostbyname(name);
19321933
#endif /* HAVE_GETHOSTBYNAME_R */
19331934
Py_END_ALLOW_THREADS
1934-
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), addr.ss_family);
1935+
/* Some C libraries would require addr.__ss_family instead of addr.ss_family.
1936+
Therefore, we cast the sockaddr_storage into sockaddr to access sa_family. */
1937+
sa = (struct sockaddr*)&addr;
1938+
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), sa->sa_family);
19351939
#ifdef USE_GETHOSTBYNAME_LOCK
19361940
PyThread_release_lock(gethostbyname_lock);
19371941
#endif

0 commit comments

Comments
 (0)