From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, kyukhin@tarantool.org Subject: [Tarantool-patches] [PATCH 12/15] sio: rework sio_strfaddr() Date: Wed, 24 Mar 2021 22:24:24 +0100 [thread overview] Message-ID: <9bf63a71e87682be996e9810a6754d16320684b8.1616620860.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1616620860.git.v.shpilevoy@tarantool.org> The function was overcomplicated, and made it harder to update it in the next patches with functional changes. The main source of the complication was usage of both inet_ntoa() and getnameinfo(). The latter is more universal, it can cover the case of the former. The patch makes it use only getnameinfo() for IP addresses regardless of v4 or v6. Needed for #5632 (cherry picked from commit 441cb814d4cdd1ec4999b812d72e04cb5528687f) --- src/sio.cc | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/sio.cc b/src/sio.cc index 3becd1ee2..0ba19346c 100644 --- a/src/sio.cc +++ b/src/sio.cc @@ -514,29 +514,22 @@ const char * sio_strfaddr(struct sockaddr *addr, socklen_t addrlen) { static __thread char name[NI_MAXHOST + _POSIX_PATH_MAX + 2]; - switch(addr->sa_family) { - case AF_UNIX: - if (addrlen >= sizeof(sockaddr_un)) { - snprintf(name, sizeof(name), "unix/:%s", - ((struct sockaddr_un *)addr)->sun_path); - } else { - snprintf(name, sizeof(name), - "unix/:(socket)"); - } - break; - default: { - char host[NI_MAXHOST], serv[NI_MAXSERV]; - if (getnameinfo(addr, addrlen, host, sizeof(host), - serv, sizeof(serv), - NI_NUMERICHOST | NI_NUMERICSERV) == 0) { - snprintf(name, sizeof(name), - addr->sa_family == AF_INET - ? "%s:%s" : "[%s]:%s", host, serv); - } else { - snprintf(name, sizeof(name), "(host):(port)"); - } - break; - } + if (addr->sa_family == AF_UNIX) { + struct sockaddr_un *u = (struct sockaddr_un *)addr; + if (addrlen >= sizeof(*u)) + snprintf(name, sizeof(name), "unix/:%s", u->sun_path); + else + snprintf(name, sizeof(name), "unix/:(socket)"); + } else { + char host[NI_MAXHOST], serv[NI_MAXSERV]; + int flags = NI_NUMERICHOST | NI_NUMERICSERV; + if (getnameinfo(addr, addrlen, host, sizeof(host), + serv, sizeof(serv), flags) != 0) + snprintf(name, sizeof(name), "(host):(port)"); + else if (addr->sa_family == AF_INET) + snprintf(name, sizeof(name), "%s:%s", host, serv); + else + snprintf(name, sizeof(name), "[%s]:%s", host, serv); } return name; } -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-03-24 21:26 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-24 21:24 [Tarantool-patches] [PATCH 00/15] Cord buffer, static alloc, and Lua GC bug for 1.10 Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 01/15] fio: don't use shared buffer in pread() Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 10/15] uri: replace static_alloc with ffi stash and ibuf Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 11/15] lua: use lua_pushfstring() instead of tt_sprintf() Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 13/15] sio: increase SERVICE_NAME_MAXLEN size Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 14/15] sio: introduce and use sio_snprintf() Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 15/15] buffer: remove Lua registers Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 02/15] test: don't use IBUF_SHARED in the tests Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 03/15] tuple: pass global ibuf explicitly where possible Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 04/15] iconv: take errno before reseting the context Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 05/15] cord_buf: introduce cord_buf API Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 06/15] cord_buf: introduce ownership management Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 07/15] buffer: implement ffi stash Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 08/15] uuid: replace static_alloc with " Vladislav Shpilevoy via Tarantool-patches 2021-03-24 21:24 ` [Tarantool-patches] [PATCH 09/15] uuid: drop tt_uuid_str() from Lua Vladislav Shpilevoy via Tarantool-patches 2021-03-29 15:41 ` [Tarantool-patches] [PATCH 00/15] Cord buffer, static alloc, and Lua GC bug for 1.10 Kirill Yukhin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9bf63a71e87682be996e9810a6754d16320684b8.1616620860.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=kyukhin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 12/15] sio: rework sio_strfaddr()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox