From 949b920321005b2aa05c67e637206fa4fcc14d7d Mon Sep 17 00:00:00 2001
From: hidnplayr <hidnplayr@kolibrios.org>
Date: Sat, 29 Dec 2012 22:22:10 +0000
Subject: [PATCH] Added TCP_mss (max segment size) stub. Bugfix in FTPD
 concerning data ports.

git-svn-id: svn://kolibrios.org@3144 a494cfbc-eb01-0410-851d-a64ba20cac60
---
 .../branches/net/applications/ftpd/commands.inc |  5 +++--
 kernel/branches/net/applications/ftpd/ftpd.asm  |  5 +++++
 kernel/branches/net/network/tcp_input.inc       |  2 +-
 kernel/branches/net/network/tcp_subr.inc        | 17 +++++++++++++++++
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/kernel/branches/net/applications/ftpd/commands.inc b/kernel/branches/net/applications/ftpd/commands.inc
index 97506da22d..f5bc9bb2d2 100644
--- a/kernel/branches/net/applications/ftpd/commands.inc
+++ b/kernel/branches/net/applications/ftpd/commands.inc
@@ -720,8 +720,9 @@ cmdPASV:
 
   .next_port:                                                   ; TODO: break the endless loop
         call    nextpasvport
-        pushw   [pasv_port]
-        popw    [ebp + thread_data.datasock.sin_port]
+        mov     ax, [pasv_port]
+        xchg    al, ah
+        mov     [ebp + thread_data.datasock.sin_port], ax
 
         mcall   bind
         cmp     eax, -1
diff --git a/kernel/branches/net/applications/ftpd/ftpd.asm b/kernel/branches/net/applications/ftpd/ftpd.asm
index 340f059c50..1378897f27 100644
--- a/kernel/branches/net/applications/ftpd/ftpd.asm
+++ b/kernel/branches/net/applications/ftpd/ftpd.asm
@@ -51,6 +51,9 @@ ABORT                   = 1 shl 31
 format binary as ""
 
 use32
+
+        org     0x0
+
         db      'MENUET01'      ; signature
         dd      1               ; header version
         dd      start           ; entry point
@@ -119,6 +122,7 @@ start:
         invoke  con_start, 1
         invoke  con_init, -1, -1, -1, -1, title
 
+; get settings from ini
         invoke  ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0
         mov     esi, ini_buf
         mov     cl, '.'
@@ -133,6 +137,7 @@ start:
         invoke  con_printf, str1, eax
         add     esp, 8
 
+; open listening socket
         mcall   socket, AF_INET4, SOCK_STREAM, 0
         cmp     eax, -1
         je      sock_err
diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc
index e2e2c9c056..5a2ceba51a 100644
--- a/kernel/branches/net/network/tcp_input.inc
+++ b/kernel/branches/net/network/tcp_input.inc
@@ -243,7 +243,7 @@ TCP_input:
         lodsw
         rol     ax, 8
         DEBUGF  1,"TCP_input: Maxseg=%u\n", ax
-        mov     [ebx + TCP_SOCKET.t_maxseg], eax
+        call    TCP_mss
        @@:
         jmp     .opt_loop
 
diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc
index 5bedabeaac..9af2ecfb50 100644
--- a/kernel/branches/net/network/tcp_subr.inc
+++ b/kernel/branches/net/network/tcp_subr.inc
@@ -594,3 +594,20 @@ TCP_xmit_timer:
         pop     ecx
 
         ret
+
+
+
+
+; eax = max segment size
+; ebx = socket ptr
+align 4
+TCP_mss:
+
+        cmp     eax, 1420                               ; FIXME
+        jbe     @f
+        mov     eax, 1420
+  @@:
+        mov     [ebx + TCP_SOCKET.t_maxseg], eax
+
+
+        ret