Correct use of TYPE and PROTOCOL parameters in socket function

git-svn-id: svn://kolibrios.org@1542 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2010-07-31 11:17:06 +00:00
parent 8a7ebf6b32
commit 445f854cae
12 changed files with 141 additions and 329 deletions

View File

@ -7,7 +7,7 @@ include '../proc32.inc'
include '../macros.inc' include '../macros.inc'
purge section,mov,add,sub purge section,mov,add,sub
include 'network.inc' include '../network.inc'
section '.flat' code readable align 16 section '.flat' code readable align 16
@ -29,7 +29,8 @@ lib_init: ;//////////////////////////////////////////////////////////////////;;
mov [dll.load], edx mov [dll.load], edx
mov [DNSrequestID], 1 mov [DNSrequestID], 1
stdcall edx, @IMPORT stdcall edx, @IMPORT
ret 4 xor eax, eax
ret
;;===========================================================================;; ;;===========================================================================;;
;; in_addr_t __stdcall inet_addr(__in const char* hostname); ;; ;; in_addr_t __stdcall inet_addr(__in const char* hostname); ;;
@ -257,7 +258,7 @@ inet_ntoa: ;;
ret ret
struct __gai_reqdata struct __gai_reqdata
socket dd ? socketnum dd ?
; external code should not look on rest of this structure, ; external code should not look on rest of this structure,
; it is internal for getaddrinfo_start/process/abort ; it is internal for getaddrinfo_start/process/abort
reqid dw ? ; DNS request ID reqid dw ? ; DNS request ID
@ -279,7 +280,7 @@ getaddrinfo: ;;
;;---------------------------------------------------------------------------;; ;;---------------------------------------------------------------------------;;
;> first parameter (optional) = host name ;; ;> first parameter (optional) = host name ;;
;> second parameter (optional) = service name (decimal number for now) ;; ;> second parameter (optional) = service name (decimal number for now) ;;
;> third parameter (optional) = hints for socket type ;; ;> third parameter (optional) = hints for socketnum type ;;
;> fourth parameter = pointer to result (head of L1-list) ;; ;> fourth parameter = pointer to result (head of L1-list) ;;
;;---------------------------------------------------------------------------;; ;;---------------------------------------------------------------------------;;
;< eax = 0 on success / one of EAI_ codes on error ;; ;< eax = 0 on success / one of EAI_ codes on error ;;
@ -425,30 +426,30 @@ end virtual
jecxz @f jecxz @f
cmp [ecx+addrinfo.ai_family], edi cmp [ecx+addrinfo.ai_family], edi
jz @f jz @f
cmp [ecx+addrinfo.ai_family], PF_INET cmp [ecx+addrinfo.ai_family], AF_INET4
jnz .ret jnz .ret
@@: @@:
; 1e. Valid combinations for ai_socktype/ai_protocol: 0/0 for any or ; 1e. Valid combinations for ai_socktype/ai_protocol: 0/0 for any or
; SOCK_STREAM/IPPROTO_TCP, SOCK_DGRAM/IPPROTO_UDP ; SOCK_STREAM/IPPROTO_TCP, SOCK_DGRAM/IPPROTO_UDP
; (raw sockets are not yet supported by the kernel) ; (raw socketnums are not yet supported by the kernel)
xor edx, edx ; assume 0=any if no hints xor edx, edx ; assume 0=any if no hints
jecxz .socket_type_ok jecxz .socketnum_type_ok
mov edx, [ecx+addrinfo.ai_socktype] mov edx, [ecx+addrinfo.ai_socktype]
mov esi, [ecx+addrinfo.ai_protocol] mov esi, [ecx+addrinfo.ai_protocol]
; 1f. Test for ai_socktype=0 and ai_protocol=0. ; 1f. Test for ai_socktype=0 and ai_protocol=0.
test edx, edx test edx, edx
jnz .check_socktype jnz .check_socktype
test esi, esi test esi, esi
jz .socket_type_ok jz .socketnum_type_ok
; 1g. ai_socktype=0, ai_protocol is nonzero. ; 1g. ai_socktype=0, ai_protocol is nonzero.
push EAI_SERVICE push EAI_SERVICE
pop eax pop eax
inc edx ; edx = SOCK_STREAM inc edx ; edx = SOCK_STREAM
cmp esi, IPPROTO_TCP cmp esi, IPPROTO_TCP
jz .socket_type_ok jz .socketnum_type_ok
inc edx ; edx = SOCK_DGRAM inc edx ; edx = SOCK_DGRAM
cmp esi, IPPROTO_UDP cmp esi, IPPROTO_UDP
jz .socket_type_ok jz .socketnum_type_ok
.ret: .ret:
; Restore saved registers, destroy stack frame and return. ; Restore saved registers, destroy stack frame and return.
mov esp, ebp mov esp, ebp
@ -464,16 +465,16 @@ end virtual
cmp edx, SOCK_DGRAM cmp edx, SOCK_DGRAM
jnz .ret jnz .ret
test esi, esi test esi, esi
jz .socket_type_ok jz .socketnum_type_ok
cmp esi, IPPROTO_UDP cmp esi, IPPROTO_UDP
jz .socket_type_ok jz .socketnum_type_ok
jmp .ret jmp .ret
.check_tcp: .check_tcp:
test esi, esi test esi, esi
jz .socket_type_ok jz .socketnum_type_ok
cmp esi, IPPROTO_TCP cmp esi, IPPROTO_TCP
jnz .ret jnz .ret
.socket_type_ok: .socketnum_type_ok:
mov [ebx+__gai_reqdata.socktype], dl mov [ebx+__gai_reqdata.socktype], dl
; 2. Resolve service. ; 2. Resolve service.
; 2a. If no name is given, remember value -1. ; 2a. If no name is given, remember value -1.
@ -513,7 +514,7 @@ end virtual
; 3. Process host name. ; 3. Process host name.
mov esi, [.hostname] mov esi, [.hostname]
; 3a. If hostname is not given, ; 3a. If hostname is not given,
; use localhost for active sockets and INADDR_ANY for passive sockets. ; use localhost for active socketnums and INADDR_ANY for passive socketnums.
mov eax, 0x0100007F ; 127.0.0.1 in network byte order mov eax, 0x0100007F ; 127.0.0.1 in network byte order
test byte [ebx+__gai_reqdata.flags], AI_PASSIVE test byte [ebx+__gai_reqdata.flags], AI_PASSIVE
jz @f jz @f
@ -679,17 +680,17 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value
cmp eax, -1 cmp eax, -1
je .ret.dnserr je .ret.dnserr
mov esi, eax ; put server address to esi mov esi, eax ; put server address to esi
; 8. Open UDP socket to DNS server, port 53. ; 8. Open UDP socketnum to DNS server, port 53.
; 8a. Create new socket. ; 8a. Create new socketnum.
mcall 74, 0, AF_INET, IPPROTO_UDP mcall 74, 0, AF_INET4, SOCK_DGRAM
cmp eax, -1 ; error? cmp eax, -1 ; error?
jz .ret.dnserr jz .ret.dnserr
mov ecx, eax ; put socket handle to ecx mov ecx, eax ; put socketnum handle to ecx
; 8b. Create sockaddr structure on the stack. ; 8b. Create sockaddr structure on the stack.
push 0 push 0
push 0 ; sin_zero push 0 ; sin_zero
push esi ; sin_addr push esi ; sin_addr
push AF_INET + (53 shl 16) push AF_INET4 + (53 shl 16)
; sin_family and sin_port in network byte order ; sin_family and sin_port in network byte order
; 8c. Connect. ; 8c. Connect.
mcall 74, 4, , esp, sizeof.sockaddr_in mcall 74, 4, , esp, sizeof.sockaddr_in
@ -706,7 +707,7 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value
cmp eax, -1 cmp eax, -1
jz .ret.close jz .ret.close
mov eax, [.reqdata] mov eax, [.reqdata]
mov [eax+__gai_reqdata.socket], ecx mov [eax+__gai_reqdata.socketnum], ecx
push -1 push -1
pop eax ; return status: more processing required pop eax ; return status: more processing required
jmp .ret.dns jmp .ret.dns
@ -759,11 +760,11 @@ end virtual
push ebx esi edi push ebx esi edi
mov edi, [.reqdata] mov edi, [.reqdata]
; 2. Read UDP datagram. ; 2. Read UDP datagram.
mov ecx, [edi+__gai_reqdata.socket] mov ecx, [edi+__gai_reqdata.socketnum]
push edi push edi
mcall 74, 7, , , 512, 0 mcall 74, 7, , , 512, 0
pop edi pop edi
; 3. Ignore events for other sockets (return if no data read) ; 3. Ignore events for other socketnums (return if no data read)
test eax, eax test eax, eax
jz .ret.more_processing_required jz .ret.more_processing_required
; 4. Sanity check: discard too short packets. ; 4. Sanity check: discard too short packets.
@ -918,10 +919,10 @@ end virtual
@@: @@:
pop eax pop eax
.ret.close: .ret.close:
; 15. Close socket. ; 15. Close socketnum.
push eax push eax
mov ecx, [.reqdata] mov ecx, [.reqdata]
mov ecx, [ecx+__gai_reqdata.socket] mov ecx, [ecx+__gai_reqdata.socketnum]
mcall 74, 1 mcall 74, 1
pop eax pop eax
; 16. Restore used registers, destroy stack frame and return. ; 16. Restore used registers, destroy stack frame and return.
@ -1170,12 +1171,12 @@ getaddrinfo._.generate_data: ;;
; 4. Fill struct addrinfo. ; 4. Fill struct addrinfo.
mov eax, [ebx+__gai_reqdata.flags] mov eax, [ebx+__gai_reqdata.flags]
mov [edi+addrinfo.ai_flags], eax mov [edi+addrinfo.ai_flags], eax
mov byte [edi+addrinfo.ai_family], PF_INET mov byte [edi+addrinfo.ai_family], AF_INET4
mov byte [edi+addrinfo.ai_addrlen], sizeof.sockaddr_in mov byte [edi+addrinfo.ai_addrlen], sizeof.sockaddr_in
lea ecx, [edi+sizeof.addrinfo] lea ecx, [edi+sizeof.addrinfo]
mov [edi+addrinfo.ai_addr], ecx mov [edi+addrinfo.ai_addr], ecx
; 5. Fill struct sockaddr_in. ; 5. Fill struct sockaddr_in.
mov byte [ecx+sockaddr_in.sin_family], PF_INET mov byte [ecx+sockaddr_in.sin_family], AF_INET4
pop eax pop eax
mov [ecx+sockaddr_in.sin_addr], eax mov [ecx+sockaddr_in.sin_addr], eax
; 6. Append new item to the list. ; 6. Append new item to the list.
@ -1189,7 +1190,7 @@ getaddrinfo._.generate_data: ;;
ret ret
.set_socktype: .set_socktype:
; Set ai_socktype and ai_protocol fields by given socket type. ; Set ai_socktype and ai_protocol fields by given socketnum type.
mov byte [edi+addrinfo.ai_socktype], cl mov byte [edi+addrinfo.ai_socktype], cl
dec cl dec cl
jnz .set_udp jnz .set_udp
@ -1219,9 +1220,9 @@ getaddrinfo_abort: ;;
;;===========================================================================;; ;;===========================================================================;;
; 0. Save used registers for __stdcall. ; 0. Save used registers for __stdcall.
push ebx push ebx
; 1. Allocated resources: only socket, so close it and return. ; 1. Allocated resources: only socketnum, so close it and return.
mov eax, [esp+8] mov eax, [esp+8]
mov ecx, [eax+__gai_reqdata.socket] mov ecx, [eax+__gai_reqdata.socketnum]
mcall 74, 1 mcall 74, 1
; 2. Restore used registers and return. ; 2. Restore used registers and return.
pop ebx pop ebx

View File

@ -1,60 +0,0 @@
; Socket types
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3 ; not supported by the kernel
; IP protocols
IPPROTO_IP = 0
IPPROTO_ICMP = 1 ; not supported by the kernel
IPPROTO_TCP = 6
IPPROTO_UDP = 17
; Address families
AF_UNSPEC = 0
AF_INET = 2 ; IPv4
;AF_INET6 = 28 ; IPv6 (not supported)
PF_UNSPEC = AF_UNSPEC
PF_INET = AF_INET
;PF_INET6 = AF_INET6
; Flags for addrinfo
AI_PASSIVE = 1
AI_CANONNAME = 2
AI_NUMERICHOST = 4
AI_NUMERICSERV = 8
AI_ADDRCONFIG = 0x400
; internal definition
AI_SUPPORTED = 0x40F
struct sockaddr_in
sin_family dw ? ; sa_family_t
sin_port dw ? ; in_port_t
sin_addr dd ? ; struct in_addr
sin_zero rb 8 ; zero
ends
struct addrinfo
ai_flags dd ? ; bitmask of AI_*
ai_family dd ? ; PF_*
ai_socktype dd ? ; SOCK_*
ai_protocol dd ? ; 0 or IPPROTO_*
ai_addrlen dd ? ; length of ai_addr
ai_canonname dd ? ; char*
ai_addr dd ? ; struct sockaddr*
ai_next dd ? ; struct addrinfo*
ends
EAI_ADDRFAMILY = 1
EAI_AGAIN = 2
EAI_BADFLAGS = 3
EAI_FAIL = 4
EAI_FAMILY = 5
EAI_MEMORY = 6
EAI_NONAME = 8
EAI_SERVICE = 9
EAI_SOCKTYPE = 10
EAI_BADHINTS = 12
EAI_PROTOCOL = 13
EAI_OVERFLOW = 14

View File

@ -1,157 +0,0 @@
;-----------------------------------------------------------------------------
proc mem.Alloc size ;/////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------
push ebx ecx
mov eax,[size]
lea ecx,[eax+4+4095]
and ecx,not 4095
mcall 68,12
add ecx,-4
mov [eax],ecx
add eax,4
pop ecx ebx
ret
endp
;-----------------------------------------------------------------------------
proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
;-----------------------------------------------------------------------------
push ebx ecx esi edi eax
mov eax,[mptr]
mov ebx,[size]
or eax,eax
jz @f
lea ecx,[ebx+4+4095]
and ecx,not 4095
add ecx,-4
cmp ecx,[eax-4]
je .exit
@@: mov eax,ebx
call mem.Alloc
xchg eax,[esp]
or eax,eax
jz .exit
mov esi,eax
xchg eax,[esp]
mov edi,eax
mov ecx,[esi-4]
cmp ecx,[edi-4]
jbe @f
mov ecx,[edi-4]
@@: add ecx,3
shr ecx,2
cld
rep movsd
xchg eax,[esp]
call mem.Free
.exit:
pop eax edi esi ecx ebx
ret
endp
;-----------------------------------------------------------------------------
proc mem.Free mptr ;//////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------
mov eax,[mptr]
or eax,eax
jz @f
push ebx ecx
lea ecx,[eax-4]
mcall 68,13
pop ecx ebx
@@: ret
endp
proc dll.Load, import_table:dword
mov esi,[import_table]
.next_lib: mov edx,[esi]
or edx,edx
jz .exit
push esi
mov esi,[esi+4]
mov edi,s_libdir.fname
@@: lodsb
stosb
or al,al
jnz @b
mcall 68,19,s_libdir
or eax,eax
jz .fail
stdcall dll.Link,eax,edx
stdcall dll.Init,[eax+4]
pop esi
add esi,8
jmp .next_lib
.exit: xor eax,eax
ret
.fail: add esp,4
xor eax,eax
inc eax
ret
endp
proc dll.Link, exp:dword,imp:dword
push eax
mov esi,[imp]
test esi,esi
jz .done
.next: lodsd
test eax,eax
jz .done
stdcall dll.GetProcAddress,[exp],eax
or eax,eax
jz @f
mov [esi-4],eax
jmp .next
@@: mov dword[esp],0
.done: pop eax
ret
endp
proc dll.Init, dllentry:dword
pushad
mov eax,mem.Alloc
mov ebx,mem.Free
mov ecx,mem.ReAlloc
mov edx,dll.Load
stdcall [dllentry]
popad
ret
endp
proc dll.GetProcAddress, exp:dword,sz_name:dword
mov edx,[exp]
xor eax,eax
.next: or edx,edx
jz .end
cmp dword[edx],0
jz .end
stdcall strcmp,[edx],[sz_name]
test eax,eax
jz .ok
add edx,8
jmp .next
.ok: mov eax,[edx+4]
.end: ret
endp
proc strcmp, str1:dword,str2:dword
push esi edi
mov esi,[str1]
mov edi,[str2]
xor eax,eax
@@: lodsb
scasb
jne .fail
or al,al
jnz @b
jmp .ok
.fail: or eax,-1
.ok: pop edi esi
ret
endp
s_libdir:
db '/sys/lib/'
.fname rb 32

View File

@ -15,7 +15,7 @@ purge mov,add,sub
include '../proc32.inc' include '../proc32.inc'
include '../dll.inc' include '../dll.inc'
include '../network_lib/network.inc' include '../network.inc'
; entry point ; entry point
start: start:

View File

@ -86,7 +86,7 @@ start:
push newline push newline
call [con_write_asciiz] call [con_write_asciiz]
mcall socket, AF_INET4, IPPROTO_TCP, 0 mcall socket, AF_INET4, SOCK_STREAM, 0
cmp eax, -1 cmp eax, -1
je error je error

View File

@ -92,7 +92,7 @@ main:
push str4 push str4
call [con_write_asciiz] call [con_write_asciiz]
mcall socket, AF_INET4, IPPROTO_TCP, 0 mcall socket, AF_INET4, SOCK_STREAM, 0
cmp eax, -1 cmp eax, -1
jz fail2 jz fail2
mov [socketnum], eax mov [socketnum], eax

View File

@ -226,7 +226,7 @@ start_transfer:
mov esi, [esi + sockaddr_in.sin_addr] mov esi, [esi + sockaddr_in.sin_addr]
mov dword [IP], esi mov dword [IP], esi
mcall socket, AF_INET4, IP_PROTO_UDP, 0 ; socket_open mcall socket, AF_INET4, SOCK_DGRAM, 0 ; socket_open
cmp eax, -1 cmp eax, -1
je still je still

View File

@ -42,14 +42,10 @@ RATE_LIMIT_INTERVAL equ 60 ; seconds (delay between successive attempts)
DEFEND_INTERVAL equ 10 ; seconds (min. wait between defensive ARPs) DEFEND_INTERVAL equ 10 ; seconds (min. wait between defensive ARPs)
AF_INET4 equ 2 ;;;;;
IP_PROTO_UDP equ 17
include '../proc32.inc' include '../proc32.inc'
include '../macros.inc' include '../macros.inc'
include '../debug-fdo.inc' include '../debug-fdo.inc'
include '../network.inc'
include 'dhcp.inc' include 'dhcp.inc'
include 'dll.inc' include 'dll.inc'
@ -136,7 +132,7 @@ START: ; start of execution
mcall 75, 1337 shl 16 + 4 mcall 75, 1337 shl 16 + 4
cmp eax, -1 cmp eax, -1
je close je exit
mov word[MAC], bx mov word[MAC], bx
mov dword[MAC+2], eax mov dword[MAC+2], eax
@ -198,7 +194,7 @@ skip_ini:
DEBUGF 1,"->Skip ini\n" DEBUGF 1,"->Skip ini\n"
mcall 74, 0, AF_INET4, IP_PROTO_UDP, 0 ; open socket (parameters: domain, type, reserved) mcall 74, 0, AF_INET4, SOCK_DGRAM, 0 ; open socket (parameters: domain, type, reserved)
cmp eax, -1 cmp eax, -1
je error je error
mov [socketNum], eax mov [socketNum], eax
@ -300,7 +296,7 @@ read_data: ; we have data - this will be the response
DEBUGF 1,"->%d bytes received\n", eax DEBUGF 1,"->%d bytes received\n", eax
push eax push eax
mcall 74, 1, [socketNum] ; close the socket mcall 74, 1, [socketNum] ; exit the socket
pop eax pop eax
cmp eax, -1 cmp eax, -1
@ -323,7 +319,7 @@ read_data: ; we have data - this will be the response
cmp [dhcpMsgType], byte 0x03 ; did we send a request? cmp [dhcpMsgType], byte 0x03 ; did we send a request?
je request je request
jmp close ; really unknown, what we did jmp exit ; really unknown, what we did
discover: discover:
call parseResponse call parseResponse
@ -339,7 +335,7 @@ request:
cmp [dhcpMsgType], byte 0x05 ; Was the response an ACK? It should be cmp [dhcpMsgType], byte 0x05 ; Was the response an ACK? It should be
jne apipa ; NO - so we do zeroconf jne apipa ; NO - so we do zeroconf
jmp close jmp exit
;*************************************************************************** ;***************************************************************************
; Function ; Function
@ -447,7 +443,7 @@ pr_exit:
; DEBUGF 1,"Sending ARP announce\n" ; DEBUGF 1,"Sending ARP announce\n"
;;; ;;;
jmp close jmp exit
apipa: apipa:
stdcall mem.Free, [dhcpMsg] stdcall mem.Free, [dhcpMsg]
@ -511,7 +507,7 @@ link_local:
; we should, instead of closing, detect ARP conflicts and detect if cable keeps connected ;) ; we should, instead of closing, detect ARP conflicts and detect if cable keeps connected ;)
error: error:
close: exit:
mcall -1 mcall -1
@ -592,4 +588,6 @@ I_END_2:
path rb 1024+5 path rb 1024+5
rb 65536
I_END: I_END:

View File

@ -225,9 +225,6 @@ ICMP_input:
cmp [ebx + SOCKET.Domain], AF_INET4 cmp [ebx + SOCKET.Domain], AF_INET4
jne .next_socket jne .next_socket
cmp [ebx + SOCKET.Type], SOCK_RAW
jne .next_socket
cmp [ebx + SOCKET.Protocol], IP_PROTO_ICMP cmp [ebx + SOCKET.Protocol], IP_PROTO_ICMP
jne .next_socket jne .next_socket

View File

@ -58,8 +58,8 @@ virtual at IP_SOCKET.end
TCP_SOCKET: TCP_SOCKET:
.LocalPort dw ? ; In INET byte order .LocalPort dw ?
.RemotePort dw ? ; In INET byte order .RemotePort dw ?
.backlog dw ? ; Backlog .backlog dw ? ; Backlog
.backlog_cur dw ? ; current size of queue for un-accept-ed connections .backlog_cur dw ? ; current size of queue for un-accept-ed connections
@ -150,8 +150,8 @@ virtual at IP_SOCKET.end
UDP_SOCKET: UDP_SOCKET:
.LocalPort dw ? ; In INET byte order .LocalPort dw ?
.RemotePort dw ? ; In INET byte order .RemotePort dw ?
.firstpacket db ? .firstpacket db ?
.end: .end:
@ -161,7 +161,7 @@ virtual at IP_SOCKET.end
ICMP_SOCKET: ICMP_SOCKET:
.Identifier dw ? ; .Identifier dw ?
.end: .end:
end virtual end virtual
@ -250,10 +250,9 @@ macro SOCKET_init {
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
sys_socket: sys_socket:
cmp ebx, 8 ; highest possible number cmp ebx, 9 ; highest possible number
jg @f jg @f
lea ebx, [sock_sysfn_table + 4*ebx] jmp dword [sock_sysfn_table + 4*ebx]
jmp dword [ebx]
@@: @@:
cmp ebx, 255 cmp ebx, 255
jz SOCKET_debug jz SOCKET_debug
@ -274,10 +273,8 @@ sock_sysfn_table:
dd SOCKET_accept ; 5 dd SOCKET_accept ; 5
dd SOCKET_send ; 6 dd SOCKET_send ; 6
dd SOCKET_receive ; 7 dd SOCKET_receive ; 7
dd SOCKET_get_opt ; 8 dd SOCKET_set_opt ; 8
; dd SOCKET_set_opt ; 9 dd SOCKET_get_opt ; 9
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
@ -297,24 +294,22 @@ SOCKET_open:
call SOCKET_alloc call SOCKET_alloc
jz s_error jz s_error
mov [esp+32], edi ; return socketnumber
mov [eax + SOCKET.Domain], ecx mov [eax + SOCKET.Domain], ecx
mov [eax + SOCKET.Type], edx mov [eax + SOCKET.Type], edx
mov [eax + SOCKET.Protocol], esi mov [eax + SOCKET.Protocol], esi
mov [esp+32], edi ; return socketnumber
cmp ecx, AF_INET4 cmp ecx, AF_INET4
jne .no_inet4 jne .no_inet4
push [IP_LIST] push [IP_LIST]
pop [eax + IP_SOCKET.LocalIP] ; fill in local ip number pop [eax + IP_SOCKET.LocalIP] ; fill in local ip number
call SOCKET_find_port ; fill in a local port number, application may change it later, or use this one cmp edx, SOCK_DGRAM
cmp edx, IP_PROTO_UDP
je .udp je .udp
cmp edx, IP_PROTO_TCP cmp edx, SOCK_STREAM
je .tcp je .tcp
cmp edx, SOCK_RAW cmp edx, SOCK_RAW
@ -323,7 +318,43 @@ SOCKET_open:
.no_inet4: .no_inet4:
ret ret
align 4
.raw:
; test esi, esi ; IP_PROTO_IP
; jz .ip
cmp esi, IP_PROTO_ICMP
je .icmp
cmp esi, IP_PROTO_UDP
je .udp
cmp esi, IP_PROTO_TCP
je .tcp
ret
align 4
.udp:
mov [eax + SOCKET.Protocol], IP_PROTO_UDP
call SOCKET_find_port ; fill in a local port number, application may change it later, or use this one
push eax
init_queue (eax + SOCKET_QUEUE_LOCATION)
pop eax
mov [eax + SOCKET.snd_proc], SOCKET_send_udp
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
ret
align 4
.tcp: .tcp:
mov [eax + SOCKET.Protocol], IP_PROTO_TCP
call SOCKET_find_port ; fill in a local port number, application may change it later, or use this one
mov ebx, eax mov ebx, eax
lea eax, [ebx + STREAM_SOCKET.snd] lea eax, [ebx + STREAM_SOCKET.snd]
@ -337,26 +368,10 @@ SOCKET_open:
ret ret
.udp:
push eax
init_queue (eax + SOCKET_QUEUE_LOCATION)
pop eax
mov [eax + SOCKET.snd_proc], SOCKET_send_udp
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
ret
.raw:
; test esi, esi
; jz .ip
cmp esi, IP_PROTO_ICMP
je .icmp
ret
;align 4
; .ip: ; .ip:
;
; push eax ; push eax
; init_queue (eax + SOCKET_QUEUE_LOCATION) ; init_queue (eax + SOCKET_QUEUE_LOCATION)
; pop eax ; pop eax
@ -366,7 +381,10 @@ SOCKET_open:
; ;
; ret ; ret
align 4
.icmp: .icmp:
push eax push eax
init_queue (eax + SOCKET_QUEUE_LOCATION) init_queue (eax + SOCKET_QUEUE_LOCATION)
pop eax pop eax
@ -421,8 +439,6 @@ SOCKET_bind:
cmp esi, 6 cmp esi, 6
jl s_error jl s_error
mov ecx, [eax + SOCKET.Type]
mov bx, word [edx + 2] mov bx, word [edx + 2]
test bx, bx test bx, bx
jz .use_preset_port jz .use_preset_port
@ -473,17 +489,21 @@ SOCKET_connect:
.af_inet4: .af_inet4:
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
je .udp je .udp
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
je .tcp je .tcp
cmp [eax + SOCKET.Type], SOCK_RAW cmp [eax + SOCKET.Protocol], IP_PROTO_IP
je .raw je .ip
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
je .ip
jmp s_error jmp s_error
align 4
.udp: .udp:
mov bx , word [edx + 2] mov bx , word [edx + 2]
mov word [eax + UDP_SOCKET.RemotePort], bx mov word [eax + UDP_SOCKET.RemotePort], bx
@ -497,7 +517,7 @@ SOCKET_connect:
mov dword [esp+32], 0 mov dword [esp+32], 0
ret ret
align 4
.tcp: .tcp:
lea ebx, [eax + SOCKET.lock] lea ebx, [eax + SOCKET.lock]
call wait_mutex call wait_mutex
@ -532,7 +552,8 @@ SOCKET_connect:
mov dword [esp+32], 0 ; success! mov dword [esp+32], 0 ; success!
ret ret
.raw: align 4
.ip:
push dword [edx + 4] push dword [edx + 4]
pop dword [eax + IP_SOCKET.RemoteIP] pop dword [eax + IP_SOCKET.RemoteIP]
@ -560,7 +581,7 @@ SOCKET_listen:
cmp word [eax + SOCKET.Domain], AF_INET4 cmp word [eax + SOCKET.Domain], AF_INET4
jne s_error jne s_error
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
jne s_error jne s_error
; TODO: check local port number ; TODO: check local port number
@ -572,7 +593,7 @@ SOCKET_listen:
mov [eax + TCP_SOCKET.backlog], dx mov [eax + TCP_SOCKET.backlog], dx
mov [eax + TCP_SOCKET.t_state], TCB_LISTEN mov [eax + TCP_SOCKET.t_state], TCB_LISTEN
or [eax + SOCKET.options], SO_ACCEPTCON or [eax + SOCKET.options], SO_ACCEPTCON ;;;; TODO: set socket state to listen
mov dword [esp+32], 0 mov dword [esp+32], 0
@ -604,7 +625,7 @@ SOCKET_accept:
.af_inet4: .af_inet4:
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
je .tcp je .tcp
jmp s_error jmp s_error
@ -651,13 +672,16 @@ SOCKET_close:
cmp [eax + SOCKET.Domain], AF_INET4 cmp [eax + SOCKET.Domain], AF_INET4
jne s_error jne s_error
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
je .free je .free
cmp [eax + SOCKET.Type], IP_PROTO_ICMP cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
je .free je .free
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_IP
je .free
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
je .tcp je .tcp
jmp s_error jmp s_error
@ -895,6 +919,14 @@ SOCKET_get_opt:
align 4
SOCKET_set_opt:
ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_debug ; SOCKET_debug
@ -942,10 +974,10 @@ SOCKET_find_port:
push ebx esi ecx push ebx esi ecx
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
je .udp je .udp
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
je .tcp je .tcp
jmp .error jmp .error
@ -986,7 +1018,7 @@ SOCKET_find_port:
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_check_port ; SOCKET_check_port (to be used with AF_INET only!)
; ;
; Checks if a local port number is unused ; Checks if a local port number is unused
; If the proposed port number is unused, it is filled in in the socket structure ; If the proposed port number is unused, it is filled in in the socket structure
@ -1002,7 +1034,7 @@ SOCKET_check_port:
DEBUGF 1,"SOCKET_check_port\n" DEBUGF 1,"SOCKET_check_port\n"
mov ecx, [eax + SOCKET.Type] mov ecx, [eax + SOCKET.Protocol]
mov esi, net_sockets mov esi, net_sockets
.next_socket: .next_socket:
@ -1010,7 +1042,7 @@ SOCKET_check_port:
or esi, esi or esi, esi
jz .port_ok jz .port_ok
cmp [esi + SOCKET.Type], ecx cmp [esi + SOCKET.Protocol], ecx
jne .next_socket jne .next_socket
cmp [esi + UDP_SOCKET.LocalPort], bx cmp [esi + UDP_SOCKET.LocalPort], bx
@ -1404,7 +1436,7 @@ SOCKET_free:
cmp [eax + SOCKET.Domain], AF_INET4 cmp [eax + SOCKET.Domain], AF_INET4
jnz .no_tcp jnz .no_tcp
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
jnz .no_tcp jnz .no_tcp
mov ebx, eax mov ebx, eax
@ -1625,10 +1657,10 @@ SOCKET_process_end:
mov [ebx + SOCKET.PID], 0 mov [ebx + SOCKET.PID], 0
cmp [ebx + SOCKET.Type], IP_PROTO_UDP cmp [ebx + SOCKET.Protocol], IP_PROTO_UDP
je .udp je .udp
cmp [ebx + SOCKET.Type], IP_PROTO_TCP cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP
je .tcp je .tcp
jmp .next_socket ; kill all sockets for given PID jmp .next_socket ; kill all sockets for given PID

View File

@ -135,7 +135,7 @@ local .exit
or eax, eax or eax, eax
jz .exit jz .exit
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP ;;; We should also check if family is AF_INET
jne .loop jne .loop
dec [eax + TCP_SOCKET.timer_ack] dec [eax + TCP_SOCKET.timer_ack]
@ -177,7 +177,7 @@ local .exit
or eax, eax or eax, eax
jz .exit jz .exit
cmp [eax + SOCKET.Type], IP_PROTO_TCP cmp [eax + SOCKET.Protocol], IP_PROTO_TCP ;;; We should also check if family is AF_INET
jne .loop jne .loop
inc [eax + TCP_SOCKET.t_idle] inc [eax + TCP_SOCKET.t_idle]
@ -378,7 +378,7 @@ TCP_input:
or ebx, ebx or ebx, ebx
jz .drop_with_reset jz .drop_with_reset
cmp [ebx + SOCKET.Type], IP_PROTO_TCP cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP ;;; We should also check if family is AF_INET
jne .socket_loop jne .socket_loop
mov ax, [edx + TCP_segment.DestinationPort] mov ax, [edx + TCP_segment.DestinationPort]
@ -1106,6 +1106,8 @@ align 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; code missing (943?) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; code missing (943?)
mov eax, [edx + TCP_segment.AckNumber] mov eax, [edx + TCP_segment.AckNumber]
mov [ebx + TCP_SOCKET.SND_UNA], eax mov [ebx + TCP_SOCKET.SND_UNA], eax
@ -1114,7 +1116,6 @@ align 4
mov [ebx + TCP_SOCKET.SND_NXT], eax mov [ebx + TCP_SOCKET.SND_NXT], eax
@@: @@:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;--------------------------------------- ;---------------------------------------
; Wake up process waiting on send buffer ; Wake up process waiting on send buffer

View File

@ -152,7 +152,7 @@ UDP_input:
jz .dump jz .dump
cmp [eax + SOCKET.Domain], AF_INET4 cmp [eax + SOCKET.Domain], AF_INET4
jne .next_socket jne .next_socket
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
jne .next_socket jne .next_socket
cmp [eax + UDP_SOCKET.LocalPort], si cmp [eax + UDP_SOCKET.LocalPort], si
jne .next_socket jne .next_socket