From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5363945746; Tue, 6 Aug 2024 07:35:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 24030402CF; Tue, 6 Aug 2024 07:35:30 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 40580402BA for ; Tue, 6 Aug 2024 07:35:28 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 691AA20B7177; Mon, 5 Aug 2024 22:35:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 691AA20B7177 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722922527; bh=23sfJEQMAqFhLcib+PLWl39HFAoVrDvOh+k7GThDbxs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QrX571V847RUk8JyRnuF1wqfFa0SMXyrHhhp5QaUEsjA6rP0zFq13mhTD2SF/plAx +8Bmf+CiTaDkdsMCB83h0lbkgmQlSlal/iErf4DhdNcbqm4nuN3IXgftPIwURTvHvc jWo3g2KPX3HBU+G9P+QUdO8h2C6lPp8Tqa2Z06wk= Date: Mon, 5 Aug 2024 22:35:27 -0700 From: Tyler Retzlaff To: Stephen Hemminger Cc: dev@dpdk.org Subject: Re: Portable alternative to inet_ntop? Message-ID: <20240806053527.GA19300@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20240724092113.4977b047@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240724092113.4977b047@hermes.local> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Jul 24, 2024 at 09:21:13AM -0700, Stephen Hemminger wrote: > The function inet_ntop is useful to make printable addresses for debugging. > It is available on Linux and FreeBSD but not on Windows. i know my reply is late. but the following wasn't usable? https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop it isn't wide (PSTR). i know trying to use winsock headers is a mess though so if it is hard duplicating seems fine. i would not be unhappy for more generalized apis to be built up within dpdk to avoid the platform coupling. ty > > There are some alternatives: > - add yet another OS shim in lib/eal/windows/include. > Win32 has similar InetNtoP but it uses wide characters. > > - copy/paste code from FreeBSD into some new functions. > > Hate duplicating code, but portability is a problem here. > > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h > index 0d103d4127..a9404b4b41 100644 > --- a/lib/net/rte_ip.h > +++ b/lib/net/rte_ip.h > @@ -839,6 +839,27 @@ rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len) > return next_proto; > } > > + > +#define RTE_IPV4_ADDR_FMT_SIZE 16 > +#define RTE_IPV6_ADDR_FMT_SIZE 46 > + > +__rte_experimental > +int > +rte_ipv4_format_addr(char *buf, uint16_t size, const void *addr); > + > +__rte_experimental > +void > +rte_ipv4_unformat_addr(const char *str, void *addr); > + > +__rte_experimental > +void > +rte_ipv6_format_addr(char *buf, uint16_t size, const void *addr); > + > +__rte_experimental > +void > +rte_ipv4_unformat_addr(const char *str, void *addr);