Skip to content

getpeername

Implemented in Antinomie 0.7.0 · Syscall list

long getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len);
Number (x86-64) 52
ABI common
Kernel entry point sys_getpeername

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

Returns the address of the peer a socket is connected to.

Name Type Meaning
fd (arg0) int File descriptor to operate on.
usockaddr (arg1) struct sockaddr * Pointer to a socket address.
usockaddr_len (arg2) int * Pointer to the size of the socket address.

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.
-107 ENOTCONN The socket is not connected.

getpeername(2) on man7.org

Coverage mark: Implemented. Every pointer argument has a capture rule in the pinned kernel patch and none of them records a “no decoder”, “address only” or “not observed” gap on any code path. Individual values can still be incomplete on a particular call; see the capture statuses.

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
usockaddr (arg1) Entry the pointer itself, as a raw word args.1, args.raw[1]
↳ pointee Exit socket address (sockaddr layout), length min(written length, capacity) arg1.sockaddr result is 0 or greater and the address pointer is not NULL
usockaddr_len (arg2) Entry the pointer itself, as a raw word args.2, args.raw[2]
↳ pointee Entry socklen_t value the program provides arg2.socklen.capacity the address pointer is not NULL
↳ pointee Exit socklen_t value the kernel wrote arg2.socklen.output result is 0 or greater and the address pointer is not NULL
  • Result: ret, syscall.errno, syscall.success, syscall.duration_ns.
  • Argument words: args.fd (arg0), args.usockaddr (arg1), args.usockaddr_len (arg2); args.0 to args.5 by position.
  • Structure sockaddr behind usockaddr (arg1): args.usockaddr.<member> for sa_family.
  • Structure wait_status behind usockaddr_len (arg2): args.usockaddr_len.<member> for value.

See Syscall Trace filter for the full syntax.

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