Skip to content
Standard libraryZig 0.17.1Official documentation
Sourcestd/c/illumos.zig

Source line 1

std.c.illumos.AF_SUN

namespace

Source line 114

ELF auxiliary vector flags.

std.c.illumos.AF_SUN.HWCAPVERIFY

constant

Source line 118

hardware capabilities can be verified against AT_SUN_HWCAP

std.c.illumos.AF_SUN.NOPLM

constant

Source line 119

std.c.illumos.AF_SUN.SETUGID

constant

Source line 116

tell ld.so.1 to run "secure" and ignore the environment.

std.c.illumos.assert

alias

Source line 3

Alias of std.debug.assert

std.c.illumos.AT_SUN

namespace

Source line 62

Extensions to the ELF auxiliary vector.

std.c.illumos.AT_SUN.AUXFLAGS

constant

Source line 95

AF_SUN_ flags passed from the kernel

std.c.illumos.AT_SUN.BRAND_AUX1

constant

Source line 101

vectors for brand modules.

std.c.illumos.AT_SUN.BRAND_AUX2

constant

Source line 102

std.c.illumos.AT_SUN.BRAND_AUX3

constant

Source line 103

std.c.illumos.AT_SUN.BRAND_AUX4

constant

Source line 104

std.c.illumos.AT_SUN.BRAND_NROOT

constant

Source line 105

std.c.illumos.AT_SUN.BRANDNAME

constant

Source line 99

name of the brand library for the linker

std.c.illumos.AT_SUN.COMMPAGE

constant

Source line 107

vector for comm page.

std.c.illumos.AT_SUN.CPU

constant

Source line 87

cpu name

std.c.illumos.AT_SUN.EMULATOR

constant

Source line 97

name of the emulation binary for the linker

std.c.illumos.AT_SUN.EXECNAME

constant

Source line 89

exec() path name in the auxv, null terminated.

std.c.illumos.AT_SUN.FPSIZE

constant

Source line 110

std.c.illumos.AT_SUN.FPTYPE

constant

Source line 109

information about the x86 FPU.

std.c.illumos.AT_SUN.GID

constant

Source line 68

effective group id

std.c.illumos.AT_SUN.HWCAP

constant

Source line 82

hints about hardware capabilities.

std.c.illumos.AT_SUN.HWCAP2

constant

Source line 83

std.c.illumos.AT_SUN.IFLUSH

constant

Source line 85

flush icache?

std.c.illumos.AT_SUN.LDDATA

constant

Source line 93

dynamic linkers data segment

std.c.illumos.AT_SUN.LDELF

constant

Source line 72

dynamic linker's ELF header

std.c.illumos.AT_SUN.LDNAME

constant

Source line 76

name of dynamic linker

std.c.illumos.AT_SUN.LDSHDR

constant

Source line 74

dynamic linker's section headers

std.c.illumos.AT_SUN.LPAGESZ

constant

Source line 78

large pagesize

std.c.illumos.AT_SUN.MMU

constant

Source line 91

mmu module name

std.c.illumos.AT_SUN.PLATFORM

constant

Source line 80

platform name

std.c.illumos.AT_SUN.RGID

constant

Source line 70

real group id

std.c.illumos.AT_SUN.RUID

constant

Source line 66

real user id

std.c.illumos.AT_SUN.UID

constant

Source line 64

effective user id

std.c.illumos.builtin

constant

Source line 1

std.c.illumos.ctid_t

alias

Source line 32

Alias of std.c.illumos.id_t

std.c.illumos.fd_t

alias

Source line 5

Alias of std.c.fd_t

std.c.illumos.FILE_EVENT

namespace

Source line 206

User watchable file events.

std.c.illumos.FILE_EVENT.ACCESS

constant

Source line 207

std.c.illumos.FILE_EVENT.ATTRIB

constant

Source line 209

std.c.illumos.FILE_EVENT.DELETE

constant

Source line 210

std.c.illumos.FILE_EVENT.isException

function

Source line 220

pub fn isException(event: u32) bool

Parameters

event: u32

std.c.illumos.FILE_EVENT.MODIFIED

constant

Source line 208

std.c.illumos.FILE_EVENT.MOUNTEDOVER

constant

Source line 218

Some other file/filesystem got mounted over the watched file/directory.

std.c.illumos.FILE_EVENT.NOFOLLOW

constant

Source line 214

std.c.illumos.FILE_EVENT.RENAME_FROM

constant

Source line 212

std.c.illumos.FILE_EVENT.RENAME_TO

constant

Source line 211

std.c.illumos.FILE_EVENT.TRUNC

constant

Source line 213

std.c.illumos.FILE_EVENT.UNMOUNTED

constant

Source line 216

The filesystem holding the watched file was unmounted.

std.c.illumos.file_obj

container

Source line 232

Fields

atim: timespec

Access time.

mtim: timespec

Modification time

ctim: timespec

Change time

__pad: [3]usize
name: [*:0]u8

std.c.illumos.GETCONTEXT

constant

Source line 34

std.c.illumos.GETUSTACK

constant

Source line 36

std.c.illumos.gid_t

alias

Source line 6

Alias of std.c.gid_t

std.c.illumos.id_t

type

Source line 27

std.c.illumos.IFNAMESIZE

alias

Source line 16

Alias of std.c.IFNAMESIZE

std.c.illumos.ino_t

alias

Source line 7

Alias of std.c.ino_t

std.c.illumos.IO

function

Source line 328

pub fn IO(io_type: u8, nr: u8) i32

Parameters

io_type: u8
nr: u8

std.c.illumos.IoCtlCommand

container

Source line 315

Fields

none = 0x20000000
write = 0x40000000
read = 0x80000000
read_write = 0xc0000000

std.c.illumos.ioImpl

function

Source line 322

fn ioImpl(cmd: IoCtlCommand, io_type: u8, nr: u8, comptime IOT: type) i32

Parameters

cmd: IoCtlCommand
io_type: u8
nr: u8
IOT: type

std.c.illumos.IOR

function

Source line 332

pub fn IOR(io_type: u8, nr: u8, comptime IOT: type) i32

Parameters

io_type: u8
nr: u8
IOT: type

std.c.illumos.IOW

function

Source line 336

pub fn IOW(io_type: u8, nr: u8, comptime IOT: type) i32

Parameters

io_type: u8
nr: u8
IOT: type

std.c.illumos.IOWR

function

Source line 340

pub fn IOWR(io_type: u8, nr: u8, comptime IOT: type) i32

Parameters

io_type: u8
nr: u8
IOT: type

std.c.illumos.IP

namespace

Source line 346

std.c.illumos.IP.ADD_MEMBERSHIP

constant

Source line 362

std.c.illumos.IP.ADD_SOURCE_MEMBERSHIP

constant

Source line 366

std.c.illumos.IP.BLOCK_SOURCE

constant

Source line 364

std.c.illumos.IP.BOUND_IF

constant

Source line 374

std.c.illumos.IP.BROADCAST

constant

Source line 380

std.c.illumos.IP.BROADCAST_TTL

constant

Source line 376

std.c.illumos.IP.DEFAULT_MULTICAST_LOOP

constant

Source line 383

std.c.illumos.IP.DEFAULT_MULTICAST_TTL

constant

Source line 382

std.c.illumos.IP.DHCPINIT_IF

constant

Source line 377

std.c.illumos.IP.DONTFRAG

constant

Source line 371

std.c.illumos.IP.DONTROUTE

constant

Source line 379

std.c.illumos.IP.DROP_MEMBERSHIP

constant

Source line 363

std.c.illumos.IP.DROP_SOURCE_MEMBERSHIP

constant

Source line 367

std.c.illumos.IP.HDRINCL

constant

Source line 348

std.c.illumos.IP.MINTTL

constant

Source line 372

std.c.illumos.IP.MULTICAST_IF

constant

Source line 359

std.c.illumos.IP.MULTICAST_LOOP

constant

Source line 361

std.c.illumos.IP.MULTICAST_TTL

constant

Source line 360

std.c.illumos.IP.NEXTHOP

constant

Source line 368

std.c.illumos.IP.OPTIONS

constant

Source line 347

std.c.illumos.IP.PKTINFO

constant

Source line 369

std.c.illumos.IP.RECVDSTADDR

constant

Source line 353

std.c.illumos.IP.RECVIF

constant

Source line 355

std.c.illumos.IP.RECVOPTS

constant

Source line 351

std.c.illumos.IP.RECVPKTINFO

constant

Source line 370

std.c.illumos.IP.RECVRETOPTS

constant

Source line 352

std.c.illumos.IP.RECVSLLA

constant

Source line 356

std.c.illumos.IP.RECVTOS

constant

Source line 358

std.c.illumos.IP.RECVTTL

constant

Source line 357

std.c.illumos.IP.RETOPTS

constant

Source line 354

std.c.illumos.IP.REUSEADDR

constant

Source line 378

std.c.illumos.IP.SEC_OPT

constant

Source line 373

std.c.illumos.IP.TOS

constant

Source line 349

std.c.illumos.IP.TTL

constant

Source line 350

std.c.illumos.IP.UNBLOCK_SOURCE

constant

Source line 365

std.c.illumos.IP.UNSPEC_SRC

constant

Source line 375

std.c.illumos.IPTOS

namespace

Source line 443

std.c.illumos.IPTOS.CE

constant

Source line 448

std.c.illumos.IPTOS.ECT

constant

Source line 447

std.c.illumos.IPTOS.LOWDELAY

constant

Source line 444

std.c.illumos.IPTOS.PREC_CRITIC_ECP

constant

Source line 451

std.c.illumos.IPTOS.PREC_FLASH

constant

Source line 453

std.c.illumos.IPTOS.PREC_FLASHOVERRIDE

constant

Source line 452

std.c.illumos.IPTOS.PREC_IMMEDIATE

constant

Source line 454

std.c.illumos.IPTOS.PREC_INTERNETCONTROL

constant

Source line 450

std.c.illumos.IPTOS.PREC_NETCONTROL

constant

Source line 449

std.c.illumos.IPTOS.PREC_PRIORITY

constant

Source line 455

std.c.illumos.IPTOS.PREC_ROUTINE

constant

Source line 456

std.c.illumos.IPTOS.RELIABILITY

constant

Source line 446

std.c.illumos.IPTOS.THROUGHPUT

constant

Source line 445

std.c.illumos.IPV6

namespace

Source line 388

std.c.illumos.IPV6.ADD_MEMBERSHIP

constant

Source line 395

std.c.illumos.IPV6.BOUND_IF

constant

Source line 422

std.c.illumos.IPV6.CHECKSUM

constant

Source line 410

std.c.illumos.IPV6.DONTFRAG

constant

Source line 413

std.c.illumos.IPV6.DROP_MEMBERSHIP

constant

Source line 396

std.c.illumos.IPV6.DSTOPTS

constant

Source line 401

std.c.illumos.IPV6.HOPLIMIT

constant

Source line 398

std.c.illumos.IPV6.HOPOPTS

constant

Source line 400

std.c.illumos.IPV6.JOIN_GROUP

constant

Source line 393

std.c.illumos.IPV6.LEAVE_GROUP

constant

Source line 394

std.c.illumos.IPV6.MINHOPCOUNT

constant

Source line 421

std.c.illumos.IPV6.MULTICAST_HOPS

constant

Source line 391

std.c.illumos.IPV6.MULTICAST_IF

constant

Source line 390

std.c.illumos.IPV6.MULTICAST_LOOP

constant

Source line 392

std.c.illumos.IPV6.NEXTHOP

constant

Source line 399

std.c.illumos.IPV6.OLD_RECVDSTOPTS

constant

Source line 407

std.c.illumos.IPV6.PATHMTU

constant

Source line 417

std.c.illumos.IPV6.PKTINFO

constant

Source line 397

std.c.illumos.IPV6.PREFER_SRC_CGA

constant

Source line 431

std.c.illumos.IPV6.PREFER_SRC_CGADEFAULT

alias

Source line 437

Alias of std.c.illumos.IPV6.PREFER_SRC_NONCGA

std.c.illumos.IPV6.PREFER_SRC_CGAMASK

constant

Source line 436

std.c.illumos.IPV6.PREFER_SRC_COA

constant

Source line 427

std.c.illumos.IPV6.PREFER_SRC_DEFAULT

constant

Source line 439

std.c.illumos.IPV6.PREFER_SRC_HOME

constant

Source line 426

std.c.illumos.IPV6.PREFER_SRC_MASK

constant

Source line 438

std.c.illumos.IPV6.PREFER_SRC_MIPDEFAULT

alias

Source line 433

Alias of std.c.illumos.IPV6.PREFER_SRC_HOME

std.c.illumos.IPV6.PREFER_SRC_MIPMASK

constant

Source line 432

std.c.illumos.IPV6.PREFER_SRC_NONCGA

constant

Source line 430

std.c.illumos.IPV6.PREFER_SRC_PUBLIC

constant

Source line 428

std.c.illumos.IPV6.PREFER_SRC_TMP

constant

Source line 429

std.c.illumos.IPV6.PREFER_SRC_TMPDEFAULT

alias

Source line 435

Alias of std.c.illumos.IPV6.PREFER_SRC_PUBLIC

std.c.illumos.IPV6.PREFER_SRC_TMPMASK

constant

Source line 434

std.c.illumos.IPV6.RECVDSTOPTS

constant

Source line 420

std.c.illumos.IPV6.RECVHOPLIMIT

constant

Source line 405

std.c.illumos.IPV6.RECVHOPOPTS

constant

Source line 406

std.c.illumos.IPV6.RECVPATHMTU

constant

Source line 416

std.c.illumos.IPV6.RECVPKTINFO

constant

Source line 404

std.c.illumos.IPV6.RECVRTHDR

constant

Source line 408

std.c.illumos.IPV6.RECVRTHDRDSTOPTS

constant

Source line 409

std.c.illumos.IPV6.RECVTCLASS

constant

Source line 411

std.c.illumos.IPV6.RTHDR

constant

Source line 402

std.c.illumos.IPV6.RTHDR_TYPE_0

constant

Source line 425

std.c.illumos.IPV6.RTHDRDSTOPTS

constant

Source line 403

std.c.illumos.IPV6.SEC_OPT

constant

Source line 414

std.c.illumos.IPV6.SRC_PREFERENCES

constant

Source line 415

std.c.illumos.IPV6.TCLASS

constant

Source line 418

std.c.illumos.IPV6.UNICAST_HOPS

constant

Source line 389

std.c.illumos.IPV6.UNSPEC_SRC

constant

Source line 423

std.c.illumos.IPV6.USE_MIN_MTU

constant

Source line 412

std.c.illumos.IPV6.V6ONLY

constant

Source line 419

std.c.illumos.lif_ifinfo_req

container

Source line 258

Fields

maxhops: u8
reachtime: u32
reachretrans: u32
maxmtu: u32

std.c.illumos.lif_nd_req

container

Source line 247

Fields

addr: sockaddr.storage
state_create: u8
state_same_lla: u8
state_diff_lla: u8
hdw_len: i32
flags: i32
__pad: i32
hdw_addr: [64]u8

std.c.illumos.lifreq

container

Source line 266

IP interface request. See if_tcp(7p) for more info.

Fields

ifrn: extern union {
    /// Interface name, e.g. "lo0", "en0".
    name: [IFNAMESIZE]u8,
}
ru1: extern union {
    /// For subnet/token etc.
    addrlen: i32,
    /// Driver's PPA (physical point of attachment).
    ppa: u32,
}
type: u32

One of the IFT types, e.g. IFT_ETHER.

ifru: extern union {
    /// Address.
    addr: sockaddr.storage,
    /// Other end of a peer-to-peer link.
    dstaddr: sockaddr.storage,
    /// Broadcast address.
    broadaddr: sockaddr.storage,
    /// Address token.
    token: sockaddr.storage,
    /// Subnet prefix.
    subnet: sockaddr.storage,
    /// Interface index.
    ivalue: i32,
    /// Flags for SIOC?LIFFLAGS.
    flags: u64,
    /// Hop count metric
    metric: i32,
    /// Maximum transmission unit
    mtu: u32,
    // Technically [2]i32
    muxid: packed struct(u64) { ip: i32, arp: i32 },
    /// Neighbor reachability determination entries
    nd_req: lif_nd_req,
    /// Link info
    ifinfo_req: lif_ifinfo_req,
    /// Name of the multipath interface group
    groupname: [IFNAMESIZE]u8,
    binding: [IFNAMESIZE]u8,
    /// Zone id associated with this interface.
    zoneid: zoneid_t,
    /// Duplicate address detection state. Either in progress or completed.
    dadstate: u32,
}

std.c.illumos.major_t

type

Source line 25

std.c.illumos.minor_t

type

Source line 26

std.c.illumos.mode_t

alias

Source line 8

Alias of std.c.mode_t

std.c.illumos.off_t

alias

Source line 9

Alias of std.c.off_t

std.c.illumos.pid_t

alias

Source line 10

Alias of std.c.pid_t

std.c.illumos.poolid_t

alias

Source line 30

Alias of std.c.illumos.id_t

std.c.illumos.PORT_ALERT

namespace

Source line 200

std.c.illumos.PORT_ALERT.SET

constant

Source line 201

std.c.illumos.PORT_ALERT.UPDATE

constant

Source line 202

std.c.illumos.port_notify

container

Source line 225

Fields

port: u32

Bind request(s) to port.

user: ?*void

User defined variable.

std.c.illumos.PORT_SOURCE

namespace

Source line 190

std.c.illumos.PORT_SOURCE.AIO

constant

Source line 191

std.c.illumos.PORT_SOURCE.ALERT

constant

Source line 195

std.c.illumos.PORT_SOURCE.FD

constant

Source line 194

std.c.illumos.PORT_SOURCE.FILE

constant

Source line 197

std.c.illumos.PORT_SOURCE.MQ

constant

Source line 196

std.c.illumos.PORT_SOURCE.TIMER

constant

Source line 192

std.c.illumos.PORT_SOURCE.USER

constant

Source line 193

std.c.illumos.POSIX_FADV

namespace

Source line 39

std.c.illumos.POSIX_FADV.DONTNEED

constant

Source line 44

std.c.illumos.POSIX_FADV.NOREUSE

constant

Source line 45

std.c.illumos.POSIX_FADV.NORMAL

constant

Source line 40

std.c.illumos.POSIX_FADV.RANDOM

constant

Source line 41

std.c.illumos.POSIX_FADV.SEQUENTIAL

constant

Source line 42

std.c.illumos.POSIX_FADV.WILLNEED

constant

Source line 43

std.c.illumos.priority

container

Source line 48

Fields

PROCESS = 0
PGRP = 1
USER = 2
GROUP = 3
SESSION = 4
LWP = 5
TASK = 6
PROJECT = 7
ZONE = 8
CONTRACT = 9

std.c.illumos.procfs

namespace

Source line 122

std.c.illumos.procfs.fdinfo

container

Source line 141

Fields

fd: fd_t
mode: mode_t
ino: ino_t
size: off_t
offset: off_t
uid: uid_t
gid: gid_t
dev_major: major_t
dev_minor: minor_t
special_major: major_t
special_minor: minor_t
fileflags: i32
fdflags: i32
locktype: i16
lockpid: pid_t
locksysid: i32
peerpid: pid_t
__filler: [25]c_int
peername: [15:0]u8
misc: [1]u8

std.c.illumos.procfs.misc_header

container

Source line 123

Fields

size: u32
type: enum(u32) {
    Pathname,
    Socketname,
    Peersockname,
    SockoptsBoolOpts,
    SockoptLinger,
    SockoptSndbuf,
    SockoptRcvbuf,
    SockoptIpNexthop,
    SockoptIpv6Nexthop,
    SockoptType,
    SockoptTcpCongestion,
    SockfiltersPriv = 14,
}

std.c.illumos.projid_t

alias

Source line 29

Alias of std.c.illumos.id_t

std.c.illumos.pthread_setname_np

function

Source line 22

pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int

Parameters

thread: pthread_t
name: [*:0]const u8
arg: ?*anyopaque

std.c.illumos.pthread_t

alias

Source line 11

Alias of std.c.pthread_t

std.c.illumos.SETCONTEXT

constant

Source line 35

std.c.illumos.SETUSTACK

constant

Source line 37

std.c.illumos.SFD

namespace

Source line 165

std.c.illumos.SFD.CLOEXEC

constant

Source line 166

std.c.illumos.SFD.NONBLOCK

constant

Source line 167

std.c.illumos.signalfd_siginfo

container

Source line 170

Fields

signo: u32
errno: i32
code: i32
pid: u32
uid: uid_t
fd: i32
tid: u32
band: u32
overrun: u32
trapno: u32
status: i32
int: i32
ptr: u64
utime: u64
stime: u64
addr: u64
__pad: [48]u8

std.c.illumos.SIOCGLIFINDEX

constant

Source line 245

std.c.illumos.SO

alias

Source line 4

Alias of std.c.SO

std.c.illumos.sockaddr

alias

Source line 12

Alias of std.c.sockaddr

std.c.illumos.socklen_t

alias

Source line 13

Alias of std.c.socklen_t

std.c.illumos.std

alias

Source line 2

Alias of std

std.c.illumos.sysconf

function

Source line 23

pub extern "c" fn sysconf(sc: c_int) i64

Parameters

sc: c_int

std.c.illumos.taskid_t

alias

Source line 28

Alias of std.c.illumos.id_t

std.c.illumos.TCP

namespace

Source line 460

std.c.illumos.TCP.ABORT_THRESHOLD

constant

Source line 465

std.c.illumos.TCP.ANONPRIVBIND

constant

Source line 477

std.c.illumos.TCP.CONGESTION

constant

Source line 482

std.c.illumos.TCP.CONN_ABORT_THRESHOLD

constant

Source line 467

std.c.illumos.TCP.CONN_NOTIFY_THRESHOLD

constant

Source line 466

std.c.illumos.TCP.CORK

constant

Source line 472

std.c.illumos.TCP.EXCLBIND

constant

Source line 478

std.c.illumos.TCP.INIT_CWND

constant

Source line 469

std.c.illumos.TCP.KEEPALIVE

constant

Source line 463

std.c.illumos.TCP.KEEPALIVE_ABORT_THRESHOLD

constant

Source line 471

std.c.illumos.TCP.KEEPALIVE_THRESHOLD

constant

Source line 470

std.c.illumos.TCP.KEEPCNT

constant

Source line 480

std.c.illumos.TCP.KEEPIDLE

constant

Source line 479

std.c.illumos.TCP.KEEPINTVL

constant

Source line 481

std.c.illumos.TCP.LINGER2

constant

Source line 476

std.c.illumos.TCP.MAXSEG

constant

Source line 462

std.c.illumos.TCP.MD5SIG

constant

Source line 484

std.c.illumos.TCP.NODELAY

constant

Source line 461

std.c.illumos.TCP.NOTIFY_THRESHOLD

constant

Source line 464

std.c.illumos.TCP.QUICKACK

constant

Source line 483

std.c.illumos.TCP.RECVDSTADDR

constant

Source line 468

std.c.illumos.TCP.RTO_INITIAL

constant

Source line 473

std.c.illumos.TCP.RTO_MAX

constant

Source line 475

std.c.illumos.TCP.RTO_MIN

constant

Source line 474

std.c.illumos.timespec

alias

Source line 14

Alias of std.c.timespec

std.c.illumos.uid_t

alias

Source line 15

Alias of std.c.uid_t

std.c.illumos.zoneid_t

alias

Source line 31

Alias of std.c.illumos.id_t

Source code

std/c/illumos.zig

const builtin = @import("builtin");
const std = @import("../std.zig");
const assert = std.debug.assert;
const SO = std.c.SO;
const fd_t = std.c.fd_t;
const gid_t = std.c.gid_t;
const ino_t = std.c.ino_t;
const mode_t = std.c.mode_t;
const off_t = std.c.off_t;
const pid_t = std.c.pid_t;
const pthread_t = std.c.pthread_t;
const sockaddr = std.c.sockaddr;
const socklen_t = std.c.socklen_t;
const timespec = std.c.timespec;
const uid_t = std.c.uid_t;
const IFNAMESIZE = std.c.IFNAMESIZE;

comptime {
    assert(builtin.os.tag == .illumos); // Prevent access of std.c symbols on wrong OS.
}

pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
pub extern "c" fn sysconf(sc: c_int) i64;

pub const major_t = u32;
pub const minor_t = u32;
pub const id_t = i32;
pub const taskid_t = id_t;
pub const projid_t = id_t;
pub const poolid_t = id_t;
pub const zoneid_t = id_t;
pub const ctid_t = id_t;

pub const GETCONTEXT = 0;
pub const SETCONTEXT = 1;
pub const GETUSTACK = 2;
pub const SETUSTACK = 3;

pub const POSIX_FADV = struct {
    pub const NORMAL = 0;
    pub const RANDOM = 1;
    pub const SEQUENTIAL = 2;
    pub const WILLNEED = 3;
    pub const DONTNEED = 4;
    pub const NOREUSE = 5;
};

pub const priority = enum(c_int) {
    PROCESS = 0,
    PGRP = 1,
    USER = 2,
    GROUP = 3,
    SESSION = 4,
    LWP = 5,
    TASK = 6,
    PROJECT = 7,
    ZONE = 8,
    CONTRACT = 9,
};

/// Extensions to the ELF auxiliary vector.
pub const AT_SUN = struct {
    /// effective user id
    pub const UID = 2000;
    /// real user id
    pub const RUID = 2001;
    /// effective group id
    pub const GID = 2002;
    /// real group id
    pub const RGID = 2003;
    /// dynamic linker's ELF header
    pub const LDELF = 2004;
    /// dynamic linker's section headers
    pub const LDSHDR = 2005;
    /// name of dynamic linker
    pub const LDNAME = 2006;
    /// large pagesize
    pub const LPAGESZ = 2007;
    /// platform name
    pub const PLATFORM = 2008;
    /// hints about hardware capabilities.
    pub const HWCAP = 2009;
    pub const HWCAP2 = 2023;
    /// flush icache?
    pub const IFLUSH = 2010;
    /// cpu name
    pub const CPU = 2011;
    /// exec() path name in the auxv, null terminated.
    pub const EXECNAME = 2014;
    /// mmu module name
    pub const MMU = 2015;
    /// dynamic linkers data segment
    pub const LDDATA = 2016;
    /// AF_SUN_ flags passed from the kernel
    pub const AUXFLAGS = 2017;
    /// name of the emulation binary for the linker
    pub const EMULATOR = 2018;
    /// name of the brand library for the linker
    pub const BRANDNAME = 2019;
    /// vectors for brand modules.
    pub const BRAND_AUX1 = 2020;
    pub const BRAND_AUX2 = 2021;
    pub const BRAND_AUX3 = 2022;
    pub const BRAND_AUX4 = 2025;
    pub const BRAND_NROOT = 2024;
    /// vector for comm page.
    pub const COMMPAGE = 2026;
    /// information about the x86 FPU.
    pub const FPTYPE = 2027;
    pub const FPSIZE = 2028;
};

/// ELF auxiliary vector flags.
pub const AF_SUN = struct {
    /// tell ld.so.1 to run "secure" and ignore the environment.
    pub const SETUGID = 0x00000001;
    /// hardware capabilities can be verified against AT_SUN_HWCAP
    pub const HWCAPVERIFY = 0x00000002;
    pub const NOPLM = 0x00000004;
};

pub const procfs = struct {
    pub const misc_header = extern struct {
        size: u32,
        type: enum(u32) {
            Pathname,
            Socketname,
            Peersockname,
            SockoptsBoolOpts,
            SockoptLinger,
            SockoptSndbuf,
            SockoptRcvbuf,
            SockoptIpNexthop,
            SockoptIpv6Nexthop,
            SockoptType,
            SockoptTcpCongestion,
            SockfiltersPriv = 14,
        },
    };

    pub const fdinfo = extern struct {
        fd: fd_t,
        mode: mode_t,
        ino: ino_t,
        size: off_t,
        offset: off_t,
        uid: uid_t,
        gid: gid_t,
        dev_major: major_t,
        dev_minor: minor_t,
        special_major: major_t,
        special_minor: minor_t,
        fileflags: i32,
        fdflags: i32,
        locktype: i16,
        lockpid: pid_t,
        locksysid: i32,
        peerpid: pid_t,
        __filler: [25]c_int,
        peername: [15:0]u8,
        misc: [1]u8,
    };
};

pub const SFD = struct {
    pub const CLOEXEC = 0o2000000;
    pub const NONBLOCK = 0o4000;
};

pub const signalfd_siginfo = extern struct {
    signo: u32,
    errno: i32,
    code: i32,
    pid: u32,
    uid: uid_t,
    fd: i32,
    tid: u32, // unused
    band: u32,
    overrun: u32, // unused
    trapno: u32,
    status: i32,
    int: i32, // unused
    ptr: u64, // unused
    utime: u64,
    stime: u64,
    addr: u64,
    __pad: [48]u8,
};

pub const PORT_SOURCE = struct {
    pub const AIO = 1;
    pub const TIMER = 2;
    pub const USER = 3;
    pub const FD = 4;
    pub const ALERT = 5;
    pub const MQ = 6;
    pub const FILE = 7;
};

pub const PORT_ALERT = struct {
    pub const SET = 0x01;
    pub const UPDATE = 0x02;
};

/// User watchable file events.
pub const FILE_EVENT = struct {
    pub const ACCESS = 0x00000001;
    pub const MODIFIED = 0x00000002;
    pub const ATTRIB = 0x00000004;
    pub const DELETE = 0x00000010;
    pub const RENAME_TO = 0x00000020;
    pub const RENAME_FROM = 0x00000040;
    pub const TRUNC = 0x00100000;
    pub const NOFOLLOW = 0x10000000;
    /// The filesystem holding the watched file was unmounted.
    pub const UNMOUNTED = 0x20000000;
    /// Some other file/filesystem got mounted over the watched file/directory.
    pub const MOUNTEDOVER = 0x40000000;

    pub fn isException(event: u32) bool {
        return event & (UNMOUNTED | DELETE | RENAME_TO | RENAME_FROM | MOUNTEDOVER) > 0;
    }
};

pub const port_notify = extern struct {
    /// Bind request(s) to port.
    port: u32,
    /// User defined variable.
    user: ?*void,
};

pub const file_obj = extern struct {
    /// Access time.
    atim: timespec,
    /// Modification time
    mtim: timespec,
    /// Change time
    ctim: timespec,
    __pad: [3]usize,
    name: [*:0]u8,
};

// struct ifreq is marked obsolete, with struct lifreq preferred for interface requests.
// Here we alias lifreq to ifreq to avoid chainging existing code in os and x.os.IPv6.
pub const SIOCGLIFINDEX = IOWR('i', 133, lifreq);

pub const lif_nd_req = extern struct {
    addr: sockaddr.storage,
    state_create: u8,
    state_same_lla: u8,
    state_diff_lla: u8,
    hdw_len: i32,
    flags: i32,
    __pad: i32,
    hdw_addr: [64]u8,
};

pub const lif_ifinfo_req = extern struct {
    maxhops: u8,
    reachtime: u32,
    reachretrans: u32,
    maxmtu: u32,
};

/// IP interface request. See if_tcp(7p) for more info.
pub const lifreq = extern struct {
    // Not actually in a union, but the stdlib expects one for ifreq
    ifrn: extern union {
        /// Interface name, e.g. "lo0", "en0".
        name: [IFNAMESIZE]u8,
    },
    ru1: extern union {
        /// For subnet/token etc.
        addrlen: i32,
        /// Driver's PPA (physical point of attachment).
        ppa: u32,
    },
    /// One of the IFT types, e.g. IFT_ETHER.
    type: u32,
    ifru: extern union {
        /// Address.
        addr: sockaddr.storage,
        /// Other end of a peer-to-peer link.
        dstaddr: sockaddr.storage,
        /// Broadcast address.
        broadaddr: sockaddr.storage,
        /// Address token.
        token: sockaddr.storage,
        /// Subnet prefix.
        subnet: sockaddr.storage,
        /// Interface index.
        ivalue: i32,
        /// Flags for SIOC?LIFFLAGS.
        flags: u64,
        /// Hop count metric
        metric: i32,
        /// Maximum transmission unit
        mtu: u32,
        // Technically [2]i32
        muxid: packed struct(u64) { ip: i32, arp: i32 },
        /// Neighbor reachability determination entries
        nd_req: lif_nd_req,
        /// Link info
        ifinfo_req: lif_ifinfo_req,
        /// Name of the multipath interface group
        groupname: [IFNAMESIZE]u8,
        binding: [IFNAMESIZE]u8,
        /// Zone id associated with this interface.
        zoneid: zoneid_t,
        /// Duplicate address detection state. Either in progress or completed.
        dadstate: u32,
    },
};

const IoCtlCommand = enum(u32) {
    none = 0x20000000, // no parameters
    write = 0x40000000, // copy out parameters
    read = 0x80000000, // copy in parameters
    read_write = 0xc0000000,
};

fn ioImpl(cmd: IoCtlCommand, io_type: u8, nr: u8, comptime IOT: type) i32 {
    const size = @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IOT))))) << 16;
    const t = @as(u32, @intCast(io_type)) << 8;
    return @as(i32, @bitCast(@backingInt(cmd) | size | t | nr));
}

pub fn IO(io_type: u8, nr: u8) i32 {
    return ioImpl(.none, io_type, nr, void);
}

pub fn IOR(io_type: u8, nr: u8, comptime IOT: type) i32 {
    return ioImpl(.write, io_type, nr, IOT);
}

pub fn IOW(io_type: u8, nr: u8, comptime IOT: type) i32 {
    return ioImpl(.read, io_type, nr, IOT);
}

pub fn IOWR(io_type: u8, nr: u8, comptime IOT: type) i32 {
    return ioImpl(.read_write, io_type, nr, IOT);
}

// https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/netinet/in.h#L1141
// (old OpenSolaris is very similar, it's just missing a few more-modern ones, and probably modern Solaris has those)
pub const IP = struct {
    pub const OPTIONS = 1;
    pub const HDRINCL = 2;
    pub const TOS = 3;
    pub const TTL = 4;
    pub const RECVOPTS = 0x5;
    pub const RECVRETOPTS = 0x6;
    pub const RECVDSTADDR = 0x7;
    pub const RETOPTS = 0x8;
    pub const RECVIF = 0x9;
    pub const RECVSLLA = 0xa;
    pub const RECVTTL = 0xb;
    pub const RECVTOS = 0xc;
    pub const MULTICAST_IF = 0x10;
    pub const MULTICAST_TTL = 0x11;
    pub const MULTICAST_LOOP = 0x12;
    pub const ADD_MEMBERSHIP = 0x13;
    pub const DROP_MEMBERSHIP = 0x14;
    pub const BLOCK_SOURCE = 0x15;
    pub const UNBLOCK_SOURCE = 0x16;
    pub const ADD_SOURCE_MEMBERSHIP = 0x17;
    pub const DROP_SOURCE_MEMBERSHIP = 0x18;
    pub const NEXTHOP = 0x19;
    pub const PKTINFO = 0x1a;
    pub const RECVPKTINFO = 0x1a;
    pub const DONTFRAG = 0x1b;
    pub const MINTTL = 0x1c;
    pub const SEC_OPT = 0x22;
    pub const BOUND_IF = 0x41;
    pub const UNSPEC_SRC = 0x42;
    pub const BROADCAST_TTL = 0x43;
    pub const DHCPINIT_IF = 0x45;
    pub const REUSEADDR = 0x104;
    pub const DONTROUTE = 0x105;
    pub const BROADCAST = 0x106;
    // Same namespace, but these are arguments rather than option names
    pub const DEFAULT_MULTICAST_TTL = 1;
    pub const DEFAULT_MULTICAST_LOOP = 1;
};

// https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/netinet/in.h#L1192
// (old OpenSolaris is very similar, it's just missing a few more-modern ones, and probably modern Solaris has those)
pub const IPV6 = struct {
    pub const UNICAST_HOPS = 0x5;
    pub const MULTICAST_IF = 0x6;
    pub const MULTICAST_HOPS = 0x7;
    pub const MULTICAST_LOOP = 0x8;
    pub const JOIN_GROUP = 0x9;
    pub const LEAVE_GROUP = 0xa;
    pub const ADD_MEMBERSHIP = 0x9;
    pub const DROP_MEMBERSHIP = 0xa;
    pub const PKTINFO = 0xb;
    pub const HOPLIMIT = 0xc;
    pub const NEXTHOP = 0xd;
    pub const HOPOPTS = 0xe;
    pub const DSTOPTS = 0xf;
    pub const RTHDR = 0x10;
    pub const RTHDRDSTOPTS = 0x11;
    pub const RECVPKTINFO = 0x12;
    pub const RECVHOPLIMIT = 0x13;
    pub const RECVHOPOPTS = 0x14;
    pub const OLD_RECVDSTOPTS = 0x15;
    pub const RECVRTHDR = 0x16;
    pub const RECVRTHDRDSTOPTS = 0x17;
    pub const CHECKSUM = 0x18;
    pub const RECVTCLASS = 0x19;
    pub const USE_MIN_MTU = 0x20;
    pub const DONTFRAG = 0x21;
    pub const SEC_OPT = 0x22;
    pub const SRC_PREFERENCES = 0x23;
    pub const RECVPATHMTU = 0x24;
    pub const PATHMTU = 0x25;
    pub const TCLASS = 0x26;
    pub const V6ONLY = 0x27;
    pub const RECVDSTOPTS = 0x28;
    pub const MINHOPCOUNT = 0x2f;
    pub const BOUND_IF = 0x41;
    pub const UNSPEC_SRC = 0x42;
    // Same namespace, but these are arguments rather than option names
    pub const RTHDR_TYPE_0 = 0;
    pub const PREFER_SRC_HOME = 0x01;
    pub const PREFER_SRC_COA = 0x02;
    pub const PREFER_SRC_PUBLIC = 0x04;
    pub const PREFER_SRC_TMP = 0x08;
    pub const PREFER_SRC_NONCGA = 0x10;
    pub const PREFER_SRC_CGA = 0x20;
    pub const PREFER_SRC_MIPMASK = PREFER_SRC_HOME | PREFER_SRC_COA;
    pub const PREFER_SRC_MIPDEFAULT = PREFER_SRC_HOME;
    pub const PREFER_SRC_TMPMASK = PREFER_SRC_PUBLIC | PREFER_SRC_TMP;
    pub const PREFER_SRC_TMPDEFAULT = PREFER_SRC_PUBLIC;
    pub const PREFER_SRC_CGAMASK = PREFER_SRC_NONCGA | PREFER_SRC_CGA;
    pub const PREFER_SRC_CGADEFAULT = PREFER_SRC_NONCGA;
    pub const PREFER_SRC_MASK = PREFER_SRC_MIPMASK | PREFER_SRC_TMPMASK | PREFER_SRC_CGAMASK;
    pub const PREFER_SRC_DEFAULT = PREFER_SRC_MIPDEFAULT | PREFER_SRC_TMPDEFAULT | PREFER_SRC_CGADEFAULT;
};

// https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/netinet/ip.h#L64
pub const IPTOS = struct {
    pub const LOWDELAY = 0x10;
    pub const THROUGHPUT = 0x08;
    pub const RELIABILITY = 0x04;
    pub const ECT = 0x02;
    pub const CE = 0x01;
    pub const PREC_NETCONTROL = 0xe0;
    pub const PREC_INTERNETCONTROL = 0xc0;
    pub const PREC_CRITIC_ECP = 0xa0;
    pub const PREC_FLASHOVERRIDE = 0x80;
    pub const PREC_FLASH = 0x60;
    pub const PREC_IMMEDIATE = 0x40;
    pub const PREC_PRIORITY = 0x20;
    pub const PREC_ROUTINE = 0x00;
};

// https://github.com/illumos/illumos-gate/blob/e1e6b944360d951edf36ef4198261818ed2d9b2f/usr/src/uts/common/netinet/tcp.h#L94
pub const TCP = struct {
    pub const NODELAY = 0x01;
    pub const MAXSEG = 0x02;
    pub const KEEPALIVE = 0x8;
    pub const NOTIFY_THRESHOLD = 0x10;
    pub const ABORT_THRESHOLD = 0x11;
    pub const CONN_NOTIFY_THRESHOLD = 0x12;
    pub const CONN_ABORT_THRESHOLD = 0x13;
    pub const RECVDSTADDR = 0x14;
    pub const INIT_CWND = 0x15;
    pub const KEEPALIVE_THRESHOLD = 0x16;
    pub const KEEPALIVE_ABORT_THRESHOLD = 0x17;
    pub const CORK = 0x18;
    pub const RTO_INITIAL = 0x19;
    pub const RTO_MIN = 0x1A;
    pub const RTO_MAX = 0x1B;
    pub const LINGER2 = 0x1C;
    pub const ANONPRIVBIND = 0x20;
    pub const EXCLBIND = 0x21;
    pub const KEEPIDLE = 0x22;
    pub const KEEPCNT = 0x23;
    pub const KEEPINTVL = 0x24;
    pub const CONGESTION = 0x25;
    pub const QUICKACK = 0x26;
    pub const MD5SIG = 0x27;
};