Compare commits

...
Author SHA1 Message Date
Doczom b6e583d41c Krn/network: added getsockname and getpeername
Check kernel codestyle / Check kernel codestyle (pull_request) Successful in 21s
Test PR / Build (en_US) (pull_request) Successful in 2m2s
Test PR / Build (ru_RU) (pull_request) Successful in 2m9s
Test PR / Build (es_ES) (pull_request) Successful in 2m13s
2026-07-30 13:29:22 +05:00
2 changed files with 140 additions and 2 deletions

No files matched your search

+137 -2
View File
@@ -279,8 +279,10 @@ sys_socket:
dd socket_get_opt ; 9
dd socket_pair ; 10
;dd socket_sendto ; 11
;dd socket_recvfrom ; 12
dd socket_getpeername ; 11
dd socket_getsockname ; 12
;dd socket_sendto ; 13
;dd socket_recvfrom ; 14
.number = ($ - .table) / 4 - 1
.error:
@@ -1396,6 +1398,139 @@ socket_pair:
;-----------------------------------------------------------------;
; ;
; socket_getpeername: Get name of connected peer socket. ;
; ;
; IN: ecx = socket number ;
; edx = pointer to sockaddr struct ;
; esi = length of sockaddr struct ;
; ;
; OUT: eax = length of sockaddr struct ;
; eax = -1 on error ;
; ebx = errorcode on error ;
; ;
;-----------------------------------------------------------------;
align 4
socket_getpeername:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_getpeername: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call socket_num_to_ptr
test eax, eax
jz .notsock
stdcall is_region_userspace, edx, esi
jnz .efault
cmp [eax + SOCKET.Domain], AF_INET4
jne .invalid
cmp esi, 8 ; domain + port + ipv4_addr
jb .errlen
mov word[edx], AF_INET4
mov esi, edx
xor edx, edx
cmp [eax + SOCKET.Type], SOCK_RAW
je .raw_protocol
mov dx, [eax + TCP_SOCKET.RemotePort]
.raw_protocol:
cmp [eax + SOCKET.state], SS_ISCONNECTED
jne .notconn
mov [esi + sockaddr.port], dx
mov edx, [eax + IP_SOCKET.RemoteIP]
mov [esi + sockaddr.ip], edx
mov dword[esp + SYSCALL_STACK.eax], 8
ret
.efault:
mov dword[esp + SYSCALL_STACK.eax], -1
mov dword[esp + SYSCALL_STACK.ebx], EFAULT
ret
.notconn:
mov dword[esp + SYSCALL_STACK.ebx], ENOTCONN
mov dword[esp + SYSCALL_STACK.eax], -1
ret
.no_inet4:
.errlen:
.invalid:
mov dword[esp + SYSCALL_STACK.ebx], EINVAL
mov dword[esp + SYSCALL_STACK.eax], -1
ret
.notsock:
mov dword[esp + SYSCALL_STACK.ebx], ENOTSOCK
mov dword[esp + SYSCALL_STACK.eax], -1
ret
;-----------------------------------------------------------------;
; ;
; socket_getsockname: Get socket name. ;
; ;
; IN: ecx = socket number ;
; edx = pointer to sockaddr struct ;
; esi = length of sockaddr struct ;
; ;
; OUT: eax = length of sockaddr struct ;
; eax = -1 on error ;
; ebx = errorcode on error ;
; ;
;-----------------------------------------------------------------;
align 4
socket_getsockname:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_getsockname: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call socket_num_to_ptr
test eax, eax
jz .notsock
stdcall is_region_userspace, edx, esi
jnz .efault
cmp [eax + SOCKET.Domain], AF_INET4
jne .invalid
cmp esi, 8 ; domain + port + ipv4_addr
jb .errlen
mov word[edx], AF_INET4
mov esi, edx
xor edx, edx
cmp [eax + SOCKET.Type], SOCK_RAW
je .raw_protocol
mov dx, [eax + TCP_SOCKET.RemotePort]
.raw_protocol:
mov [esi + sockaddr.port], dx
mov edx, [eax + IP_SOCKET.RemoteIP]
mov [esi + sockaddr.ip], edx
mov dword[esp + SYSCALL_STACK.eax], 8
ret
.efault:
mov dword[esp + SYSCALL_STACK.eax], -1
mov dword[esp + SYSCALL_STACK.ebx], EFAULT
ret
.errlen:
.invalid:
mov dword[esp + SYSCALL_STACK.ebx], EINVAL
mov dword[esp + SYSCALL_STACK.eax], -1
ret
.notsock:
mov dword[esp + SYSCALL_STACK.ebx], ENOTSOCK
mov dword[esp + SYSCALL_STACK.eax], -1
ret
;-----------------------------------------------------------------;
; ;
; socket_debug: Copy socket variables to application buffer. ;
+3
View File
@@ -139,6 +139,9 @@ EISCONN = 56
ETIMEDOUT = 60
ECONNREFUSED = 61
EFAULT = 14 ; copy, defined in posix/posix.inc ; Bad address
ENOTSOCK = 38 ; FreeBSD error code, Socket operation on non-socket
; Api protocol numbers
API_ETH = 0
API_IPv4 = 1