dan-s1 commented on code in PR #8691:
URL: https://github.com/apache/nifi/pull/8691#discussion_r1601629943


##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;

Review Comment:
   ```suggestion
       private ByteBufferInterface io;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);
+
+        public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;

Review Comment:
   ```suggestion
               this.io = io;
               
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);
+
+        public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            try {
+                read();
+            } catch 
(org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 e) {
+                this.logger.error("PCAP file header could not be parsed due to 
{}", new Object[] {e});

Review Comment:
   ```suggestion
                   this.logger.error("PCAP file header could not be parsed due 
to ", e);
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");

Review Comment:
   ```suggestion
               session.putAttribute(flowFile, ERROR_REASON, "PCAP file empty.");
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{

Review Comment:
   ```suggestion
           try {
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);

Review Comment:
   ```suggestion
           private final Logger logger = LoggerFactory.getLogger(Header.class);
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;

Review Comment:
   ```suggestion
           final PCAP parsedPcap;
           final PCAP templatePcap;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);
+
+        public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            try {
+                read();
+            } catch 
(org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 e) {
+                this.logger.error("PCAP file header could not be parsed due to 
{}", new Object[] {e});
+            }
+        }
+
+        public Header(byte[] magicNumber, int versionMajor, int versionMinor, 
int thiszone, long sigfigs, long snaplen,
+                String network) {
+
+            Linktype networkEnum = Linktype.RAW;
+            if (EnumUtils.isValidEnum(Linktype.class, network)) {
+                networkEnum = Linktype.valueOf(network);
+            }
+
+            this.magicNumber = magicNumber;
+            this.versionMajor = versionMajor;
+            this.versionMinor = versionMinor;
+            this.thiszone = thiszone;
+            this.sigfigs = sigfigs;
+            this.snaplen = snaplen;
+            this.network = networkEnum;
+        }
+
+        public ByteBufferInterface io() {
+            return io;
+        }
+
+        private void read()
+                throws 
org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 {
+            this.magicNumber = this.io.readBytes(4);
+            if (this.magicNumber == new byte[] { (byte) 0xd4, (byte) 0xc3, 
(byte) 0xb2, (byte) 0xa1 }) {
+                // have to swap the bits
+                this.versionMajor = this.io.readU2be();
+                if (!(versionMajor() == 2)) {
+
+                    throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
+                }
+                this.versionMinor = this.io.readU2be();
+                this.thiszone = this.io.readS4be();
+                this.sigfigs = this.io.readU4be();
+                this.snaplen = this.io.readU4be();
+                this.network = Linktype.byId(this.io.readU4be());
+            } else {
+                this.versionMajor = this.io.readU2le();
+                if (!(versionMajor() == 2)) {
+                    throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
+                }
+                this.versionMinor = this.io.readU2le();
+                this.thiszone = this.io.readS4le();
+                this.sigfigs = this.io.readU4le();
+                this.snaplen = this.io.readU4le();
+                this.network = Linktype.byId(this.io.readU4le());
+            }
+        }
+
+        private byte[] magicNumber;
+        private int versionMajor;
+        private int versionMinor;
+        private int thiszone;
+        private long sigfigs;
+        private long snaplen;
+        private Linktype network;
+        private PCAP root;
+        private PCAP parent;
+
+        public byte[] magicNumber() {
+            return magicNumber;
+        }
+
+        public int versionMajor() {
+            return versionMajor;
+        }
+
+        public int versionMinor() {
+            return versionMinor;
+        }
+
+        /**
+         * Correction time in seconds between UTC and the local
+         * timezone of the following packet header timestamps.
+         */
+        public int thiszone() {
+            return thiszone;
+        }
+
+        /**
+         * In theory, the accuracy of time stamps in the capture; in
+         * practice, all tools set it to 0.
+         */
+        public long sigfigs() {
+            return sigfigs;
+        }
+
+        /**
+         * The "snapshot length" for the capture (typically 65535 or
+         * even more, but might be limited by the user), see: incl_len
+         * vs. orig_len.
+         */
+        public long snaplen() {
+            return snaplen;
+        }
+
+        /**
+         * Link-layer header type, specifying the type of headers at
+         * the beginning of the packet.
+         */
+        public Linktype network() {
+            return network;
+        }
+
+        public PCAP root() {
+            return root;
+        }
+
+        public PCAP parent() {
+            return parent;
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header";>Source</a>
+     */
+    public static class Packet {
+        public ByteBufferInterface io;
+
+        public Packet(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            read();
+        }
+
+        public Packet(long tSSec, long tSUsec, long inclLen, long origLen, 
byte[] rawBody) {
+
+            this.tsSec = tSSec;
+            this.tsUsec = tSUsec;
+            this.inclLen = inclLen;
+            this.origLen = origLen;
+            this.raw_body = rawBody;
+        }
+
+        private void read() {
+            this.tsSec = this.io.readU4le();
+            this.tsUsec = this.io.readU4le();
+            this.inclLen = this.io.readU4le();
+            this.origLen = this.io.readU4le();
+            {
+                Linktype on = root().hdr().network();
+                if (on != null) {
+                    switch (root().hdr().network()) {
+                        case PPI, ETHERNET: {
+                            this.raw_body = this.io.readBytes(
+                                    (inclLen() < root().hdr().snaplen() ? 
inclLen() : root().hdr().snaplen()));
+                            break;
+                        }
+                        default: {
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        private long tsSec;
+        private long tsUsec;
+        private long inclLen;
+        private long origLen;
+        private PCAP root;
+        private PCAP parent;
+        private byte[] raw_body;

Review Comment:
   ```suggestion
           private byte[] rawBody;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/Linktype.java:
##########
@@ -0,0 +1,259 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public enum Linktype {

Review Comment:
   Can this list change? If so how do we keep track of this list when it 
changes so we know whether to add or remove entries?



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)

Review Comment:
   It is not enough to only have an integer as a user can specify 0 or a 
negative number which in this case would have no meaning. In order to prevent 
that, use a validator that will ensure the number is greater than 0.
   ```suggestion
               .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;

Review Comment:
   ```suggestion
           private ByteBufferInterface io;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);
+
+        public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            try {
+                read();
+            } catch 
(org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 e) {
+                this.logger.error("PCAP file header could not be parsed due to 
{}", new Object[] {e});
+            }
+        }
+
+        public Header(byte[] magicNumber, int versionMajor, int versionMinor, 
int thiszone, long sigfigs, long snaplen,
+                String network) {
+
+            Linktype networkEnum = Linktype.RAW;
+            if (EnumUtils.isValidEnum(Linktype.class, network)) {
+                networkEnum = Linktype.valueOf(network);
+            }
+
+            this.magicNumber = magicNumber;
+            this.versionMajor = versionMajor;
+            this.versionMinor = versionMinor;
+            this.thiszone = thiszone;
+            this.sigfigs = sigfigs;
+            this.snaplen = snaplen;
+            this.network = networkEnum;
+        }
+
+        public ByteBufferInterface io() {
+            return io;
+        }
+
+        private void read()
+                throws 
org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 {
+            this.magicNumber = this.io.readBytes(4);
+            if (this.magicNumber == new byte[] { (byte) 0xd4, (byte) 0xc3, 
(byte) 0xb2, (byte) 0xa1 }) {
+                // have to swap the bits
+                this.versionMajor = this.io.readU2be();
+                if (!(versionMajor() == 2)) {
+
+                    throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
+                }
+                this.versionMinor = this.io.readU2be();
+                this.thiszone = this.io.readS4be();
+                this.sigfigs = this.io.readU4be();
+                this.snaplen = this.io.readU4be();
+                this.network = Linktype.byId(this.io.readU4be());
+            } else {
+                this.versionMajor = this.io.readU2le();
+                if (!(versionMajor() == 2)) {
+                    throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
+                }
+                this.versionMinor = this.io.readU2le();
+                this.thiszone = this.io.readS4le();
+                this.sigfigs = this.io.readU4le();
+                this.snaplen = this.io.readU4le();
+                this.network = Linktype.byId(this.io.readU4le());
+            }
+        }
+
+        private byte[] magicNumber;
+        private int versionMajor;
+        private int versionMinor;
+        private int thiszone;
+        private long sigfigs;
+        private long snaplen;
+        private Linktype network;
+        private PCAP root;
+        private PCAP parent;
+
+        public byte[] magicNumber() {
+            return magicNumber;
+        }
+
+        public int versionMajor() {
+            return versionMajor;
+        }
+
+        public int versionMinor() {
+            return versionMinor;
+        }
+
+        /**
+         * Correction time in seconds between UTC and the local
+         * timezone of the following packet header timestamps.
+         */
+        public int thiszone() {
+            return thiszone;
+        }
+
+        /**
+         * In theory, the accuracy of time stamps in the capture; in
+         * practice, all tools set it to 0.
+         */
+        public long sigfigs() {
+            return sigfigs;
+        }
+
+        /**
+         * The "snapshot length" for the capture (typically 65535 or
+         * even more, but might be limited by the user), see: incl_len
+         * vs. orig_len.
+         */
+        public long snaplen() {
+            return snaplen;
+        }
+
+        /**
+         * Link-layer header type, specifying the type of headers at
+         * the beginning of the packet.
+         */
+        public Linktype network() {
+            return network;
+        }
+
+        public PCAP root() {
+            return root;
+        }
+
+        public PCAP parent() {
+            return parent;
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header";>Source</a>
+     */
+    public static class Packet {
+        public ByteBufferInterface io;
+
+        public Packet(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            read();
+        }
+
+        public Packet(long tSSec, long tSUsec, long inclLen, long origLen, 
byte[] rawBody) {
+
+            this.tsSec = tSSec;
+            this.tsUsec = tSUsec;
+            this.inclLen = inclLen;
+            this.origLen = origLen;
+            this.raw_body = rawBody;
+        }
+
+        private void read() {
+            this.tsSec = this.io.readU4le();
+            this.tsUsec = this.io.readU4le();
+            this.inclLen = this.io.readU4le();
+            this.origLen = this.io.readU4le();
+            {
+                Linktype on = root().hdr().network();
+                if (on != null) {
+                    switch (root().hdr().network()) {
+                        case PPI, ETHERNET: {
+                            this.raw_body = this.io.readBytes(
+                                    (inclLen() < root().hdr().snaplen() ? 
inclLen() : root().hdr().snaplen()));
+                            break;
+                        }
+                        default: {
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        private long tsSec;
+        private long tsUsec;
+        private long inclLen;
+        private long origLen;
+        private PCAP root;
+        private PCAP parent;
+        private byte[] raw_body;
+
+        public long tsSec() {
+            return tsSec;
+        }
+
+        public long tsUsec() {
+            return tsUsec;
+        }
+
+        /**
+         * Number of bytes of packet data actually captured and saved in the 
file.
+         */
+        public long inclLen() {
+            return inclLen;
+        }
+
+        /**
+         * Length of the packet as it appeared on the network when it was 
captured.
+         */
+        public long origLen() {
+            return origLen;
+        }
+
+        /**
+         * @see <a href=
+         *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Packet_Data";>Source</a>
+         */
+        public PCAP root() {
+            return root;
+        }
+
+        public PCAP parent() {
+            return parent;
+        }
+
+        public byte[] raw_body() {

Review Comment:
   Per earlier request
   ```suggestion
           public byte[] rawBody() {
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();
+
+        int currentPacketCollectionSize = 0;
+        int totalFlowfileCount = 1;
+        int packetHeaderLength = 24;
+
+        ArrayList<Packet> newPackets = new ArrayList<>();

Review Comment:
   ```suggestion
           List<Packet> newPackets = new ArrayList<>();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();
+
+        int currentPacketCollectionSize = 0;
+        int totalFlowfileCount = 1;
+        int packetHeaderLength = 24;
+
+        ArrayList<Packet> newPackets = new ArrayList<>();
+        templatePcap.packets().clear();
+
+
+        // Loop through all packets in the pcap file and split them into 
smaller pcap files.
+        while (!unprocessedPackets.isEmpty()){
+            var packet = unprocessedPackets.get(0);
+
+            if (packet.inclLen() > pcapMaxSize){
+                session.putAttribute(flowFile,ERROR_REASON, "PCAP contains a 
packet larger than the max size.");
+                session.transfer(flowFile, REL_FAILURE);
+                return;
+            }
+
+            if (currentPacketCollectionSize + (packet.inclLen() + 
packetHeaderLength) > pcapMaxSize && currentPacketCollectionSize > 0){
+                templatePcap.packets().addAll(newPackets);
+                var newFlowFile = session.create(flowFile);
+
+                session.write(newFlowFile, out -> 
out.write(templatePcap.readBytesFull()));
+
+                session.putAttribute(
+                    newFlowFile,
+                    "filename",
+                    flowFile.getAttribute("filename").split("\\.")[0] + "-" + 
totalFlowfileCount + ".pcap"
+                );
+
+                session.transfer(newFlowFile, REL_SUCCESS);
+                totalFlowfileCount += 1;
+
+                newPackets = new ArrayList<>();
+                currentPacketCollectionSize = 0;
+                templatePcap.packets().clear();
+
+            } else {
+                newPackets.add(packet);
+                currentPacketCollectionSize += ((int) packet.inclLen() + 
packetHeaderLength);
+                unprocessedPackets.remove(0);

Review Comment:
   ```suggestion
                   unprocessedPackets.removeFirst();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();
+
+        int currentPacketCollectionSize = 0;
+        int totalFlowfileCount = 1;
+        int packetHeaderLength = 24;
+
+        ArrayList<Packet> newPackets = new ArrayList<>();
+        templatePcap.packets().clear();
+
+
+        // Loop through all packets in the pcap file and split them into 
smaller pcap files.
+        while (!unprocessedPackets.isEmpty()){
+            var packet = unprocessedPackets.get(0);
+
+            if (packet.inclLen() > pcapMaxSize){
+                session.putAttribute(flowFile,ERROR_REASON, "PCAP contains a 
packet larger than the max size.");
+                session.transfer(flowFile, REL_FAILURE);
+                return;
+            }
+
+            if (currentPacketCollectionSize + (packet.inclLen() + 
packetHeaderLength) > pcapMaxSize && currentPacketCollectionSize > 0){

Review Comment:
   ```suggestion
               if (currentPacketCollectionSize + (packet.inclLen() + 
packetHeaderLength) > pcapMaxSize && currentPacketCollectionSize > 0) {
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();
+
+        int currentPacketCollectionSize = 0;
+        int totalFlowfileCount = 1;
+        int packetHeaderLength = 24;
+
+        ArrayList<Packet> newPackets = new ArrayList<>();
+        templatePcap.packets().clear();
+
+
+        // Loop through all packets in the pcap file and split them into 
smaller pcap files.
+        while (!unprocessedPackets.isEmpty()){
+            var packet = unprocessedPackets.get(0);
+
+            if (packet.inclLen() > pcapMaxSize){
+                session.putAttribute(flowFile,ERROR_REASON, "PCAP contains a 
packet larger than the max size.");
+                session.transfer(flowFile, REL_FAILURE);
+                return;
+            }
+
+            if (currentPacketCollectionSize + (packet.inclLen() + 
packetHeaderLength) > pcapMaxSize && currentPacketCollectionSize > 0){
+                templatePcap.packets().addAll(newPackets);
+                var newFlowFile = session.create(flowFile);
+
+                session.write(newFlowFile, out -> 
out.write(templatePcap.readBytesFull()));
+
+                session.putAttribute(
+                    newFlowFile,
+                    "filename",
+                    flowFile.getAttribute("filename").split("\\.")[0] + "-" + 
totalFlowfileCount + ".pcap"
+                );
+
+                session.transfer(newFlowFile, REL_SUCCESS);
+                totalFlowfileCount += 1;
+
+                newPackets = new ArrayList<>();
+                currentPacketCollectionSize = 0;
+                templatePcap.packets().clear();
+
+            } else {
+                newPackets.add(packet);
+                currentPacketCollectionSize += ((int) packet.inclLen() + 
packetHeaderLength);
+                unprocessedPackets.remove(0);
+            }
+        }
+
+        // If there are any packets left over, create a new flowfile.
+        if(!newPackets.isEmpty()){
+            templatePcap.packets().addAll(newPackets);
+            var newFlowFile = session.create(flowFile);
+            session.putAttribute(
+                newFlowFile,
+                "filename",
+                flowFile.getAttribute("filename").split("\\.")[0] + "-" + 
totalFlowfileCount + ".pcap"
+            );

Review Comment:
   All of the split processors (SplitAvro, SplitContent, SplitXml, SplitJson 
and SplitRecord) make use of the 
`org.apache.nifi.flowfile.attributes.FragmentAttributes` enum found in the 
`nifi-utils` which is already included in the `pom.xml` for 
`nifi-network-processors`. Please see the aforementioned processors to see how 
the enum   is used and please include them in `@WritesAttribute` as seen in 
those processor files.



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).

Review Comment:
   Intellij suggests to replace URL with an HTML link.
   ```suggestion
    * produced by tools like [tcpdump](<a 
href="https://www.tcpdump.org/";>...</a>) or
    * [Wireshark](<a href="https://www.wireshark.org/";>...</a>).
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();
+
+        int currentPacketCollectionSize = 0;
+        int totalFlowfileCount = 1;
+        int packetHeaderLength = 24;
+
+        ArrayList<Packet> newPackets = new ArrayList<>();
+        templatePcap.packets().clear();
+
+
+        // Loop through all packets in the pcap file and split them into 
smaller pcap files.
+        while (!unprocessedPackets.isEmpty()){
+            var packet = unprocessedPackets.get(0);

Review Comment:
   ```suggestion
             Packet packet = unprocessedPackets.getFirst();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the maximum size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if(contentByteArray.length == 0){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        PCAP parsedPcap;
+        PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try{
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deepcopy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e){
+            session.putAttribute(flowFile,ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        var unprocessedPackets = parsedPcap.packets();

Review Comment:
   I do not want to discourage Java features, I just think specifying the data 
structure in this case adds clarity.
   ```suggestion
           final List<Packet> unprocessedPackets = parsedPcap.packets();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/Linktype.java:
##########
@@ -0,0 +1,259 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public enum Linktype {
+    NULL_LINKTYPE(0),
+    ETHERNET(1),
+    EXP_ETHERNET(2),
+    AX25(3),
+    PRONET(4),
+    CHAOS(5),
+    IEEE802_5(6),
+    ARCNET_BSD(7),
+    SLIP(8),
+    PPP(9),
+    FDDI(10),
+    REDBACK_SMARTEDGE(32),
+    PPP_HDLC(50),
+    PPP_ETHER(51),
+    SYMANTEC_FIREWALL(99),
+    ATM_RFC1483(100),
+    RAW(101),
+    C_HDLC(104),
+    IEEE802_11(105),
+    ATM_CLIP(106),
+    FRELAY(107),
+    LOOP(108),
+    ENC(109),
+    NETBSD_HDLC(112),
+    LINUX_SLL(113),
+    LTALK(114),
+    ECONET(115),
+    IPFILTER(116),
+    PFLOG(117),
+    CISCO_IOS(118),
+    IEEE802_11_PRISM(119),
+    AIRONET_HEADER(120),
+    IP_OVER_FC(122),
+    SUNATM(123),
+    RIO(124),
+    PCI_EXP(125),
+    AURORA(126),
+    IEEE802_11_RADIOTAP(127),
+    TZSP(128),
+    ARCNET_LINUX(129),
+    JUNIPER_MLPPP(130),
+    JUNIPER_MLFR(131),
+    JUNIPER_ES(132),
+    JUNIPER_GGSN(133),
+    JUNIPER_MFR(134),
+    JUNIPER_ATM2(135),
+    JUNIPER_SERVICES(136),
+    JUNIPER_ATM1(137),
+    APPLE_IP_OVER_IEEE1394(138),
+    MTP2_WITH_PHDR(139),
+    MTP2(140),
+    MTP3(141),
+    SCCP(142),
+    DOCSIS(143),
+    LINUX_IRDA(144),
+    IBM_SP(145),
+    IBM_SN(146),
+    USER0(147),
+    USER1(148),
+    USER2(149),
+    USER3(150),
+    USER4(151),
+    USER5(152),
+    USER6(153),
+    USER7(154),
+    USER8(155),
+    USER9(156),
+    USER10(157),
+    USER11(158),
+    USER12(159),
+    USER13(160),
+    USER14(161),
+    USER15(162),

Review Comment:
   I am not a network expert but I am trying to understand why there are so 
many user entries? Do they each have individual meaning?



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})

Review Comment:
   ```suggestion
   import org.apache.nifi.annotation.behavior.InputRequirement;
   import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
   import org.apache.nifi.annotation.behavior.SideEffectFree;
   import org.apache.nifi.annotation.behavior.WritesAttribute;
   import org.apache.nifi.annotation.documentation.CapabilityDescription;
   import org.apache.nifi.annotation.documentation.Tags;
   import org.apache.nifi.processor.AbstractProcessor;
   import org.apache.nifi.processor.ProcessContext;
   import org.apache.nifi.processor.ProcessSession;
   import org.apache.nifi.processor.Relationship;
   import org.apache.nifi.processor.util.StandardValidators;
   import org.apache.nifi.processors.network.util.PCAP;
   import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
   import org.apache.nifi.processors.network.util.PCAP.Packet;
   
   import java.io.ByteArrayOutputStream;
   import java.util.ArrayList;
   import java.util.List;
   import java.util.Set;
   
   @SideEffectFree
   @InputRequirement(Requirement.INPUT_REQUIRED)
   @Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/SplitPCAP.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.network.util.PCAP;
+import org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface;
+import org.apache.nifi.processors.network.util.PCAP.Packet;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttribute(attribute = SplitPCAP.ERROR_REASON, description = "The reason 
the flowfile was sent to the failure relationship.")
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP_MAX_SIZE")
+            .displayName("PCAP max size (bytes)")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("output flowfiles")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("Flowfiles not parseable as pcap.")
+            .build();
+
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+
+    private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS, 
REL_FAILURE);

Review Comment:
   It seems most of the current split processors (SplitAvro, SplitContent, 
SplitXml, SplitJson and SplitRecord) have 3 relationships `original`, `split` 
and `failure`. Remove the `success` relationship and add the `split` and 
`original` relationships. Please refer to the aforementioned processors to see 
how these relationships are declared and used so the same can be done here.



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+
+    public static class ByteBufferInterface {
+
+        public ByteBufferInterface(byte[] byteArray) {
+            this.buffer = ByteBuffer.wrap(byteArray);
+        }
+
+        public static class ValidationNotEqualError extends Exception {
+            public ValidationNotEqualError(String message) {
+                super(message);
+            }
+        }
+
+        public ByteBuffer buffer;
+
+        public int readU2be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public int readU2le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return (buffer.getShort() & 0xffff);
+        }
+
+        public long readU4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public long readU4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return ((long) buffer.getInt() & 0xffffffffL);
+        }
+
+        public int readS4be() {
+            buffer.order(ByteOrder.BIG_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public int readS4le() {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+            return buffer.getInt();
+        }
+
+        public byte[] readBytes(int n) {
+            byte[] output = new byte[n];
+            buffer.get(output);
+            return output;
+        }
+
+        public byte[] readBytes(long n) {
+            byte[] output = new byte[(int) n];
+            buffer.get(output);
+            return output;
+        }
+
+        public boolean isEof() {
+            return !buffer.hasRemaining();
+        }
+    }
+
+    /**
+     * @see <a href=
+     *      
"https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header";>Source</a>
+     */
+    public static class Header {
+        public ByteBufferInterface io;
+        private Logger logger = LoggerFactory.getLogger(Header.class);
+
+        public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+            this.parent = parent;
+            this.root = root;
+            this.io = io;
+            try {
+                read();
+            } catch 
(org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 e) {
+                this.logger.error("PCAP file header could not be parsed due to 
{}", new Object[] {e});
+            }
+        }
+
+        public Header(byte[] magicNumber, int versionMajor, int versionMinor, 
int thiszone, long sigfigs, long snaplen,
+                String network) {
+
+            Linktype networkEnum = Linktype.RAW;
+            if (EnumUtils.isValidEnum(Linktype.class, network)) {
+                networkEnum = Linktype.valueOf(network);
+            }
+
+            this.magicNumber = magicNumber;
+            this.versionMajor = versionMajor;
+            this.versionMinor = versionMinor;
+            this.thiszone = thiszone;
+            this.sigfigs = sigfigs;
+            this.snaplen = snaplen;
+            this.network = networkEnum;
+        }
+
+        public ByteBufferInterface io() {
+            return io;
+        }
+
+        private void read()
+                throws 
org.apache.nifi.processors.network.util.PCAP.ByteBufferInterface.ValidationNotEqualError
 {

Review Comment:
   ```suggestion
                   throws ByteBufferInterface.ValidationNotEqualError {
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/util/PCAP.java:
##########
@@ -0,0 +1,457 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.commons.lang3.EnumUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ListIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](https://www.tcpdump.org/) or
+ * [Wireshark](https://www.wireshark.org/).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    public ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io){
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network().id(), 4, 
true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        ListIterator<Packet> packetsIterator = packets.listIterator();
+
+        int packetBufferSize = 0;
+
+        for (int loop = 0; loop < packets.size(); loop++) {
+            Packet currentPacket = packetsIterator.next();
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.raw_body().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen, 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen, 4, 
false));
+            currentPacketBytes.put(currentPacket.raw_body());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.raw_body().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int number_of_bytes, boolean 
isSigned) {
+        byte[] output = new byte[number_of_bytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < number_of_bytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }

Review Comment:
   ```suggestion
       private byte[] readIntToNBytes(int input, int numberOfBytes, boolean 
isSigned) {
           byte[] output = new byte[numberOfBytes];
           output[0] = (byte) (input & 0xff);
           for (int loop = 1; loop < numberOfBytes; loop++) {
               if (isSigned) {
                   output[loop] = (byte) (input >> (8 * loop));
               } else {
                   output[loop] = (byte) (input >>> (8 * loop));
               }
           }
           return output;
       }
   
       private byte[] readLongToNBytes(long input, int numberOfBytes, boolean 
isSigned) {
           byte[] output = new byte[numberOfBytes];
           output[0] = (byte) (input & 0xff);
           for (int loop = 1; loop < numberOfBytes; loop++) {
               if (isSigned) {
                   output[loop] = (byte) (input >> (8 * loop));
               } else {
                   output[loop] = (byte) (input >>> (8 * loop));
               }
           }
           return output;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to