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 CD35DA00C2; Thu, 1 Dec 2022 02:45:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C270242D3E; Thu, 1 Dec 2022 02:44:53 +0100 (CET) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 4B8D242D40 for ; Thu, 1 Dec 2022 02:44:51 +0100 (CET) Received: by mail-pl1-f177.google.com with SMTP id w23so186190ply.12 for ; Wed, 30 Nov 2022 17:44:51 -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=vtPX6DEkBCCFh34jQLV2HQHEx3KM8jJIiQBAm4AxeF0=; b=7yndYfM7CYQuy1nQwjVEQbXc2amGHk0ils7F/R2lTuON4yTe4RHQAcfg2WjVfIRxLj KPZYec1DgOBTSKISEqVIuiDXhn4X6Vj3/JeSZCYBJhKqwKXSbj72i87uGpyR1N+5lTcT TI+bACaFBLdRyGHln4LXXRh11P/ybvSTbNlpsXDn68pD+9FYYAG706i0/XZ+I40hA6iy 1GBBtiUKSuoZVUPfs5ix34diM/EKVYKA3jUgE7dtj8RIhVK06vHjuDZhLQv4PcZqAYcn IKeWD7SfR5WpMNhvp/W/FnhxwF/5RnH/NswgxBc5lHQejE2UDxzggXEoQcidlGw5MtZi AK/A== 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=vtPX6DEkBCCFh34jQLV2HQHEx3KM8jJIiQBAm4AxeF0=; b=dPgxxGF8RWseLvkKussGjucO2WbH+xU3PMp1KR4gkshuX2GiFBbDUsiqdYNQu0gBq8 5tgpxWWYjVl3uh78cs8D+hse0aMaG8nO10XgUKxaNrwasrqrS0tJMKPGXinv18AZlRoJ DH9MGNLQHAJI1jcaT5rIx3nwMOtdWSGnzAvc6OvEYqVckBvOBpS3CkTZ8tyIdlWbs+dY +gUocnBacmRSrAxUsaZM/mAn50yjcg0cYQHjVcj66o3FOe3hjfNN+qszaZSy63zVGC1I 0ye7ONXb1560gefHGYPWRui/h2aRlBxAUS+If0b0bUlurMsJiRcD4SSsBRazsAvIr6qO VRGw== X-Gm-Message-State: ANoB5plH1L60cWTmbydG5pInsQY7SDQULIjf3XVFSOrALOGsyWSaQfBl iWCeaOgEDuJdZGS3Eg3fqORtrT5lYfaqoNH5 X-Google-Smtp-Source: AA0mqf7kUd7jz8qPESOXQNZ6iGH6seBqnwWpKHfPdgKBKfGPKNbtPCMfrjRcEbzSlll90RmlU9Xhuw== X-Received: by 2002:a17:90b:258:b0:219:396f:8a09 with SMTP id fz24-20020a17090b025800b00219396f8a09mr17747550pjb.20.1669859090446; Wed, 30 Nov 2022 17:44:50 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h14-20020a170902680e00b00186ffe62502sm2125014plk.254.2022.11.30.17.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 17:44:50 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH 8/8] pcapng: windows compatability Date: Wed, 30 Nov 2022 17:44:39 -0800 Message-Id: <20221201014440.11896-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221201014440.11896-1-stephen@networkplumber.org> References: <20221201014440.11896-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 compatability wrappers for writev() and if_nametoindex. Signed-off-by: Stephen Hemminger --- 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 80d08e1a3bde..888f8b84cd97 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 @@ -44,6 +48,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.35.1