diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-22 19:14:12 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-22 19:20:55 +0300 |
commit | ff5932a8d8d61351b2a9593ab407cc29c094109d (patch) | |
tree | 0cd929040cb5807820458791adf2ff9b3928aa40 | |
parent | 949a49c9da9f8adb64bdddbd8f0258eaa881df2f (diff) | |
download | micropython-ff5932a8d8d61351b2a9593ab407cc29c094109d.tar.gz micropython-ff5932a8d8d61351b2a9593ab407cc29c094109d.zip |
modsocket: Workaround uClibc issue with numeric port for getaddrinfo().
It sucks to workaround this on uPy side, but upgrading not upgradable
embedded systems sucks even more.
-rw-r--r-- | unix/modsocket.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/unix/modsocket.c b/unix/modsocket.c index 457dc81671..5dce46b2e9 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -356,6 +356,8 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { const char *host = mp_obj_str_get_str(args[0]); const char *serv = NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); // getaddrinfo accepts port in string notation, so however // it may seem stupid, we need to convert int to str if (MP_OBJ_IS_SMALL_INT(args[1])) { @@ -363,14 +365,24 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { char buf[6]; sprintf(buf, "%d", port); serv = buf; + hints.ai_flags = AI_NUMERICSERV; +#if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) +#warning Working around uClibc bug with numeric service name + // Older versions og uClibc have bugs when numeric ports in service + // arg require also hints.ai_socktype (or hints.ai_protocol) != 0 + // This actually was fixed in 0.9.32.1, but uClibc doesn't allow to + // test for that. + // http://git.uclibc.org/uClibc/commit/libc/inet/getaddrinfo.c?id=bc3be18145e4d5 + // Note that this is crude workaround, precluding UDP socket addresses + // to be returned. TODO: set only if not set by Python args. + hints.ai_socktype = SOCK_STREAM; +#endif } else { serv = mp_obj_str_get_str(args[1]); } - struct addrinfo hints; struct addrinfo *addr_list; - memset(&hints, 0, sizeof(hints)); - int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr_list); + int res = getaddrinfo(host, serv, &hints, &addr_list); if (res != 0) { // CPython: socket.gaierror |