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 12E9A41C26; Tue, 7 Feb 2023 01:20:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6338842D53; Tue, 7 Feb 2023 01:19:53 +0100 (CET) Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by mails.dpdk.org (Postfix) with ESMTP id 45FF4427E9 for ; Tue, 7 Feb 2023 01:19:48 +0100 (CET) Received: by mail-pj1-f43.google.com with SMTP id bx22so10384570pjb.3 for ; Mon, 06 Feb 2023 16:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qHmZvaEwA2Idi2a9p9IZVgRD1nqVxj8o6eo83qT7IX4=; b=ILsI8Cuj4J6+uvzFbnMjXNO4Xa1jWdwBcCJm7HkRj59/t2nVR2i0q//zdORMmS3X80 o41P67OGB14hRnLnmoVjEQ0gEMrRhH+MARTYCdLQO5u2coJ3cMoDvboYzAOeRh7YfZ0k Nd4Y/xW4Q77QHMg5CKcShl8DLVGipoROo+Bt+sLK5ihahJ9wFDSZxGsdNV2Y9vdUIPY2 YAVchF9ZgO3qFQPiwOzmj7S6hdAzRchGMHQltttfn35UEfqyoGWQRSBTegXFx8NpvqwS Qqe5c68k2IGDKFTvqZx3ghSn9/TrsNrVOe9FNSI8nfqSmknRCqe26o0DUP6F31+a3jjp jLtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qHmZvaEwA2Idi2a9p9IZVgRD1nqVxj8o6eo83qT7IX4=; b=M1+GV/pvANxhk0IhmKVjyY1lJChMfxif9FX82hpqSaZNBg4Q/8PeP/tGA1mUgFDGtF 34JhIA7Dpk5zzxfgrL4X3jcOHQS4YHYCMX55gWdNQJqR2yupUX9HrioIDB/7yoJwIY50 DmLX0c8uzFMYebr6CFxMYSSd7tjSKrVnaK5j53Nn6bvUs4ACBeQprc3jlnKObN6fD/mx kLLgp/wZdWox/JtMUHL8opmYDgInpTfqeIGN/xXmvu2Dzxw0LUFBSu0/453MKFU9ohRz 7Oc/wsQOMOJoAzT/kTv7ckgilY46iHyZUArAxrr4iFUEHuAQuqMhq/at6mO/i4UL7ALg hfeQ== X-Gm-Message-State: AO0yUKXc4h1ebAMJJwi5Nn05Y2j2MqKkltWgpV6UCH/zmrnXL9rQnTQK SPehnO29tDfHYW4YonIeJNQoYhz4WV3Up7MwiS0= X-Google-Smtp-Source: AK7set/R4gEroeMA9j4rkBCOK549vN+S+agymJahjuf7FQ3aNWHiVavG4os+WxK+tEouSBt0i1v2tg== X-Received: by 2002:a05:6a20:4422:b0:be:9893:fd82 with SMTP id ce34-20020a056a20442200b000be9893fd82mr1634451pzb.23.1675729187246; Mon, 06 Feb 2023 16:19:47 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id o11-20020a637e4b000000b0046ff3634a78sm6617393pgn.71.2023.02.06.16.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 16:19:46 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Reshma Pattan Subject: [PATCH v2 8/8] pcapng: windows compatibility Date: Mon, 6 Feb 2023 16:19:37 -0800 Message-Id: <20230207001937.875608-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207001937.875608-1-stephen@networkplumber.org> References: <20221201014440.11896-1-stephen@networkplumber.org> <20230207001937.875608-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Allow building on Windows, need to provide some comparability wrappers for writev() and if_nametoindex. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/pcapng/meson.build | 6 ----- lib/pcapng/rte_pcapng.c | 59 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/pcapng/meson.build b/lib/pcapng/meson.build index da938bbcb733..4549925d41b6 100644 --- a/lib/pcapng/meson.build +++ b/lib/pcapng/meson.build @@ -1,12 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Microsoft Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - sources = files('rte_pcapng.c') headers = files('rte_pcapng.h') diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index ea004939e63e..89d444d6ab5b 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -3,15 +3,18 @@ */ #include -#include #include #include #include #include -#include #include #include +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#include +#endif + #include #include #include @@ -20,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +51,57 @@ static struct pcapng_time { struct rte_reciprocal_u64 tsc_hz_inverse; } pcapng_time; + +#ifdef RTE_EXEC_ENV_WINDOWS +/* + * Windows does not have writev() call. + * Emulate this by copying to a new buffer. + * The copy is necessary since pcapng needs to be thread-safe + * and do atomic write operations. + */ + +#define IOV_MAX 128 +struct iovec { + void *iov_base; + size_t iov_len; +}; + +static ssize_t writev(int fd, const struct iovec *iov, int iovcnt) +{ + size_t bytes = 0; + uint8_t *ptr; + void *tmp_buf; + ssize_t ret; + int i; + + for (i = 0; i < iovcnt; i++) + bytes += iov[i].iov_len; + + if (unlikely(bytes == 0)) + return 0; + + tmp_buf = malloc(bytes); + if (unlikely(tmp_buf == NULL)) { + errno = ENOMEM; + return -1; + } + + ptr = tmp_buf; + for (i = 0; i < iovcnt; i++) { + rte_memcpy(ptr, iov[i].iov_base, iov[i].iov_len); + ptr += iov[i].iov_len; + } + + ret = write(fd, tmp_buf, bytes); + free(tmp_buf); + return ret; +} + +#define IF_NAMESIZE 16 +/* compatiablity wrapper because name is optional */ +#define if_indextoname(ifindex, ifname) NULL +#endif + static inline void pcapng_init(void) { -- 2.39.1