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 11BE64568A; Wed, 24 Jul 2024 18:21:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A5AFC40B97; Wed, 24 Jul 2024 18:21:17 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 99A704026F for ; Wed, 24 Jul 2024 18:21:16 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fd65aaac27so7586865ad.1 for ; Wed, 24 Jul 2024 09:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1721838076; x=1722442876; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:subject:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=k0RNYYXJ/ZH7yh2gI7OHP1HnLij+LtoEqwCkgapVdK8=; b=1tYaIceW4EgYD8/QB/++wUS6gKxDD/4CpzAQSY0OH7aehxXzGDzZFB8IylAiiVO97Q T+MMc9C18JhymLYrQ2oWMstG8hf/R40TAR8btICvg8y7BY26lXBRYVUTL9jSRvgU+vzE 6SYAoc5JC94GZMENgK7J7wGyP//fx39QH8jX3VfA9AZhSO7J57cv03eTuQAqf1uLB6jA UrG7EMSTsn821s6nFIaMQ/pEpoujW3gnBerUmKpRxTEFD+MdPBh6yMPcgPQn4zR10RX0 Cc5G6qOTeVvlUkBWUXBDzxs1Fa5k4RWfKngpR8uBpySpDvdqHyYr6bgNtaD7VSZTJ2jC 7cug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721838076; x=1722442876; h=content-transfer-encoding:mime-version:message-id:subject:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k0RNYYXJ/ZH7yh2gI7OHP1HnLij+LtoEqwCkgapVdK8=; b=gJZ6WRcSQMSO4EvZ3ZMU4pIgOhMOZXu6kjqP1RNBx29L4mD22X7vNWXMMk/euCPM/j KX0RMZXy57oPRBJ692lJPLnNTHuo6lXJeo062ERyf5sqKGbh/oubEcKxA0FioLm/Whlg UGACvcntNro/D30onDdK47eC0xeWNLoQb2sJ3tpx4xsAxE5QApuv+KBADv9LJZ49jmDe LGmYUH/Gkr70YXUyWvH9Q4rTNVyCzI25yJGakGMA0OH8/F0RFU3HHp/9YAx1Di+vnG53 SfXf1jC/QFd2fIL8RQ6niNDE4vm5zMoNrSyriGYljMFWC6sMWJJiYIGvjnX507asNcyk /ISA== X-Gm-Message-State: AOJu0YyQ0wN6JDkfFxk7uJf6v+f7m90H6sVxtv172pA0EGYse9Z2d1Mr /TIus7w8sQbqoMZTHOol6MP+KQ8SlppQ5RxP55yBYwP90yGv8gXhRLVCO9hlBnxf/dV6BvuPWsx r X-Google-Smtp-Source: AGHT+IFgMR/aRZ8hz6YOX3oEZragXaTzHD5v74Kj/G1SmsKpagX7v53MEb1/odX50hZRwrRCRVozOg== X-Received: by 2002:a17:90b:1c8d:b0:2ab:8324:1b47 with SMTP id 98e67ed59e1d1-2cf21f49bb8mr198050a91.15.1721838075735; Wed, 24 Jul 2024 09:21:15 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cdb747ad27sm1827704a91.42.2024.07.24.09.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 09:21:15 -0700 (PDT) Date: Wed, 24 Jul 2024 09:21:13 -0700 From: Stephen Hemminger To: dev@dpdk.org, Tyler Retzlaff Subject: Portable alternative to inet_ntop? Message-ID: <20240724092113.4977b047@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 The function inet_ntop is useful to make printable addresses for debugging. It is available on Linux and FreeBSD but not on Windows. 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);