Fixed: Freebsd syscall 'getpeername' is missing.

This commit is contained in:
Wison Ye
2025-03-23 13:22:19 +13:00
parent f578ce3acb
commit 2af691f587
+20 -6
View File
@@ -21,6 +21,7 @@ SYS_close : uintptr : 6
SYS_getpid : uintptr : 20 SYS_getpid : uintptr : 20
SYS_recvfrom : uintptr : 29 SYS_recvfrom : uintptr : 29
SYS_accept : uintptr : 30 SYS_accept : uintptr : 30
SYS_getpeername: uintptr : 31
SYS_getsockname: uintptr : 32 SYS_getsockname: uintptr : 32
SYS_fcntl : uintptr : 92 SYS_fcntl : uintptr : 92
SYS_fsync : uintptr : 95 SYS_fsync : uintptr : 95
@@ -202,18 +203,17 @@ accept_nil :: proc "contextless" (s: Fd) -> (Fd, Errno) {
accept :: proc { accept_T, accept_nil } accept :: proc { accept_T, accept_nil }
// Get socket name. getsockname_or_peername :: proc "contextless" (s: Fd, sockaddr: ^$T, is_peer: bool) -> Errno {
//
// 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 // sockaddr must contain a valid pointer, or this will segfault because
// we're telling the syscall that there's memory available to write to. // we're telling the syscall that there's memory available to write to.
addrlen: socklen_t = size_of(T) addrlen: socklen_t = size_of(T)
result, ok := intrinsics.syscall_bsd(SYS_getsockname, result, ok := intrinsics.syscall_bsd(
is_peer ? SYS_getpeername : SYS_getsockname,
cast(uintptr)s, cast(uintptr)s,
cast(uintptr)sockaddr, cast(uintptr)sockaddr,
cast(uintptr)&addrlen) cast(uintptr)&addrlen
)
if !ok { if !ok {
return cast(Errno)result return cast(Errno)result
@@ -222,6 +222,20 @@ getsockname :: proc "contextless" (s: Fd, sockaddr: ^$T) -> Errno {
return nil 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 {
return getsockname_or_peername(s, sockaddr, false)
}
// Synchronize changes to a file. // Synchronize changes to a file.
// //
// The fsync() system call appeared in 4.2BSD. // The fsync() system call appeared in 4.2BSD.