diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-09-17 22:22:19 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-09-17 22:22:19 +0200 |
| commit | 652557bfcd64deccf018e96817a001fd9c4d69a1 (patch) | |
| tree | 0f2ba9b19523fd200dcdaaa709b4383f4118a7e6 /core/sys | |
| parent | 6ef779cd5c8260b2e6979e676d28489fd53dd599 (diff) | |
net: add `bound_endpoint` procedure
Diffstat (limited to 'core/sys')
| -rw-r--r-- | core/sys/freebsd/syscalls.odin | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/sys/freebsd/syscalls.odin b/core/sys/freebsd/syscalls.odin index 8590df46e..83b51138a 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_getsockname: uintptr : 32 SYS_fcntl : uintptr : 92 SYS_fsync : uintptr : 95 SYS_socket : uintptr : 97 @@ -201,6 +202,26 @@ accept_nil :: proc "contextless" (s: Fd) -> (Fd, Errno) { accept :: proc { accept_T, accept_nil } +// 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 +} + // Synchronize changes to a file. // // The fsync() system call appeared in 4.2BSD. |