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 684AF41E23; Thu, 9 Mar 2023 22:32:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 77DFF42D29; Thu, 9 Mar 2023 22:31:42 +0100 (CET) Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by mails.dpdk.org (Postfix) with ESMTP id A427742BC9 for ; Thu, 9 Mar 2023 22:31:38 +0100 (CET) Received: by mail-pj1-f45.google.com with SMTP id x34so3406602pjj.0 for ; Thu, 09 Mar 2023 13:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1678397497; 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=4/y2OL0bfLf9p3FbQAar27dqsROXQlTkEYW6xvg/tFE=; b=f5DAfUnakofER2c4AwNCd0xX1+QAk6y82fAfZS3fBMbppz7OXMXO0e3I+DZlezfBp8 vQKpHAgIm1dRyQqDjxogLiYOd3/GTWpD4glygVlhoa1N26J5gG0WGYuyY1jGtg/9IXLp aq9HX4v4oTpu09Ah2WT+TJcGjD/O57U9zfIEa5z1Bedsa5+OZAnb5FWpk6FuTvDwUjAF XfRnAVl0uUdux2fIlAJwGR6LnEI0Y+SqxA0xy2k7I4aODWXFhfctKKx6WAFJqsamwgjX vL2g1umH5IV8b4LQPsIsXLa2N0yQo5HNszHWGkGZf382I8J+Lh+tQ3bKmuIVrD1/UgvC mUIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678397497; 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=4/y2OL0bfLf9p3FbQAar27dqsROXQlTkEYW6xvg/tFE=; b=ZBx+HS38p97+nAYWWISDA/wGlEbQSoBeI1bATQF3XTRHuKOo4WprQ/OACdnN7q2kwN ORzhtROH2k0CHKXB3qk3zsmW00NI73WYIBCnK9Lx2+JIAI4MCfRI5VubTIYOztu2AM3Y 5GlM2KRjRhq2Pq/c6VdWUdGFEi7aBt1darSvMIUl/GBCJpRBjd+rpijLWw/07uVG42e0 ehxHhn3kG6dvS4jD5IL2eX+CPq43x30Wh5HFZoFbJQkPuS3Reiea2U18eUq795sTcsH0 gLPw2JCToH3n4mNZmlcuDsa6ib2D9jFWSkah/XXQjJmVR4vqP0b6ZBfEMV0MOIwYumJE uM9g== X-Gm-Message-State: AO0yUKU0qj/dA0JulSseymZ4hDnMeAj13USmcJsW22NUcSz/D7glpbkN QPELDjxUC1+1iScIzTqO/eTEAzc6PiAjJwTPgSCwuw== X-Google-Smtp-Source: AK7set8sL3O1fUS6dmzrWorLxioIaDwbzO98eReHtnVdlZt5RdDxbHC+pmf0nIZDETXpD5hbHTImaA== X-Received: by 2002:a05:6a20:548b:b0:be:e450:69b3 with SMTP id i11-20020a056a20548b00b000bee45069b3mr29493934pzk.0.1678397497651; Thu, 09 Mar 2023 13:31:37 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id q3-20020a63cc43000000b00502e4015ff7sm64225pgi.23.2023.03.09.13.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 13:31:37 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH v5 8/9] pcapng: windows compatibility Date: Thu, 9 Mar 2023 13:31:27 -0800 Message-Id: <20230309213128.34146-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309213128.34146-1-stephen@networkplumber.org> References: <20221201014440.11896-1-stephen@networkplumber.org> <20230309213128.34146-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 65c8c77fa405..3c91fc77644a 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 +/* compatibility wrapper because name is optional */ +#define if_indextoname(ifindex, ifname) NULL +#endif + static inline void pcapng_init(void) { -- 2.39.2