linux/socket

Linux IPv4 socket declarations for addresses, address-resolution records, raw socket options, connection lifecycle, byte-order conversion, and address resolution.


Constants

Constant example

"linux/socket" use
"control" use

{} () {} [
  AF_INET printStack _:;
  SOCK_STREAM printStack _:;
  SHUT_WR printStack _:;
  INADDR_ANY printStack _:;
] "main" exportFunction

Expected Output During Compilation

2
1
1
0n32

Address and lookup schemas

Schema example

"linux/socket" use
"control" use

{} () {} [
  sockaddr_in fieldCount printStack _:;
  addrinfo 0 fieldName printStack _:;
] "main" exportFunction

Expected Output During Compilation

4
"ai_flags"

Socket and address model


Arguments and results


Connection workflow


Imported functions


Signature examples

Printing imported names during compilation shows the exact imported signatures.

"linux/socket" use
"control" use

{} Int32 {} [
  @getaddrinfo printStack _:;
  @recv printStack _:;
  @socket printStack _:;
  0
] "main" exportFunction

Expected Output During Compilation

{node: Natx; service: Natx; hints: {ai_flags: Int32; ai_family: Int32; ai_socktype: Int32; ai_protocol: Int32; ai_addrlen: Natx; ai_addr: Natx; ai_canonname: Natx; ai_next: Natx;} Cref; res: Natx;} Int32 {convention: "";} codeRef
{sockfd: Int32; buf: Natx; len: Natx; flags: Int32;} Intx {convention: "";} codeRef
{domain: Int32; type: Int32; protocol: Int32;} Int32 {convention: "";} codeRef

Examples

Byte-order helpers can be demonstrated without external networking state.

Byte-order helpers

"linux/socket" use
"String" use
"control" use

{} Int32 {} [
  (0x01020304n32 htonl ntohl 0x01020304n32 = toString LF) printList
  0
] "main" exportFunction

Expected Output

TRUE

Descriptor creation example

"linux/socket" use
"linux/posix" use
"String" use
"control" use

{} Int32 {} [
  sock: AF_INET SOCK_STREAM IPPROTO_TCP socket;
  ("created=" sock 0 < ~ LF
   "close=" sock close 0 = LF) printList
  0
] "main" exportFunction

Expected Output

created=TRUE
close=TRUE

See also