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 C1CEC6FC8F; Thu, 25 Mar 2021 00:26:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C1CEC6FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616621199; bh=w8yHjuLk8pLgShA5iz3Y6LED0v0dBbn5pcbqJLw3Lbs=; 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=XE164SItwcMA45aYYq6YUDPTjTT0ao/lLDxFrjPdVwnIKfddsDf+3rAjRHSHJbsqq vThcJG8S2N0SYsInFXFPGE5cIeodghKfPjsP45Odbd+mkyUDuWILd7ooaMlSvNy9kr uZL/i4Yu+q/oS6rtSawn3B343UueUmaXd8HXW5L0= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (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 E3FB26BD3A for ; Thu, 25 Mar 2021 00:24:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E3FB26BD3A Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1lPAzX-0004ib-Rb; Thu, 25 Mar 2021 00:24:40 +0300 To: tarantool-patches@dev.tarantool.org, kyukhin@tarantool.org Date: Wed, 24 Mar 2021 22:24:24 +0100 Message-Id: <9bf63a71e87682be996e9810a6754d16320684b8.1616620860.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: 4F1203BC0FB41BD9064ADF4728AA0EE922675D89A18E042B1EBC993A8274C79D182A05F538085040450CDD58D13736BAB1A62CEC25499FF258A8C0CF4C9C569119CF74848A4BDE3D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE701173C01F417A2A6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637040380BD28C1B15C8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C5DD32608FC869F5D9D572D64D5B70D32F41F16F95B14137FA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7820CF4CC0E318EFB9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3A12191B5F2BB8629117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFDD354218917E60E4BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6470100DFE4501EF176E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A2BEBFE083D3B9BA73A03B725D353964BB11811A4A51E3B096D1867E19FE14079BA9C0B312567BB23089D37D7C0E48F6CA18204E546F3947CB26E97DCB74E625257739F23D657EF2BC8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F790063757B1FBEA53BC6EDBEFF80C71ABB335746BA297DBC24807EA27F269C8F02392CD6143B1329D1CCA5627F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824AC8B6CDF511875BC4E8F7B195E1C97831148145A0506FFD4811447ED96C72CD2D X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C5DD32608FC869F5D9D572D64D5B70D32F41F16F95B14137F9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34B3611847B8BC2D0BD8CD637A7D7D26458E9CFA5FC4DDFF6079F34E18861CA38D275C3B6D1F4B5F131D7E09C32AA3244C15C3A1F0FDA1B270669A1702061D0EA75A1673A01BA68E40729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjqzNotmU+gc/X8I+7Byjxw== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110A906815429F9D9609F4DCA58200BC7396CD94E02192C25FD07784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 12/15] 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 (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)