package org.xbib.net.socket.v4.unix;

import com.sun.jna.Structure;
import java.util.List;

/**
 * sockaddr_un
 */
public class SocketAddressUnix extends Structure {

    public short family; // AF_UNIX

    public final byte[] path = new byte[108];

    public SocketAddressUnix(String path) {
        this.family = 1;
        setPath(path);
    }

    public void setPath(String sunPath) {
        System.arraycopy((sunPath + "\u0000").getBytes(), 0, this.path, 0, sunPath.length());
    }

    public short getFamily() {
        return family;
    }

    public byte[] getPath() {
        return path;
    }

    @Override
    protected List<String> getFieldOrder() {
        return List.of("family", "path");
    }
}
