More fixes in UDP, IPv4 and socket code.

Fixes in network library, nslookup works now.

git-svn-id: svn://kolibrios.org@1208 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2009-10-12 18:14:14 +00:00
parent 3bff332168
commit 7c8d55d5bb
4 changed files with 27 additions and 28 deletions

View File

@ -675,40 +675,23 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value
mov eax, 0x01000100 mov eax, 0x01000100
stosd stosd
; 7. Get DNS server address. ; 7. Get DNS server address.
; Get number of running cards. mcall 75, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address
mcall 73, -1
xchg eax, edx
; Loop for all initialized network cards, scanning for initialized DNS address.
mov ebx, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address
.get_dns_loop:
mcall 75
cmp eax, -1 cmp eax, -1
jz .get_dns_next je .ret.dnserr
test ecx, ecx mov esi, eax ; put server address to esi
jnz .got_dns
dec edx
jz .get_dns_done
.get_dns_next:
inc bh
jnz .get_dns_loop
; all possible devices were checked, none found - return error
.get_dns_done:
jmp .ret.dnserr
.got_dns:
mov esi, ecx ; put server address to esi
; 8. Open UDP socket to DNS server, port 53. ; 8. Open UDP socket to DNS server, port 53.
; 8a. Create new socket. ; 8a. Create new socket.
mcall 74, 0, AF_INET, IPPROTO_UDP mcall 74, 0, AF_INET, IPPROTO_UDP
cmp eax, -1 ; error? cmp eax, -1 ; error?
jz .ret.dnserr jz .ret.dnserr
xchg ecx, eax ; put socket handle to ecx mov ecx, eax ; put socket 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 24) push AF_INET + (53 shl 24)
; sin_family and sin_port in network byte order ; sin_family and sin_port in network byte order
; 8c. Call the system. ; 8c. Connect.
mcall 74, 4, , esp, sizeof.sockaddr_in mcall 74, 4, , esp, sizeof.sockaddr_in
; 8d. Restore the stack, undo 8b. ; 8d. Restore the stack, undo 8b.
add esp, esi add esp, esi
@ -778,7 +761,7 @@ end virtual
; 2. Read UDP datagram. ; 2. Read UDP datagram.
mov ecx, [edi+__gai_reqdata.socket] mov ecx, [edi+__gai_reqdata.socket]
push edi push edi
mcall 74, 6, , , 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 sockets (return if no data read)
test eax, eax test eax, eax

View File

@ -512,6 +512,16 @@ IPv4_create_packet:
cmp ecx, 1480 cmp ecx, 1480
jg .exit_ jg .exit_
cmp ebx, ebx ; if dest ip = 0
jnz .ip_ok ; and local ip is valid
; use local ip instead
cmp [IP_LIST],0xffffffff ;
je .ip_ok ; TODO: find solution to send broadcast
; on device other then device 0
mov ebx, [IP_LIST] ;
;
.ip_ok: ;
push ecx eax ebx dx di push ecx eax ebx dx di
cmp eax, -1 cmp eax, -1

View File

@ -722,9 +722,11 @@ socket_send:
cmp [eax + SOCKET.LocalPort],0 cmp [eax + SOCKET.LocalPort],0
jne .port_ok jne .port_ok
push esi
mov ecx, [eax + SOCKET.Type] mov ecx, [eax + SOCKET.Type]
call socket_find_port call socket_find_port
test bx, bx test bx, bx
pop esi
je s_error je s_error
mov [eax + SOCKET.LocalPort], bx mov [eax + SOCKET.LocalPort], bx
@ -733,7 +735,7 @@ socket_send:
mov ecx, esi mov ecx, esi
mov esi, edx mov esi, edx
mov edx, dword [eax + SOCKET.LocalPort] ; load local port and remote port at once mov edx, dword [eax + SOCKET.LocalPort] ; load local port and remote port at once
DEBUGF 1,"local port: %x, remote port: %x\n",[eax + SOCKET.LocalPort]:2, [eax + SOCKET.RemotePort]:2 DEBUGF 1,"local port: %x, remote port: %x\n",[eax + SOCKET.LocalPort]:4, [eax + SOCKET.RemotePort]:4
mov ebx, [eax + SOCKET.LocalIP] mov ebx, [eax + SOCKET.LocalIP]
mov eax, [eax + SOCKET.RemoteIP] mov eax, [eax + SOCKET.RemoteIP]
@ -787,7 +789,7 @@ socket_send:
align 4 align 4
socket_find_port: socket_find_port:
DEBUGF 1,"Socket_find_free_port, type: %u ",eax DEBUGF 1,"Socket_find_free_port\n"
cmp ecx, IP_PROTO_UDP cmp ecx, IP_PROTO_UDP
je .udp je .udp

View File

@ -95,6 +95,8 @@ UDP_handler:
cmp [eax + SOCKET.LocalPort], bx cmp [eax + SOCKET.LocalPort], bx
jne .next_socket jne .next_socket
DEBUGF 1,"found socket with matching domain, type and localport\n"
; For dhcp, we must allow any remote server to respond. ; For dhcp, we must allow any remote server to respond.
; I will accept the first incoming response to be the one ; I will accept the first incoming response to be the one
; I bind to, if the socket is opened with a destination IP address of ; I bind to, if the socket is opened with a destination IP address of
@ -103,15 +105,17 @@ UDP_handler:
je .ok1 je .ok1
mov ebx, [esp] mov ebx, [esp]
mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet FIXME
cmp [eax + SOCKET.RemoteIP], eax cmp [eax + SOCKET.RemoteIP], ebx
jne .try_more ; Quit if the source IP is not valid, check for more sockets with this IP/PORT combination jne .try_more ; Quit if the source IP is not valid, check for more sockets with this IP/PORT combination
DEBUGF 1,"Remote Ip matches\n"
.ok1: .ok1:
mov bx, [edx + UDP_Packet.SourcePort] ; Remote port must be 0, or equal to sourceport of packet mov bx, [edx + UDP_Packet.SourcePort] ; Remote port must be 0, or equal to sourceport of packet
cmp [eax + SOCKET.RemotePort],0 cmp [eax + SOCKET.RemotePort], 0
je .ok2 je .ok2
cmp [eax + SOCKET.RemotePort], bx cmp [eax + SOCKET.RemotePort], bx