All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.bechberger.ebpf.bpf.raw.tcphdr Maven / Gradle / Ivy

The newest version!
// Generated by jextract

package me.bechberger.ebpf.bpf.raw;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct tcphdr {
 *     __be16 source;
 *     __be16 dest;
 *     __be32 seq;
 *     __be32 ack_seq;
 *     __u16 res1 : 4;
 *     __u16 doff : 4;
 *     __u16 fin : 1;
 *     __u16 syn : 1;
 *     __u16 rst : 1;
 *     __u16 psh : 1;
 *     __u16 ack : 1;
 *     __u16 urg : 1;
 *     __u16 ece : 1;
 *     __u16 cwr : 1;
 *     __be16 window;
 *     __sum16 check;
 *     __be16 urg_ptr;
 * }
 * }
 */
public class tcphdr {

    tcphdr() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        Lib.C_SHORT.withName("source"),
        Lib.C_SHORT.withName("dest"),
        Lib.C_INT.withName("seq"),
        Lib.C_INT.withName("ack_seq"),
        MemoryLayout.paddingLayout(2),
        Lib.C_SHORT.withName("window"),
        Lib.C_SHORT.withName("check"),
        Lib.C_SHORT.withName("urg_ptr")
    ).withName("tcphdr");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfShort source$LAYOUT = (OfShort)$LAYOUT.select(groupElement("source"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be16 source
     * }
     */
    public static final OfShort source$layout() {
        return source$LAYOUT;
    }

    private static final long source$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be16 source
     * }
     */
    public static final long source$offset() {
        return source$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be16 source
     * }
     */
    public static short source(MemorySegment struct) {
        return struct.get(source$LAYOUT, source$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be16 source
     * }
     */
    public static void source(MemorySegment struct, short fieldValue) {
        struct.set(source$LAYOUT, source$OFFSET, fieldValue);
    }

    private static final OfShort dest$LAYOUT = (OfShort)$LAYOUT.select(groupElement("dest"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be16 dest
     * }
     */
    public static final OfShort dest$layout() {
        return dest$LAYOUT;
    }

    private static final long dest$OFFSET = 2;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be16 dest
     * }
     */
    public static final long dest$offset() {
        return dest$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be16 dest
     * }
     */
    public static short dest(MemorySegment struct) {
        return struct.get(dest$LAYOUT, dest$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be16 dest
     * }
     */
    public static void dest(MemorySegment struct, short fieldValue) {
        struct.set(dest$LAYOUT, dest$OFFSET, fieldValue);
    }

    private static final OfInt seq$LAYOUT = (OfInt)$LAYOUT.select(groupElement("seq"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be32 seq
     * }
     */
    public static final OfInt seq$layout() {
        return seq$LAYOUT;
    }

    private static final long seq$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be32 seq
     * }
     */
    public static final long seq$offset() {
        return seq$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be32 seq
     * }
     */
    public static int seq(MemorySegment struct) {
        return struct.get(seq$LAYOUT, seq$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be32 seq
     * }
     */
    public static void seq(MemorySegment struct, int fieldValue) {
        struct.set(seq$LAYOUT, seq$OFFSET, fieldValue);
    }

    private static final OfInt ack_seq$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ack_seq"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be32 ack_seq
     * }
     */
    public static final OfInt ack_seq$layout() {
        return ack_seq$LAYOUT;
    }

    private static final long ack_seq$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be32 ack_seq
     * }
     */
    public static final long ack_seq$offset() {
        return ack_seq$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be32 ack_seq
     * }
     */
    public static int ack_seq(MemorySegment struct) {
        return struct.get(ack_seq$LAYOUT, ack_seq$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be32 ack_seq
     * }
     */
    public static void ack_seq(MemorySegment struct, int fieldValue) {
        struct.set(ack_seq$LAYOUT, ack_seq$OFFSET, fieldValue);
    }

    private static final OfShort window$LAYOUT = (OfShort)$LAYOUT.select(groupElement("window"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be16 window
     * }
     */
    public static final OfShort window$layout() {
        return window$LAYOUT;
    }

    private static final long window$OFFSET = 14;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be16 window
     * }
     */
    public static final long window$offset() {
        return window$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be16 window
     * }
     */
    public static short window(MemorySegment struct) {
        return struct.get(window$LAYOUT, window$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be16 window
     * }
     */
    public static void window(MemorySegment struct, short fieldValue) {
        struct.set(window$LAYOUT, window$OFFSET, fieldValue);
    }

    private static final OfShort check$LAYOUT = (OfShort)$LAYOUT.select(groupElement("check"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __sum16 check
     * }
     */
    public static final OfShort check$layout() {
        return check$LAYOUT;
    }

    private static final long check$OFFSET = 16;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __sum16 check
     * }
     */
    public static final long check$offset() {
        return check$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __sum16 check
     * }
     */
    public static short check(MemorySegment struct) {
        return struct.get(check$LAYOUT, check$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __sum16 check
     * }
     */
    public static void check(MemorySegment struct, short fieldValue) {
        struct.set(check$LAYOUT, check$OFFSET, fieldValue);
    }

    private static final OfShort urg_ptr$LAYOUT = (OfShort)$LAYOUT.select(groupElement("urg_ptr"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be16 urg_ptr
     * }
     */
    public static final OfShort urg_ptr$layout() {
        return urg_ptr$LAYOUT;
    }

    private static final long urg_ptr$OFFSET = 18;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be16 urg_ptr
     * }
     */
    public static final long urg_ptr$offset() {
        return urg_ptr$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be16 urg_ptr
     * }
     */
    public static short urg_ptr(MemorySegment struct) {
        return struct.get(urg_ptr$LAYOUT, urg_ptr$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be16 urg_ptr
     * }
     */
    public static void urg_ptr(MemorySegment struct, short fieldValue) {
        struct.set(urg_ptr$LAYOUT, urg_ptr$OFFSET, fieldValue);
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy