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 EC15241CE2; Sun, 19 Feb 2023 18:51:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1889842D46; Sun, 19 Feb 2023 18:50:35 +0100 (CET) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id 5457E42D3F for ; Sun, 19 Feb 2023 18:50:24 +0100 (CET) Received: by mail-pj1-f41.google.com with SMTP id w12-20020a17090a4f4c00b00236a0d55d3aso1294477pjl.3 for ; Sun, 19 Feb 2023 09:50:24 -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=LFUwQiMZBZSXVoc57R5sltggKpaWcIsy0laqAgGpQ34=; b=rk0xjQDkKurTZOaePUKr/ZsSc38GDMySfpBFQiGNgH4bU8KEpMqmia2JLQ6uuFajlk F3ikUnOfadcCeEVeCoNRIPeKGBQXevREnP4H7Wn4SpVsEguxwnTXJTVrfjDOMzbV7Sff 2jqC6o/3q66sLrl+7VBHuZ8jydBpgF56O7UDXVkRhD8Ani0FBdJX1OX2eHUnRxQHCvId XDSboLcON/1Vi+do0inKroaktFgNrJ0HMcgzaNEFw4dC3rC4A4aHkG71rig4F289tmr8 b4hrlWNzhGv8Hb2a+POWzMJJNZ3WolLTIsLOJEZ7ji8fSG1TnbajCN7yi1IArsezamUI HJug== 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=LFUwQiMZBZSXVoc57R5sltggKpaWcIsy0laqAgGpQ34=; b=zrKN0H/vi4qn/jXpNrvzTbB4hBVzdJLw/6EU3GHc27zwD6AtyPISzfS9pVAdXzEv0I RaxizlS3ASJJhKgxerxoi16trx2e/VJfsnM3Bxa172jhKkQFOpQghBSb8EA6V9Lh4Q68 Zp504oxdrpo3XpvPlYlVBCU67qGYH+jism/s9VB1EfhvCGsT6iqYkhNKP7wP5JqWqVh0 eFTEFFD37pgI2Qn7CtZ/FBAfKkJrgUEF16/BDJsqYsUdlavItIWN6/I8BModhNnxQj98 7IBwzK1AFEBpc82lJE7FqdZbDDUpsUHtIQGHy2H5AFtL9w74/iZ9nFsbysOEAl84kW61 /n0w== X-Gm-Message-State: AO0yUKUKu46eJNAZEHIBb34mgbzcGrjgezztMPq1I5GrD7ut8bEymaBE DUyz3tBFSVyIBb/c0k8BDRaKsr+1VUlSfEweAqs= X-Google-Smtp-Source: AK7set8haFM0G/kNaDohxElCjs9C3DIcSAdPcEXnMix+8DlY4sNcVRHWv60IZnZkQGZYFOsIa/vXLg== X-Received: by 2002:a17:902:f691:b0:19a:59a5:e88e with SMTP id l17-20020a170902f69100b0019a59a5e88emr89786plg.59.1676829023304; Sun, 19 Feb 2023 09:50:23 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id a13-20020a170902b58d00b001991e4e0bdcsm6238408pls.233.2023.02.19.09.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 09:50:22 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Reshma Pattan Subject: [PATCH v3 8/8] pcapng: windows compatibility Date: Sun, 19 Feb 2023 09:50:13 -0800 Message-Id: <20230219175013.10057-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230219175013.10057-1-stephen@networkplumber.org> References: <20230207001937.875608-1-stephen@networkplumber.org> <20230219175013.10057-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..d4b2db773160 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