From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id CB5E56EC56; Sat, 20 Mar 2021 03:44:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CB5E56EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616201094; bh=DhNPJP3+eOvYtgRAP7iF4mLm4ZIMbY1uYef/vt8ktAY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Wha/sxTed1UNN7NKbVeg1zP1SYZaocYdeivK7svzDCS/hQ7MgREJ2IOrLWlh7GIxl canLymdfuuVJfkCTEwtoDF952RaCWv0RIigWykbYDAXxlb2kB07nySh2MM5sLEaVpF lvDIv+flfA5sHyjB10kMiCUYXjpJRsKQVAZYkZpI= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 339906F3CB for ; Sat, 20 Mar 2021 03:42:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 339906F3CB Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lNPhd-00076U-D3; Sat, 20 Mar 2021 03:42:53 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sat, 20 Mar 2021 01:42:35 +0100 Message-Id: <393f1f92a15c7c1ec26f27daf1f6f88bd052da5a.1616200860.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F19D4B90E2C0E110A6B701D7D268243E19182A05F538085040EFF49E212AB7A24652C39557F5F1EA85A3DDAE92E754EB9C053138C8B2B1806F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3DED2DACB82E709C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7A3DED2DACB82E7098F08D7030A58E5ADC58D69EE07B14084C6CDE5D1141D2B1C6329739450BAD0CDB532E5DB68C294C96CF29B08EA35F7439FA2833FD35BB23D9E625A9149C048EE1E561CDFBCA1751F28451B159A507268D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B1BE95B8C87527B4BA471835C12D1D977C4224003CC836476EC64975D915A344093EC92FD9297F6718AA50765F7900637BC468E7E89D8C5D6A7F4EDE966BC389F395957E7521B51C24C7702A67D5C33162DBA43225CD8A89F9FFED5BD9FB41755A91E23F1B6B78B78B5C8C57E37DE458B4C7702A67D5C3316FA3894348FB808DBAF038BB36E94EA6B574AF45C6390F7469DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20BD3311767B7455A33FB22DE93D61E34A6 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C81A23F326053F827285EC2DE8F6863DE808803B5A361FAFF9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343D50AEDB859DBAD9056CDDA3A61F93A53B207C8A3136FF13F59C3F7BC42A59FF98C7B5167A9AE4111D7E09C32AA3244C1A39ABDEA2C042F3BE17EC9ADA2CB90F6C24832127668422FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8xHC0Ak4ylY6KFP36cRMFg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D35C4175BCA21C66AF030E618798A57C3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 13/16] sio: rework sio_strfaddr() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 --- src/lib/core/sio.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/lib/core/sio.c b/src/lib/core/sio.c index d008526d5..deffee86c 100644 --- a/src/lib/core/sio.c +++ b/src/lib/core/sio.c @@ -329,33 +329,23 @@ sio_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen) const char * sio_strfaddr(const struct sockaddr *addr, socklen_t addrlen) { - switch (addr->sa_family) { - case AF_UNIX: { - struct sockaddr_un *u = (struct sockaddr_un *) addr; - if (addrlen >= sizeof(*u)) - return tt_sprintf("unix/:%s", u->sun_path); - else - return tt_sprintf("unix/:(socket)"); - break; - } - case AF_INET: { - struct sockaddr_in *in = (struct sockaddr_in *) addr; - return tt_snprintf(SERVICE_NAME_MAXLEN, "%s:%d", - inet_ntoa(in->sin_addr), - ntohs(in->sin_port)); - } - default: { - char host[NI_MAXHOST], serv[NI_MAXSERV]; - if (getnameinfo(addr, addrlen, host, sizeof(host), - serv, sizeof(serv), - NI_NUMERICHOST | NI_NUMERICSERV) != 0) - return tt_sprintf("(host):(port)"); - - return tt_snprintf(NI_MAXHOST + NI_MAXSERV, "[%s]:%s", - host, serv); - } + if (addr->sa_family == AF_UNIX) { + struct sockaddr_un *u = (struct sockaddr_un *)addr; + if (addrlen >= sizeof(*u)) + return tt_sprintf("unix/:%s", u->sun_path); + else + return tt_sprintf("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) + return tt_sprintf("(host):(port)"); + else if (addr->sa_family == AF_INET) + return tt_sprintf("%s:%s", host, serv); + else + return tt_sprintf("[%s]:%s", host, serv); } - unreachable(); } int -- 2.24.3 (Apple Git-128)