diff --git a/kernel/branches/net/applications/ftpd/commands.inc b/kernel/branches/net/applications/ftpd/commands.inc index cddd95f525..97506da22d 100644 --- a/kernel/branches/net/applications/ftpd/commands.inc +++ b/kernel/branches/net/applications/ftpd/commands.inc @@ -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 diff --git a/kernel/branches/net/applications/ftpd/ftpd.asm b/kernel/branches/net/applications/ftpd/ftpd.asm index c36fd0a98a..340f059c50 100644 --- a/kernel/branches/net/applications/ftpd/ftpd.asm +++ b/kernel/branches/net/applications/ftpd/ftpd.asm @@ -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 diff --git a/kernel/branches/net/applications/libraries/network/network.asm b/kernel/branches/net/applications/libraries/network/network.asm index ca015b92f5..d9f6073850 100644 --- a/kernel/branches/net/applications/libraries/network/network.asm +++ b/kernel/branches/net/applications/libraries/network/network.asm @@ -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 diff --git a/kernel/branches/net/applications/synergyc/synergyc.asm b/kernel/branches/net/applications/synergyc/synergyc.asm index 0884d9f46c..b2c20fb3be 100644 --- a/kernel/branches/net/applications/synergyc/synergyc.asm +++ b/kernel/branches/net/applications/synergyc/synergyc.asm @@ -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 diff --git a/kernel/branches/net/applications/tcpserv/tcpserv.asm b/kernel/branches/net/applications/tcpserv/tcpserv.asm index a122985e8d..6e71f2b468 100644 --- a/kernel/branches/net/applications/tcpserv/tcpserv.asm +++ b/kernel/branches/net/applications/tcpserv/tcpserv.asm @@ -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 diff --git a/kernel/branches/net/applications/telnet/telnet.asm b/kernel/branches/net/applications/telnet/telnet.asm index 239270c2a1..2fc34048c6 100644 --- a/kernel/branches/net/applications/telnet/telnet.asm +++ b/kernel/branches/net/applications/telnet/telnet.asm @@ -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 diff --git a/kernel/branches/net/applications/tftpc/tftpc.asm b/kernel/branches/net/applications/tftpc/tftpc.asm index e11e0d48ca..8bad637eb0 100644 --- a/kernel/branches/net/applications/tftpc/tftpc.asm +++ b/kernel/branches/net/applications/tftpc/tftpc.asm @@ -141,27 +141,27 @@ key: align 4 draw_window: mcall 12,1 - mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title + mcall 0, (50*65536+400), (30*65536+180), 0x34AABBCC, 0x085080DD, str_title - mcall 4,35*65536+10,0x80000000, str_server + mcall 4, 35*65536+10, 0x80000000, str_server - mov ebx,5*65536+ 30 + mov ebx, 5*65536+30 mov edx, str_source mcall - mov ebx,11*65536+ 50 + mov ebx, 11*65536+50 mov edx, str_destination mcall - mov ebx,47*65536+72 + mov ebx, 47*65536+72 mov edx, str_mode mcall - mov ebx,160*65536+72 + mov ebx, 160*65536+72 mov edx, str_method mcall - mov ebx,270*65536+72 + mov ebx, 270*65536+72 mov edx, str_blocksize mcall @@ -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 diff --git a/kernel/branches/net/applications/vncc/vncc.asm b/kernel/branches/net/applications/vncc/vncc.asm index f284df1c8e..9887fa1b6f 100644 --- a/kernel/branches/net/applications/vncc/vncc.asm +++ b/kernel/branches/net/applications/vncc/vncc.asm @@ -238,7 +238,7 @@ pointerevent db 5 ; pointerevent sockaddr1: dw AF_INET4 -.port dw 5900 +.port dw 0x0c17 ; 5900 .ip dd 0 rb 10 diff --git a/kernel/branches/net/applications/zeroconf/zeroconf.asm b/kernel/branches/net/applications/zeroconf/zeroconf.asm index 5374e91d1d..9e8c370369 100644 --- a/kernel/branches/net/applications/zeroconf/zeroconf.asm +++ b/kernel/branches/net/applications/zeroconf/zeroconf.asm @@ -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 diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 21ac290920..9cb5c55b2d 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -375,7 +375,7 @@ IPv4_input: ; TODO: add IPv4 mov [esi + FRAGMENT_slot.ttl], 15 ; RFC recommends 15 secs as ttl mov ax, [edx + IPv4_header.Identification] mov [esi + FRAGMENT_slot.id], ax - mov eax,[edx + IPv4_header.SourceAddress] + mov eax, [edx + IPv4_header.SourceAddress] mov [esi + FRAGMENT_slot.SrcIP], eax mov eax, [edx + IPv4_header.DestinationAddress] mov [esi + FRAGMENT_slot.DstIP], eax diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 6640e0078e..414fdf19bf 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -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 diff --git a/kernel/branches/net/network/stack.inc b/kernel/branches/net/network/stack.inc index 71c93906d5..54578608bb 100644 --- a/kernel/branches/net/network/stack.inc +++ b/kernel/branches/net/network/stack.inc @@ -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 diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index e69601fb87..e482ee8340 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -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 diff --git a/kernel/branches/net/network/tcp_output.inc b/kernel/branches/net/network/tcp_output.inc index 50d969f7f7..0570b3c6aa 100644 --- a/kernel/branches/net/network/tcp_output.inc +++ b/kernel/branches/net/network/tcp_output.inc @@ -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 diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index 46cae23758..128bf05e88 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -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 diff --git a/kernel/branches/net/network/udp.inc b/kernel/branches/net/network/udp.inc index 60abea1d5f..2b9a5ad0de 100644 --- a/kernel/branches/net/network/udp.inc +++ b/kernel/branches/net/network/udp.inc @@ -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