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
This commit is contained in:
hidnplayr 2012-04-17 19:00:13 +00:00
parent a83978c197
commit 4f5e5cb45b

View File

@ -383,11 +383,28 @@ SOCKET_bind:
cmp esi, 6 cmp esi, 6
jb s_error jb s_error
pushw [edx + 2] cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
pop [eax + UDP_SOCKET.LocalPort] je .udp
pushd [edx + 4] cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
pop [eax + IP_SOCKET.LocalIP] 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",\ DEBUGF 1,"local ip: %u.%u.%u.%u\n",\
[eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ [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" DEBUGF 1,"SOCKET_check_port\n"
mov ecx, [eax + SOCKET.Protocol] mov ecx, [eax + SOCKET.Protocol]
mov edx, [eax + IP_SOCKET.LocalIP]
mov esi, net_sockets mov esi, net_sockets
.next_socket: .next_socket:
@ -1031,6 +1049,9 @@ SOCKET_check_port:
cmp [esi + SOCKET.Protocol], ecx cmp [esi + SOCKET.Protocol], ecx
jne .next_socket jne .next_socket
cmp [esi + IP_SOCKET.LocalIP], edx
jne .next_socket
cmp [esi + UDP_SOCKET.LocalPort], bx cmp [esi + UDP_SOCKET.LocalPort], bx
jne .next_socket jne .next_socket