/kernel/branches/net/applications/network_lib/network.asm |
---|
675,33 → 675,16 |
mov eax, 0x01000100 |
stosd |
; 7. Get DNS server address. |
; Get number of running cards. |
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 |
mcall 75, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address |
cmp eax, -1 |
jz .get_dns_next |
test ecx, ecx |
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 |
je .ret.dnserr |
mov esi, eax ; put server address to esi |
; 8. Open UDP socket to DNS server, port 53. |
; 8a. Create new socket. |
mcall 74, 0, AF_INET, IPPROTO_UDP |
cmp eax, -1 ; error? |
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. |
push 0 |
push 0 ; sin_zero |
708,7 → 691,7 |
push esi ; sin_addr |
push AF_INET + (53 shl 24) |
; sin_family and sin_port in network byte order |
; 8c. Call the system. |
; 8c. Connect. |
mcall 74, 4, , esp, sizeof.sockaddr_in |
; 8d. Restore the stack, undo 8b. |
add esp, esi |
778,7 → 761,7 |
; 2. Read UDP datagram. |
mov ecx, [edi+__gai_reqdata.socket] |
push edi |
mcall 74, 6, , , 512, 0 |
mcall 74, 7, , , 512, 0 |
pop edi |
; 3. Ignore events for other sockets (return if no data read) |
test eax, eax |
/kernel/branches/net/network/IPv4.inc |
---|
512,6 → 512,16 |
cmp ecx, 1480 |
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 |
cmp eax, -1 |
/kernel/branches/net/network/socket.inc |
---|
722,9 → 722,11 |
cmp [eax + SOCKET.LocalPort],0 |
jne .port_ok |
push esi |
mov ecx, [eax + SOCKET.Type] |
call socket_find_port |
test bx, bx |
pop esi |
je s_error |
mov [eax + SOCKET.LocalPort], bx |
733,7 → 735,7 |
mov ecx, esi |
mov esi, edx |
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 eax, [eax + SOCKET.RemoteIP] |
787,7 → 789,7 |
align 4 |
socket_find_port: |
DEBUGF 1,"Socket_find_free_port, type: %u ",eax |
DEBUGF 1,"Socket_find_free_port\n" |
cmp ecx, IP_PROTO_UDP |
je .udp |
/kernel/branches/net/network/udp.inc |
---|
95,6 → 95,8 |
cmp [eax + SOCKET.LocalPort], bx |
jne .next_socket |
DEBUGF 1,"found socket with matching domain, type and localport\n" |
; For dhcp, we must allow any remote server to respond. |
; 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 |
103,10 → 105,12 |
je .ok1 |
mov ebx, [esp] |
mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet |
cmp [eax + SOCKET.RemoteIP], eax |
mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet FIXME |
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 |
DEBUGF 1,"Remote Ip matches\n" |
.ok1: |
mov bx, [edx + UDP_Packet.SourcePort] ; Remote port must be 0, or equal to sourceport of packet |