io.netty.handler.pcap.PcapHeaders Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
/*
* Copyright 2020 The Netty Project
*
* The Netty Project 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:
*
* https://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 io.netty.handler.pcap;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.io.OutputStream;
final class PcapHeaders {
/**
* Pcap Global Header built from:
*
* - magic_number
* - version_major
* - version_minor
* - thiszone
* - sigfigs
* - snaplen
* - network
*
*/
private static final byte[] GLOBAL_HEADER = {-95, -78, -61, -44, 0, 2, 0, 4, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 1};
private PcapHeaders() {
// Prevent outside initialization
}
/**
* Writes the Pcap Global Header to the provided {@code OutputStream}
*
* @param outputStream OutputStream where Pcap data will be written.
* @throws IOException if there is an error writing to the {@code OutputStream}
*/
static void writeGlobalHeader(OutputStream outputStream) throws IOException {
outputStream.write(GLOBAL_HEADER);
}
/**
* Write Pcap Packet Header
*
* @param byteBuf ByteBuf where we'll write header data
* @param ts_sec timestamp seconds
* @param ts_usec timestamp microseconds
* @param incl_len number of octets of packet saved in file
* @param orig_len actual length of packet
*/
static void writePacketHeader(ByteBuf byteBuf, int ts_sec, int ts_usec, int incl_len, int orig_len) {
byteBuf.writeInt(ts_sec);
byteBuf.writeInt(ts_usec);
byteBuf.writeInt(incl_len);
byteBuf.writeInt(orig_len);
}
}