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

me.bechberger.ebpf.bpf.raw.bpf_sock_addr 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 bpf_sock_addr {
 *     __u32 user_family;
 *     __u32 user_ip4;
 *     __u32 user_ip6[4];
 *     __u32 user_port;
 *     __u32 family;
 *     __u32 type;
 *     __u32 protocol;
 *     __u32 msg_src_ip4;
 *     __u32 msg_src_ip6[4];
 *     union {
 *         struct bpf_sock *sk;
 *         __u64 : 64;
 *     };
 * }
 * }
 */
public class bpf_sock_addr {

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

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        Lib.C_INT.withName("user_family"),
        Lib.C_INT.withName("user_ip4"),
        MemoryLayout.sequenceLayout(4, Lib.C_INT).withName("user_ip6"),
        Lib.C_INT.withName("user_port"),
        Lib.C_INT.withName("family"),
        Lib.C_INT.withName("type"),
        Lib.C_INT.withName("protocol"),
        Lib.C_INT.withName("msg_src_ip4"),
        MemoryLayout.sequenceLayout(4, Lib.C_INT).withName("msg_src_ip6"),
        MemoryLayout.paddingLayout(4),
        MemoryLayout.unionLayout(
            Lib.C_POINTER.withName("sk")
        ).withName("$anon$6760:2")
    ).withName("bpf_sock_addr");

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

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

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

    private static final long user_family$OFFSET = 0;

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

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

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

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

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

    private static final long user_ip4$OFFSET = 4;

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

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

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

    private static final SequenceLayout user_ip6$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("user_ip6"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static final SequenceLayout user_ip6$layout() {
        return user_ip6$LAYOUT;
    }

    private static final long user_ip6$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static final long user_ip6$offset() {
        return user_ip6$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static MemorySegment user_ip6(MemorySegment struct) {
        return struct.asSlice(user_ip6$OFFSET, user_ip6$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static void user_ip6(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, user_ip6$OFFSET, user_ip6$LAYOUT.byteSize());
    }

    private static long[] user_ip6$DIMS = { 4 };

    /**
     * Dimensions for array field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static long[] user_ip6$dimensions() {
        return user_ip6$DIMS;
    }
    private static final VarHandle user_ip6$ELEM_HANDLE = user_ip6$LAYOUT.varHandle(sequenceElement());

    /**
     * Indexed getter for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static int user_ip6(MemorySegment struct, long index0) {
        return (int)user_ip6$ELEM_HANDLE.get(struct, 0L, index0);
    }

    /**
     * Indexed setter for field:
     * {@snippet lang=c :
     * __u32 user_ip6[4]
     * }
     */
    public static void user_ip6(MemorySegment struct, long index0, int fieldValue) {
        user_ip6$ELEM_HANDLE.set(struct, 0L, index0, fieldValue);
    }

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

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

    private static final long user_port$OFFSET = 24;

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

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

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

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

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

    private static final long family$OFFSET = 28;

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

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

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

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

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

    private static final long type$OFFSET = 32;

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

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

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

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

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

    private static final long protocol$OFFSET = 36;

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

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

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

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

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

    private static final long msg_src_ip4$OFFSET = 40;

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

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

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

    private static final SequenceLayout msg_src_ip6$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("msg_src_ip6"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static final SequenceLayout msg_src_ip6$layout() {
        return msg_src_ip6$LAYOUT;
    }

    private static final long msg_src_ip6$OFFSET = 44;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static final long msg_src_ip6$offset() {
        return msg_src_ip6$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static MemorySegment msg_src_ip6(MemorySegment struct) {
        return struct.asSlice(msg_src_ip6$OFFSET, msg_src_ip6$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static void msg_src_ip6(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, msg_src_ip6$OFFSET, msg_src_ip6$LAYOUT.byteSize());
    }

    private static long[] msg_src_ip6$DIMS = { 4 };

    /**
     * Dimensions for array field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static long[] msg_src_ip6$dimensions() {
        return msg_src_ip6$DIMS;
    }
    private static final VarHandle msg_src_ip6$ELEM_HANDLE = msg_src_ip6$LAYOUT.varHandle(sequenceElement());

    /**
     * Indexed getter for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static int msg_src_ip6(MemorySegment struct, long index0) {
        return (int)msg_src_ip6$ELEM_HANDLE.get(struct, 0L, index0);
    }

    /**
     * Indexed setter for field:
     * {@snippet lang=c :
     * __u32 msg_src_ip6[4]
     * }
     */
    public static void msg_src_ip6(MemorySegment struct, long index0, int fieldValue) {
        msg_src_ip6$ELEM_HANDLE.set(struct, 0L, index0, fieldValue);
    }

    private static final AddressLayout sk$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("$anon$6760:2"), groupElement("sk"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * struct bpf_sock *sk
     * }
     */
    public static final AddressLayout sk$layout() {
        return sk$LAYOUT;
    }

    private static final long sk$OFFSET = 64;

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

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

    /**
     * Setter for field:
     * {@snippet lang=c :
     * struct bpf_sock *sk
     * }
     */
    public static void sk(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(sk$LAYOUT, sk$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