forked from KolibriOS/kolibrios
Port numbers for TCP and UDP must be given in Big endian order now.
git-svn-id: svn://kolibrios.org@2995 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8e79162d05
commit
151ae82c14
@ -763,11 +763,11 @@ cmdPASV:
|
||||
mov al, ','
|
||||
stosb
|
||||
; port
|
||||
movzx eax, byte [ebp + thread_data.datasock.sin_port + 1]
|
||||
movzx eax, byte [ebp + thread_data.datasock.sin_port]
|
||||
call dword_to_ascii
|
||||
mov al, ','
|
||||
stosb
|
||||
movzx eax, byte [ebp + thread_data.datasock.sin_port]
|
||||
movzx eax, byte [ebp + thread_data.datasock.sin_port+1]
|
||||
call dword_to_ascii
|
||||
; ')', 13, 10, 0
|
||||
mov eax, ')' + 0x000a0d00
|
||||
@ -843,13 +843,10 @@ cmdPORT:
|
||||
; Now the same with portnumber
|
||||
inc esi
|
||||
call ascii_to_byte
|
||||
mov bh, al
|
||||
mov byte[ebp + thread_data.datasock.sin_port], al
|
||||
inc esi
|
||||
call ascii_to_byte
|
||||
mov bl, al
|
||||
|
||||
; Save it in datasock too
|
||||
mov [ebp + thread_data.datasock.sin_port], bx
|
||||
mov byte[ebp + thread_data.datasock.sin_port+1], al
|
||||
|
||||
; We will open the socket, but do not connect yet!
|
||||
mov [ebp + thread_data.datasock.sin_family], AF_INET4
|
||||
|
@ -126,8 +126,10 @@ start:
|
||||
mov [serverip], ebx
|
||||
|
||||
invoke ini.get_int, path, str_ftpd, str_port, 21
|
||||
xchg al, ah
|
||||
mov [sockaddr1.port], ax
|
||||
|
||||
xchg al, ah
|
||||
invoke con_printf, str1, eax
|
||||
add esp, 8
|
||||
|
||||
@ -378,7 +380,7 @@ str_end db 'end', 0
|
||||
|
||||
sockaddr1:
|
||||
dw AF_INET4
|
||||
.port dw 21
|
||||
.port dw 0
|
||||
.ip dd 0
|
||||
rb 10
|
||||
.length = $ - sockaddr1
|
||||
|
@ -689,7 +689,7 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value
|
||||
push 0
|
||||
push 0 ; sin_zero
|
||||
push esi ; sin_addr
|
||||
push AF_INET4 + (53 shl 16)
|
||||
push AF_INET4 + (53 shl 24)
|
||||
; sin_family and sin_port in network byte order
|
||||
; 8c. Connect.
|
||||
mcall 75, 4, , esp, sizeof.sockaddr_in
|
||||
@ -1204,7 +1204,7 @@ getaddrinfo._.generate_data: ;;
|
||||
; Just copy port from input __gai_reqdata to output addrinfo.
|
||||
push edx
|
||||
mov edx, [ebx+__gai_reqdata.service]
|
||||
xchg dl, dh ; convert to network byte order
|
||||
xchg dl, dh ; convert to network byte order ;;;;; CHECKME
|
||||
mov [edi+sizeof.addrinfo+sockaddr_in.sin_port], dx
|
||||
pop edx
|
||||
ret
|
||||
|
@ -29,7 +29,9 @@ use32
|
||||
__DEBUG__ equ 1 ; enable/disable
|
||||
__DEBUG_LEVEL__ equ 1 ; 1 = all, 2 = errors
|
||||
|
||||
|
||||
BUFFERSIZE equ 1024
|
||||
DEFAULTPORT equ 24800
|
||||
|
||||
include '../macros.inc'
|
||||
purge mov,add,sub
|
||||
@ -79,7 +81,8 @@ start:
|
||||
test eax, eax
|
||||
jnz error
|
||||
|
||||
invoke ini.get_int, path, str_remote, str_port, 24800
|
||||
invoke ini.get_int, path, str_remote, str_port, DEFAULTPORT
|
||||
xchg al, ah
|
||||
mov [sockaddr1.port], ax
|
||||
|
||||
push str1
|
||||
@ -337,7 +340,7 @@ mousestate dd 0
|
||||
|
||||
sockaddr1:
|
||||
dw AF_INET4
|
||||
.port dw 24800
|
||||
.port dw 0
|
||||
.ip dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24
|
||||
rb 10
|
||||
|
||||
|
@ -135,7 +135,7 @@ hello db 'Hello world!',0
|
||||
|
||||
sockaddr1:
|
||||
dw AF_INET4
|
||||
.port dw 23
|
||||
.port dw 0x1700 ; 23
|
||||
.ip dd 0
|
||||
rb 10
|
||||
.length = $ - sockaddr1
|
||||
|
@ -264,7 +264,7 @@ str10 db 'Push any key to continue.',0
|
||||
|
||||
sockaddr1:
|
||||
dw AF_INET4
|
||||
.port dw 23
|
||||
.port dw 0x1700 ; 23
|
||||
.ip dd 0
|
||||
rb 10
|
||||
|
||||
|
@ -451,7 +451,7 @@ done dd 0
|
||||
|
||||
sockaddr:
|
||||
dw AF_INET4
|
||||
dw 69
|
||||
dw 0x4500 ; 69
|
||||
IP db 192,168,1,115
|
||||
sockaddr_len = $ - sockaddr
|
||||
|
||||
|
@ -238,7 +238,7 @@ pointerevent db 5 ; pointerevent
|
||||
|
||||
sockaddr1:
|
||||
dw AF_INET4
|
||||
.port dw 5900
|
||||
.port dw 0x0c17 ; 5900
|
||||
.ip dd 0
|
||||
rb 10
|
||||
|
||||
|
@ -548,7 +548,7 @@ str_type db 'type',0
|
||||
sockaddr1:
|
||||
|
||||
dw AF_INET4
|
||||
dw 68 ; local port
|
||||
dw 68 shl 8 ; local port
|
||||
dd 0 ; local IP
|
||||
|
||||
rb 10
|
||||
@ -557,7 +557,7 @@ sockaddr1:
|
||||
sockaddr2:
|
||||
|
||||
dw AF_INET4
|
||||
dw 67 ; destination port
|
||||
dw 67 shl 8 ; destination port
|
||||
dd -1 ; destination IP
|
||||
|
||||
rb 10
|
||||
|
@ -44,15 +44,15 @@ ends
|
||||
|
||||
struct IP_SOCKET SOCKET
|
||||
|
||||
LocalIP rd 4
|
||||
RemoteIP rd 4
|
||||
LocalIP rd 4 ; network byte order
|
||||
RemoteIP rd 4 ; network byte order
|
||||
|
||||
ends
|
||||
|
||||
struct TCP_SOCKET IP_SOCKET
|
||||
|
||||
LocalPort dw ?
|
||||
RemotePort dw ?
|
||||
LocalPort dw ? ; network byte order
|
||||
RemotePort dw ? ; network byte order
|
||||
|
||||
t_state dd ? ; TCB state
|
||||
t_rxtshift db ?
|
||||
@ -141,8 +141,8 @@ ends
|
||||
|
||||
struct UDP_SOCKET IP_SOCKET
|
||||
|
||||
LocalPort dw ?
|
||||
RemotePort dw ?
|
||||
LocalPort dw ? ; network byte order
|
||||
RemotePort dw ? ; network byte order
|
||||
firstpacket db ?
|
||||
|
||||
ends
|
||||
@ -213,6 +213,7 @@ macro SOCKET_init {
|
||||
jb @r
|
||||
cmp ax, MAX_EPHEMERAL_PORT
|
||||
ja @r
|
||||
xchg al, ah
|
||||
mov [last_UDP_port], ax
|
||||
|
||||
@@:
|
||||
@ -221,6 +222,7 @@ macro SOCKET_init {
|
||||
jb @r
|
||||
cmp ax, MAX_EPHEMERAL_PORT
|
||||
ja @r
|
||||
xchg al, ah
|
||||
mov [last_TCP_port], ax
|
||||
|
||||
}
|
||||
@ -446,7 +448,7 @@ SOCKET_bind:
|
||||
@@:
|
||||
mov [eax + IP_SOCKET.LocalIP], ebx
|
||||
|
||||
mov bx, [edx + 2] ; Now fill in the port if it's still available
|
||||
mov bx, [edx + 2] ; Now fill in the local port if it's still available
|
||||
call SOCKET_check_port
|
||||
jz s_error ; ZF is set by socket_check_port, on error
|
||||
|
||||
@ -1106,11 +1108,6 @@ SOCKET_find_port:
|
||||
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
||||
je .tcp
|
||||
|
||||
jmp .error
|
||||
|
||||
.done:
|
||||
mov [eax + UDP_SOCKET.LocalPort], bx
|
||||
.error:
|
||||
pop ecx esi ebx
|
||||
ret
|
||||
|
||||
@ -1118,26 +1115,30 @@ SOCKET_find_port:
|
||||
mov bx, [last_UDP_port]
|
||||
call .findit
|
||||
mov [last_UDP_port], bx
|
||||
jmp .done
|
||||
|
||||
pop ecx esi ebx
|
||||
ret
|
||||
|
||||
.tcp:
|
||||
mov bx, [last_TCP_port]
|
||||
call .findit
|
||||
mov [last_TCP_port], bx
|
||||
jmp .done
|
||||
|
||||
pop ecx esi ebx
|
||||
ret
|
||||
|
||||
|
||||
.restart:
|
||||
mov bx, MIN_EPHEMERAL_PORT
|
||||
mov bx, MIN_EPHEMERAL_PORT_N
|
||||
.findit:
|
||||
inc bx
|
||||
cmp bx, MAX_EPHEMERAL_PORT_N
|
||||
je .restart
|
||||
|
||||
cmp bx, MAX_EPHEMERAL_PORT
|
||||
jz .restart
|
||||
add bh, 1
|
||||
adc bl, 0
|
||||
|
||||
call SOCKET_check_port
|
||||
jz .findit
|
||||
|
||||
ret
|
||||
|
||||
|
||||
@ -1150,9 +1151,9 @@ SOCKET_find_port:
|
||||
; If the proposed port number is unused, it is filled in in the socket structure
|
||||
;
|
||||
; IN: eax = socket ptr (to find out if its a TCP/UDP socket)
|
||||
; bx = proposed socket number
|
||||
; bx = proposed socket number (network byte order)
|
||||
;
|
||||
; OUT: ZF = cleared on error
|
||||
; OUT: ZF = set on error
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
@ -1182,10 +1183,9 @@ SOCKET_check_port:
|
||||
ret
|
||||
|
||||
.port_ok:
|
||||
DEBUGF 1,"local port %u is free\n", bx
|
||||
DEBUGF 1,"local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf
|
||||
mov [eax + UDP_SOCKET.LocalPort], bx
|
||||
or bx, bx ; set the zero-flag
|
||||
|
||||
or bx, bx ; clear the zero-flag
|
||||
ret
|
||||
|
||||
|
||||
|
@ -34,7 +34,9 @@ endg
|
||||
MAX_NET_DEVICES = 16
|
||||
|
||||
MIN_EPHEMERAL_PORT = 49152
|
||||
MIN_EPHEMERAL_PORT_N = 0x00C0 ; same in Network byte order (FIXME)
|
||||
MAX_EPHEMERAL_PORT = 61000
|
||||
MAX_EPHEMERAL_PORT_N = 0x48EE ; same in Network byte order (FIXME)
|
||||
|
||||
; Ethernet protocol numbers
|
||||
ETHER_ARP = 0x0608
|
||||
|
@ -76,8 +76,6 @@ TCP_input:
|
||||
|
||||
ntohw [edx + TCP_header.Window]
|
||||
ntohw [edx + TCP_header.UrgentPointer]
|
||||
ntohw [edx + TCP_header.SourcePort]
|
||||
ntohw [edx + TCP_header.DestinationPort]
|
||||
|
||||
;------------------------
|
||||
; Find the socket pointer
|
||||
|
@ -425,10 +425,7 @@ TCP_send:
|
||||
ntohd [esp]
|
||||
|
||||
push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ?
|
||||
ntohw [esp]
|
||||
|
||||
push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ?
|
||||
ntohw [esp]
|
||||
|
||||
push edi ; header size
|
||||
|
||||
|
@ -348,10 +348,8 @@ TCP_respond_socket:
|
||||
; Fill in the TCP header by using the socket ptr
|
||||
|
||||
mov ax, [esi + TCP_SOCKET.LocalPort]
|
||||
rol ax, 8
|
||||
stosw
|
||||
mov ax, [esi + TCP_SOCKET.RemotePort]
|
||||
rol ax, 8
|
||||
stosw
|
||||
mov eax, [esi + TCP_SOCKET.SND_NXT]
|
||||
bswap eax
|
||||
@ -429,10 +427,8 @@ TCP_respond_segment:
|
||||
; Fill in the TCP header by using a received segment
|
||||
|
||||
mov ax, [esi + TCP_header.DestinationPort]
|
||||
rol ax, 8
|
||||
stosw
|
||||
mov ax, [esi + TCP_header.SourcePort]
|
||||
rol ax, 8
|
||||
stosw
|
||||
mov eax, [esi + TCP_header.AckNumber]
|
||||
bswap eax
|
||||
|
@ -131,10 +131,8 @@ UDP_input:
|
||||
.no_checksum:
|
||||
DEBUGF 1,"UDP_input: checksum ok\n"
|
||||
|
||||
; Convert port numbers to intel format
|
||||
; Convert length to little endian
|
||||
|
||||
rol [esi + UDP_header.DestinationPort], 8
|
||||
rol [esi + UDP_header.SourcePort], 8
|
||||
rol [esi + UDP_header.Length], 8
|
||||
|
||||
; Look for a socket where
|
||||
@ -198,7 +196,7 @@ UDP_input:
|
||||
call mutex_lock
|
||||
popa
|
||||
|
||||
DEBUGF 1,"UDP_input: new remote port=%u\n", cx
|
||||
DEBUGF 1,"UDP_input: new remote port=%x\n", cx ; FIXME: find a way to print big endian values with debugf
|
||||
mov [eax + UDP_SOCKET.RemotePort], cx
|
||||
inc [eax + UDP_SOCKET.firstpacket]
|
||||
|
||||
@ -234,12 +232,10 @@ UDP_output:
|
||||
DEBUGF 1,"UDP_output: socket=%x bytes=%u data_ptr=%x\n", eax, ecx, esi
|
||||
|
||||
mov dx, [eax + UDP_SOCKET.RemotePort]
|
||||
DEBUGF 1,"UDP_output: remote port=%u, ", dx
|
||||
rol dx, 8
|
||||
DEBUGF 1,"UDP_output: remote port=%x, ", dx ; FIXME: find a way to print big endian values with debugf
|
||||
rol edx, 16
|
||||
mov dx, [eax + UDP_SOCKET.LocalPort]
|
||||
DEBUGF 1,"local port=%u\n", dx
|
||||
rol dx, 8
|
||||
DEBUGF 1,"local port=%x\n", dx
|
||||
|
||||
sub esp, 8 ; Data ptr and data size will be placed here
|
||||
push edx esi
|
||||
|
Loading…
Reference in New Issue
Block a user