Skip to content

setsockopt

Partial in Antinomie 0.7.0 · Syscall list

long setsockopt(int fd, int level, int optname, char *optval, int optlen);
Number (x86-64) 54
ABI 64
Kernel entry point sys_setsockopt

This is the raw kernel prototype from the pinned Linux 6.12.94 schema, not the libc wrapper.

Sets an option on a socket or on a protocol layer, identified by a level and an option name.

Name Type Meaning
fd (arg0) int File descriptor to operate on.
level (arg1) int Protocol level, SOL_SOCKET (1) or a protocol number such as IPPROTO_TCP (6).
optname (arg2) int Option name within the level.
optval (arg3) char * Pointer to the option value.
optlen (arg4) int Size of the option value in bytes.

On success: 0.

In an Antinomie trace the Return column and the ret filter field show the raw kernel return value. On failure that is the negative errno, for example -2 for ENOENT, not the -1 plus errno that the libc wrapper gives. syscall.errno holds the positive errno and syscall.success is false.

Raw return Name Meaning
-9 EBADF A file descriptor is not valid for this operation.
-22 EINVAL An argument is invalid.
-92 ENOPROTOOPT The protocol does not support this option.

setsockopt(2) on man7.org

Coverage mark: Partial. Known (level, option) pairs decode their value. An unknown pair records the raw bytes (up to 128 KiB) together with a sockopt.unknown_option “no decoder” gap, and a few nested structures are left raw.

Every call is recorded as an Entry record (the six argument words and the pointees copied at entry) and an Exit record (the return value and the pointees copied at exit).

Argument When How Recorded field key Condition
fd (arg0) Entry raw scalar word args.0, args.fd
level (arg1) Entry raw scalar word args.1, args.level
optname (arg2) Entry raw scalar word args.2, args.optname
optval (arg3) Entry the pointer itself, as a raw word args.3, args.raw[3]
↳ pointee Entry the option value; known options use their layout (integers, linger, timeouts, interface names, congestion control names, membership structures); unknown (level, optname) pairs are raw bytes up to 128 KiB arg3.optval length from optlen (arg4); “invalid extent” on a size mismatch
↳ pointee Entry array of sock_filter instructions (8 bytes each) arg3.optval.filter SO_ATTACH_FILTER or SO_ATTACH_REUSEPORT_CBPF; “invalid extent” if the length is 0 or above 4,096
optlen (arg4) Entry raw scalar word args.4, args.optlen
  • Selector: (level, optname). The value is recorded at entry as arg3.optval, with a known layout for known options (integers, linger, timeouts, socket filters with their instruction array, interface names, congestion control names).
  • Result: ret, syscall.errno, syscall.success, syscall.duration_ns.
  • Argument words: args.fd (arg0), args.level (arg1), args.optname (arg2), args.optval (arg3), args.optlen (arg4); args.0 to args.5 by position.
  • Structure sock_fprog behind optval (arg3): args.optval.<member> for filter, len.

See Syscall Trace filter for the full syntax.

  • An unknown (level, optname) pair also records sockopt.unknown_option with the “no decoder” status; a few nested structures (netfilter table replacement, multicast source lists) keep only their top-level bytes.
  • See the coverage mark above for the code paths that record a gap.

For what the capture statuses mean, see Capture statuses. For what is never recorded, see Known gaps.