From e1c0f13ae54ced1505abb1934e3ae7e0f8d118a2 Mon Sep 17 00:00:00 2001 From: Brandon Black Date: Thu, 3 Sep 2026 10:37:53 -0500 Subject: [PATCH] std.c: define TCP options for several OSes Primary motivation was the lack of TCP.NODELAY on multiple targets that should have it. Note that FreeBSD has a much larger set of defines in the "TCP_" namespace than what I've pasted here, including a bunch of non-option constants and extremely platform-specific features. I stuck to just the simpler and more traditional options only for now. The rest could be added later, and may need some thought as how to best represent them. --- lib/std/c.zig | 6 ++++++ lib/std/c/dragonfly.zig | 14 ++++++++++++++ lib/std/c/freebsd.zig | 43 +++++++++++++++++++++++++++++++++++++++++ lib/std/c/haiku.zig | 8 ++++++++ lib/std/c/illumos.zig | 28 +++++++++++++++++++++++++++ lib/std/c/netbsd.zig | 13 +++++++++++++ lib/std/c/openbsd.zig | 10 ++++++++++ 7 files changed, 122 insertions(+) diff --git a/lib/std/c.zig b/lib/std/c.zig index 5fcefbf03ed0f0b3e86b7ee228f901fcd0b38e2f..e3625edb869186614eb961174748f5fcab77f5b4 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -5997,8 +5997,14 @@ pub const SOCK = switch (native_os) { pub const TCP = switch (native_os) { .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.TCP, .linux => linux.TCP, + .freebsd => freebsd.TCP, + .netbsd => netbsd.TCP, + .openbsd => openbsd.TCP, + .dragonfly => dragonfly.TCP, .emscripten => emscripten.TCP, .windows => ws2_32.TCP, + .illumos => illumos.TCP, + .haiku => haiku.TCP, // https://github.com/SerenityOS/serenity/blob/61ac554a3403838f79ca746bd1c65ded6f97d124/Kernel/API/POSIX/netinet/tcp.h#L13-L14 .serenity => struct { pub const NODELAY = 10; diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 40fb9c8b836bdda8f2bbccaac8c6c2dbd5285d92..75ace2565a5439267930563e8b647df025091c28 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -302,3 +302,17 @@ pub const IPTOS = struct { pub const ECN_CE = 0x03; pub const ECN_MASK = 0x03; }; + +// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/8410ea0817ce17438e0a10fc4ba6c9697281048a/sys/netinet/tcp.h#L156 +pub const TCP = struct { + pub const NODELAY = 0x01; + pub const MAXSEG = 0x02; + pub const NOPUSH = 0x04; + pub const NOOPT = 0x08; + pub const SIGNATURE_ENABLE = 0x10; + pub const KEEPINIT = 0x20; + pub const FASTKEEP = 0x80; + pub const KEEPIDLE = 0x100; + pub const KEEPINTVL = 0x200; + pub const KEEPCNT = 0x400; +}; diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index ad67b23a14685bd6fc7fd4ffefa25c3edb7f41e9..adea1bdadfddd08bdfe9cac4b077c7b4c12a5761 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -586,3 +586,46 @@ pub const IPTOS = struct { pub const ECN_CE = 0x03; pub const ECN_MASK = 0x03; }; + +// https://cgit.freebsd.org/src/tree/sys/netinet/tcp.h?id=52c0d52b91e34f9190c9ba8fab7b6bc463bc4cbb#n183 +pub const TCP = struct { + pub const NODELAY = 1; + pub const MAXSEG = 2; + pub const NOPUSH = 4; + pub const NOOPT = 8; + pub const MD5SIG = 16; + pub const INFO = 32; + pub const STATS = 33; + pub const LOG = 34; + pub const LOGBUF = 35; + pub const LOGID = 36; + pub const LOGDUMP = 37; + pub const LOGDUMPID = 38; + pub const TXTLS_ENABLE = 39; + pub const TXTLS_MODE = 40; + pub const RXTLS_ENABLE = 41; + pub const RXTLS_MODE = 42; + pub const IWND_NB = 43; + pub const IWND_NSEG = 44; + pub const USE_DDP = 45; + pub const LOGID_CNT = 46; + pub const LOG_TAG = 47; + pub const USER_LOG = 48; + pub const CONGESTION = 64; + pub const CCALGOOPT = 65; + pub const MAXUNACKTIME = 68; + pub const IDLE_REDUCE = 70; + pub const REMOTE_UDP_ENCAPS_PORT = 71; + pub const DELACK = 72; + pub const FIN_IS_RST = 73; + pub const LOG_LIMIT = 74; + pub const SHARED_CWND_ALLOWED = 75; + pub const PROC_ACCOUNTING = 76; + pub const USE_CMP_ACKS = 77; + pub const PERF_INFO = 78; + pub const KEEPINIT = 128; + pub const KEEPIDLE = 256; + pub const KEEPINTVL = 512; + pub const KEEPCNT = 1024; + pub const FASTOPEN = 1025; +}; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index dd8bb8abf621324ba3ff2c9765f17524e30624c6..9e59fbb8b55e6c5ac9d0214a6e9f04bba2aac698 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -289,3 +289,11 @@ pub const IPTOS = struct { pub const THROUGHPUT = 0x08; pub const LOWDELAY = 0x10; }; + +// https://github.com/haiku/haiku/blob/2ffb9aef511dde272ab57d545a5d8631705a5ec8/headers/posix/netinet/tcp.h#L74 +pub const TCP = struct { + pub const NODELAY = 0x01; + pub const MAXSEG = 0x02; + pub const NOPUSH = 0x04; + pub const NOOPT = 0x08; +}; diff --git a/lib/std/c/illumos.zig b/lib/std/c/illumos.zig index 634c0c124e33c6fb655049083d14ef459a95d350..86e3be7f3dad324c1e84749084a170ce2cc91199 100644 --- a/lib/std/c/illumos.zig +++ b/lib/std/c/illumos.zig @@ -455,3 +455,31 @@ pub const IPTOS = struct { 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; +}; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index f15cf498b15d672a6943fea04c88c4d415120d07..5ebb3a57c17a549f7ac179262cf0c1cd4767c646 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -373,3 +373,16 @@ pub const IPTOS = struct { pub const PREC_PRIORITY = 0x20; pub const PREC_ROUTINE = 0x00; }; + +// https://github.com/NetBSD/src/blob/2579a44b3da9597de159e42cb1b5db0d382bd511/sys/netinet/tcp.h#L126 +pub const TCP = struct { + pub const NODELAY = 1; + pub const MAXSEG = 2; + pub const KEEPIDLE = 3; + pub const KEEPINTVL = 5; + pub const KEEPCNT = 6; + pub const KEEPINIT = 7; + pub const INFO = 9; + pub const MD5SIG = 0x10; + pub const CONGCTL = 0x20; +}; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 1dd65dca7b2f7ceb1c0ccbf02c4f5ae1bb073f2a..91ba8a8f5f76b85a2952c0a37421dcc11925a087 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -443,3 +443,13 @@ pub const IPTOS = struct { pub const ECN_CE = 0x03; pub const ECN_MASK = 0x03; }; + +// https://github.com/openbsd/src/blob/5761484065d1eed341f812f818ecf3f79138e7c6/sys/netinet/tcp.h#L215 +pub const TCP = struct { + pub const NODELAY = 0x01; + pub const MAXSEG = 0x02; + pub const MD5SIG = 0x04; + pub const SACK_ENABLE = 0x08; + pub const INFO = 0x09; + pub const NOPUSH = 0x10; +}; -- 2.54.0