aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorWison Ye <wisonye@gmail.com>2025-03-23 13:22:19 +1300
committerWison Ye <wisonye@gmail.com>2025-03-23 13:22:19 +1300
commit2af691f58741eae8fa4ada329bdf65729f9a50fe (patch)
tree98517efca8fd7a0fae31941412b7d2b9f41ff54f /core
parentf578ce3acb23bf7eb93699c5666ddc61693abbb7 (diff)
Fixed: Freebsd syscall 'getpeername' is missing.
Diffstat (limited to 'core')
-rw-r--r--core/sys/freebsd/syscalls.odin42
1 files changed, 28 insertions, 14 deletions
diff --git a/core/sys/freebsd/syscalls.odin b/core/sys/freebsd/syscalls.odin
index 83b51138a..3c96e0b52 100644
--- a/core/sys/freebsd/syscalls.odin
+++ b/core/sys/freebsd/syscalls.odin
@@ -21,6 +21,7 @@ SYS_close : uintptr : 6
SYS_getpid : uintptr : 20
SYS_recvfrom : uintptr : 29
SYS_accept : uintptr : 30
+SYS_getpeername: uintptr : 31
SYS_getsockname: uintptr : 32
SYS_fcntl : uintptr : 92
SYS_fsync : uintptr : 95
@@ -202,24 +203,37 @@ accept_nil :: proc "contextless" (s: Fd) -> (Fd, Errno) {
accept :: proc { accept_T, accept_nil }
+getsockname_or_peername :: proc "contextless" (s: Fd, sockaddr: ^$T, is_peer: bool) -> Errno {
+ // sockaddr must contain a valid pointer, or this will segfault because
+ // we're telling the syscall that there's memory available to write to.
+ addrlen: socklen_t = size_of(T)
+
+ result, ok := intrinsics.syscall_bsd(
+ is_peer ? SYS_getpeername : SYS_getsockname,
+ cast(uintptr)s,
+ cast(uintptr)sockaddr,
+ cast(uintptr)&addrlen
+ )
+
+ if !ok {
+ return cast(Errno)result
+ }
+
+ return nil
+}
+
+// Get name of connected peer
+//
+// The getpeername() system call appeared in 4.2BSD.
+getpeername :: proc "contextless" (s: Fd, sockaddr: ^$T) -> Errno {
+ return getsockname_or_peername(s, sockaddr, true)
+}
+
// Get socket name.
//
// The getsockname() system call appeared in 4.2BSD.
getsockname :: proc "contextless" (s: Fd, sockaddr: ^$T) -> Errno {
- // sockaddr must contain a valid pointer, or this will segfault because
- // we're telling the syscall that there's memory available to write to.
- addrlen: socklen_t = size_of(T)
-
- result, ok := intrinsics.syscall_bsd(SYS_getsockname,
- cast(uintptr)s,
- cast(uintptr)sockaddr,
- cast(uintptr)&addrlen)
-
- if !ok {
- return cast(Errno)result
- }
-
- return nil
+ return getsockname_or_peername(s, sockaddr, false)
}
// Synchronize changes to a file.