From 4f5e5cb45b151b337469a8460cad248247b6378a Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Tue, 17 Apr 2012 19:00:13 +0000 Subject: [PATCH] SOCKET_bind now checks if the localport is not already in use. SOCKET_check_port now works correctly if the computer has multiple IP addresses git-svn-id: svn://kolibrios.org@2622 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/socket.inc | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 59ee57a278..67cf19c8b7 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -383,11 +383,28 @@ SOCKET_bind: cmp esi, 6 jb s_error - pushw [edx + 2] - pop [eax + UDP_SOCKET.LocalPort] + cmp [eax + SOCKET.Protocol], IP_PROTO_UDP + je .udp - pushd [edx + 4] - pop [eax + IP_SOCKET.LocalIP] + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + je .tcp + + jmp s_error + + .tcp: + .udp: + + mov ebx, [edx + 4] ; First, fill in the IP + test ebx, ebx ; If IP is 0, use default + jnz @f + mov ebx, [NET_DEFAULT] + mov ebx, [IP_LIST + 4*ebx] + @@: + mov [eax + IP_SOCKET.LocalIP], ebx + + mov bx, [edx + 2] ; Now fill in the port if it's still available + call SOCKET_check_port + jz s_error ; ZF is set by socket_check_port, on error DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ @@ -1021,6 +1038,7 @@ SOCKET_check_port: DEBUGF 1,"SOCKET_check_port\n" mov ecx, [eax + SOCKET.Protocol] + mov edx, [eax + IP_SOCKET.LocalIP] mov esi, net_sockets .next_socket: @@ -1031,6 +1049,9 @@ SOCKET_check_port: cmp [esi + SOCKET.Protocol], ecx jne .next_socket + cmp [esi + IP_SOCKET.LocalIP], edx + jne .next_socket + cmp [esi + UDP_SOCKET.LocalPort], bx jne .next_socket