2009-09-17 13:55:38 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-02-21 09:44:51 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
2012-07-24 22:29:46 +02:00
|
|
|
;; Part of the tcp/ip network stack for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org, ;;
|
2010-07-27 20:53:38 +02:00
|
|
|
;; and Clevermouse. ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; ;;
|
2010-07-27 20:53:38 +02:00
|
|
|
;; Based on code by mike.dld ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
$Revision$
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2011-01-28 17:49:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct SOCKET
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
NextPtr dd ? ; pointer to next socket in list
|
|
|
|
PrevPtr dd ? ; pointer to previous socket in list
|
|
|
|
Number dd ? ; socket number
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mutex MUTEX
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
PID dd ? ; application process id
|
|
|
|
Domain dd ? ; INET/UNIX/..
|
|
|
|
Type dd ? ; RAW/STREAM/DGRAP
|
|
|
|
Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP
|
|
|
|
errorcode dd ?
|
2012-07-17 23:36:34 +02:00
|
|
|
device dd ?
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
options dd ?
|
|
|
|
state dd ?
|
|
|
|
backlog dw ? ; how many incomming connections that can be queued
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
snd_proc dd ?
|
|
|
|
rcv_proc dd ?
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct IP_SOCKET SOCKET
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
LocalIP rd 4
|
|
|
|
RemoteIP rd 4
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct TCP_SOCKET IP_SOCKET
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
LocalPort dw ?
|
|
|
|
RemotePort dw ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
t_state dd ? ; TCB state
|
2012-08-28 22:48:45 +02:00
|
|
|
t_rxtshift db ?
|
|
|
|
rb 3 ; align
|
2012-02-25 13:03:22 +01:00
|
|
|
t_rxtcur dd ?
|
|
|
|
t_dupacks dd ?
|
|
|
|
t_maxseg dd ?
|
|
|
|
t_force dd ?
|
|
|
|
t_flags dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;---------------
|
|
|
|
; RFC783 page 21
|
|
|
|
|
|
|
|
; send sequence
|
2012-02-25 13:03:22 +01:00
|
|
|
SND_UNA dd ? ; sequence number of unack'ed sent Packets
|
|
|
|
SND_NXT dd ? ; next send sequence number to use
|
2012-07-26 16:54:57 +02:00
|
|
|
SND_UP dd ? ; urgent pointer
|
2012-02-25 13:03:22 +01:00
|
|
|
SND_WL1 dd ? ; window minus one
|
|
|
|
SND_WL2 dd ? ;
|
|
|
|
ISS dd ? ; initial send sequence number
|
|
|
|
SND_WND dd ? ; send window
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
; receive sequence
|
2012-08-30 09:02:10 +02:00
|
|
|
RCV_WND dd ? ; receive window
|
2012-02-25 13:03:22 +01:00
|
|
|
RCV_NXT dd ? ; next receive sequence number to use
|
2012-07-26 16:54:57 +02:00
|
|
|
RCV_UP dd ? ; urgent pointer
|
2012-02-25 13:03:22 +01:00
|
|
|
IRS dd ? ; initial receive sequence number
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;---------------------
|
|
|
|
; Additional variables
|
|
|
|
|
|
|
|
; receive variables
|
2012-02-25 13:03:22 +01:00
|
|
|
RCV_ADV dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
; retransmit variables
|
2012-02-25 13:03:22 +01:00
|
|
|
SND_MAX dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
; congestion control
|
2012-02-25 13:03:22 +01:00
|
|
|
SND_CWND dd ?
|
|
|
|
SND_SSTHRESH dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;----------------------
|
|
|
|
; Transmit timing stuff
|
2012-02-25 13:03:22 +01:00
|
|
|
t_idle dd ?
|
|
|
|
t_rtt dd ?
|
|
|
|
t_rtseq dd ?
|
|
|
|
t_srtt dd ?
|
|
|
|
t_rttvar dd ?
|
|
|
|
t_rttmin dd ?
|
|
|
|
max_sndwnd dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;-----------------
|
|
|
|
; Out-of-band data
|
2012-02-25 13:03:22 +01:00
|
|
|
t_oobflags dd ?
|
|
|
|
t_iobc dd ?
|
|
|
|
t_softerror dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
;---------
|
2012-08-15 18:15:57 +02:00
|
|
|
; RFC 1323 ; the order of next 4 elements may not change
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
SND_SCALE db ?
|
|
|
|
RCV_SCALE db ?
|
|
|
|
requested_s_scale db ?
|
|
|
|
request_r_scale db ?
|
2011-11-12 21:05:07 +01:00
|
|
|
|
2012-08-15 18:15:57 +02:00
|
|
|
ts_recent dd ? ; a copy of the most-recent valid timestamp from the other end
|
2012-02-25 13:03:22 +01:00
|
|
|
ts_recent_age dd ?
|
|
|
|
last_ack_sent dd ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2010-07-15 20:54:19 +02:00
|
|
|
|
|
|
|
;-------
|
|
|
|
; Timers
|
2012-08-28 22:48:45 +02:00
|
|
|
timer_retransmission dd ? ; rexmt
|
|
|
|
timer_persist dd ?
|
|
|
|
timer_keepalive dd ? ; keepalive/syn timeout
|
|
|
|
timer_timed_wait dd ? ; also used as 2msl timer
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-26 16:54:57 +02:00
|
|
|
; extra
|
|
|
|
|
2012-08-15 18:15:57 +02:00
|
|
|
ts_ecr dd ? ; timestamp echo reply
|
2012-08-27 15:55:15 +02:00
|
|
|
ts_val dd ?
|
|
|
|
temp_bits db ?
|
2012-07-26 16:54:57 +02:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct UDP_SOCKET IP_SOCKET
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
LocalPort dw ?
|
|
|
|
RemotePort dw ?
|
|
|
|
firstpacket db ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct ICMP_SOCKET IP_SOCKET
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
Identifier dw ?
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct RING_BUFFER
|
2011-11-12 23:35:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
start_ptr dd ? ; Pointer to start of buffer
|
|
|
|
end_ptr dd ? ; pointer to end of buffer
|
|
|
|
read_ptr dd ? ; Read pointer
|
|
|
|
write_ptr dd ? ; Write pointer
|
|
|
|
size dd ? ; Number of bytes buffered
|
2011-11-12 23:35:01 +01:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct STREAM_SOCKET TCP_SOCKET
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
rcv RING_BUFFER
|
|
|
|
snd RING_BUFFER
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2011-11-09 00:06:26 +01:00
|
|
|
ends
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
struct socket_queue_entry
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
data_ptr dd ?
|
|
|
|
buf_ptr dd ?
|
|
|
|
data_size dd ?
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2009-11-15 22:44:17 +01:00
|
|
|
ends
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-04-14 23:15:00 +02:00
|
|
|
SOCKETBUFFSIZE = 4096 ; in bytes
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-04-14 23:15:00 +02:00
|
|
|
SOCKET_QUEUE_SIZE = 10 ; maximum number ofincoming packets queued for 1 socket
|
2010-07-12 01:13:12 +02:00
|
|
|
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
|
2012-04-14 23:15:00 +02:00
|
|
|
SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
uglobal
|
2012-02-25 13:03:22 +01:00
|
|
|
net_sockets rd 4
|
|
|
|
last_socket_num dd ?
|
|
|
|
last_UDP_port dw ? ; These values give the number of the last used ephemeral port
|
|
|
|
last_TCP_port dw ? ;
|
2009-09-17 13:55:38 +02:00
|
|
|
endg
|
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_init
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2012-02-25 13:03:22 +01:00
|
|
|
macro SOCKET_init {
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
xor eax, eax
|
|
|
|
mov edi, net_sockets
|
|
|
|
mov ecx, 5
|
|
|
|
rep stosd
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
@@:
|
2012-02-25 13:03:22 +01:00
|
|
|
pseudo_random eax
|
|
|
|
cmp ax, MIN_EPHEMERAL_PORT
|
|
|
|
jb @r
|
|
|
|
cmp ax, MAX_EPHEMERAL_PORT
|
|
|
|
ja @r
|
|
|
|
mov [last_UDP_port], ax
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
@@:
|
2012-02-25 13:03:22 +01:00
|
|
|
pseudo_random eax
|
|
|
|
cmp ax, MIN_EPHEMERAL_PORT
|
|
|
|
jb @r
|
|
|
|
cmp ax, MAX_EPHEMERAL_PORT
|
|
|
|
ja @r
|
|
|
|
mov [last_TCP_port], ax
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
}
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_block
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
macro SOCKET_block socket, loop, done {
|
|
|
|
|
|
|
|
test [socket + SOCKET.options], SO_BLOCK ; Is this a blocking socket?
|
|
|
|
jz done ; No, return immediately
|
|
|
|
|
|
|
|
push esi
|
|
|
|
mov esi, 5 ; yes, wait for event
|
|
|
|
call delay_ms
|
|
|
|
pop esi
|
|
|
|
|
|
|
|
jmp loop
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; Socket API (function 74)
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2012-04-14 23:15:00 +02:00
|
|
|
align 4
|
|
|
|
sys_socket:
|
|
|
|
|
|
|
|
cmp ebx, 255
|
|
|
|
jz SOCKET_debug
|
|
|
|
|
|
|
|
cmp ebx, .number
|
|
|
|
ja s_error
|
|
|
|
jmp dword [.table + 4*ebx]
|
|
|
|
|
|
|
|
.table:
|
2012-02-25 13:03:22 +01:00
|
|
|
dd SOCKET_open ; 0
|
|
|
|
dd SOCKET_close ; 1
|
|
|
|
dd SOCKET_bind ; 2
|
|
|
|
dd SOCKET_listen ; 3
|
|
|
|
dd SOCKET_connect ; 4
|
|
|
|
dd SOCKET_accept ; 5
|
|
|
|
dd SOCKET_send ; 6
|
|
|
|
dd SOCKET_receive ; 7
|
|
|
|
dd SOCKET_set_opt ; 8
|
|
|
|
dd SOCKET_get_opt ; 9
|
2012-04-14 23:15:00 +02:00
|
|
|
.number = ($ - .table) / 4 - 1
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
s_error:
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"socket error\n"
|
|
|
|
mov dword [esp+32], -1
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2011-11-07 22:03:20 +01:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_open
|
|
|
|
;
|
|
|
|
; IN: domain in ecx
|
|
|
|
; type in edx
|
2009-10-05 22:47:27 +02:00
|
|
|
; protocol in esi
|
2009-09-17 13:55:38 +02:00
|
|
|
; OUT: eax is socket num, -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_open:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_open: domain=%u type=%u protocol=%x\n", ecx, edx, esi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ecx edx esi
|
|
|
|
call SOCKET_alloc
|
|
|
|
pop esi edx ecx
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [esp+32], edi ; return socketnumber
|
2010-07-31 13:17:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.Domain], ecx
|
|
|
|
mov [eax + SOCKET.Type], edx
|
|
|
|
mov [eax + SOCKET.Protocol], esi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp ecx, AF_INET4
|
|
|
|
jne .no_inet4
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp edx, SOCK_DGRAM
|
|
|
|
je .udp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp edx, SOCK_STREAM
|
|
|
|
je .tcp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp edx, SOCK_RAW
|
|
|
|
je .raw
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
.no_inet4:
|
2012-08-19 21:09:09 +02:00
|
|
|
cmp ecx, AF_PPP
|
|
|
|
jne .no_ppp
|
|
|
|
|
|
|
|
cmp esi, PPP_PROTO_ETHERNET
|
|
|
|
je .pppoe
|
|
|
|
|
|
|
|
.no_ppp:
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
|
|
|
.raw:
|
2012-02-25 13:03:22 +01:00
|
|
|
test esi, esi ; IP_PROTO_IP
|
|
|
|
jz .ip
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, IP_PROTO_ICMP
|
|
|
|
je .icmp
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, IP_PROTO_UDP
|
|
|
|
je .udp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, IP_PROTO_TCP
|
|
|
|
je .tcp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
2010-07-30 11:09:06 +02:00
|
|
|
.udp:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
|
|
mov [eax + SOCKET.snd_proc], SOCKET_send_udp
|
|
|
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
|
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
|
|
|
.tcp:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
mov [eax + SOCKET.snd_proc], SOCKET_send_tcp
|
|
|
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp
|
2011-02-03 22:35:16 +01:00
|
|
|
|
2012-04-14 20:20:01 +02:00
|
|
|
TCP_init_socket eax
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
align 4
|
|
|
|
.ip:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.snd_proc], SOCKET_send_ip
|
|
|
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
|
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
|
|
|
|
align 4
|
2010-07-30 23:54:27 +02:00
|
|
|
.icmp:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.snd_proc], SOCKET_send_icmp
|
|
|
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-08-19 21:09:09 +02:00
|
|
|
align 4
|
|
|
|
.pppoe:
|
|
|
|
push eax
|
|
|
|
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
mov [eax + SOCKET.snd_proc], SOCKET_send_pppoe
|
|
|
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_bind
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
|
|
|
; pointer to sockaddr struct in edx
|
|
|
|
; length of that struct in esi
|
|
|
|
; OUT: 0 on success
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_bind:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, 2
|
|
|
|
jb s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp word [edx], AF_INET4
|
|
|
|
je .af_inet4
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp word [edx], AF_UNIX
|
|
|
|
je .af_unix
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp s_error
|
2009-11-06 21:45:08 +01:00
|
|
|
|
|
|
|
.af_unix:
|
2012-02-25 13:03:22 +01:00
|
|
|
; TODO: write code here
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.af_inet4:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, 6
|
|
|
|
jb s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-04-17 21:00:13 +02:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
|
|
je .udp
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-04-17 21:00:13 +02:00
|
|
|
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
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_bind: local ip=%u.%u.%u.%u\n",\
|
2012-02-25 13:03:22 +01:00
|
|
|
[eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\
|
|
|
|
[eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_connect
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
|
|
|
; pointer to sockaddr struct in edx
|
|
|
|
; length of that struct in esi
|
|
|
|
; OUT: 0 on success
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_connect:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp esi, 8
|
|
|
|
jb s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp word [edx], AF_INET4
|
|
|
|
je .af_inet4
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.af_inet4:
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + IP_SOCKET.LocalIP], 0
|
|
|
|
jne @f
|
|
|
|
push [IP_LIST]
|
|
|
|
pop [eax + IP_SOCKET.LocalIP]
|
2010-07-31 21:44:17 +02:00
|
|
|
@@:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
|
|
je .udp
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
je .tcp
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_IP
|
|
|
|
je .ip
|
2010-07-31 13:17:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
|
|
|
|
je .ip
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
2009-11-08 19:00:01 +01:00
|
|
|
.udp:
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pushw [edx + 2]
|
|
|
|
pop [eax + UDP_SOCKET.RemotePort]
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pushd [edx + 4]
|
|
|
|
pop [eax + IP_SOCKET.RemoteIP]
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + UDP_SOCKET.LocalPort], 0
|
|
|
|
jne @f
|
|
|
|
call SOCKET_find_port
|
2010-07-31 21:44:17 +02:00
|
|
|
@@:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + UDP_SOCKET.firstpacket], 0
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue
|
|
|
|
pop eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_unlock
|
|
|
|
|
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
2009-11-08 19:00:01 +01:00
|
|
|
.tcp:
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pushw [edx + 2]
|
|
|
|
pop [eax + TCP_SOCKET.RemotePort]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pushd [edx + 4]
|
|
|
|
pop [eax + IP_SOCKET.RemoteIP]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + TCP_SOCKET.LocalPort], 0
|
|
|
|
jne @f
|
|
|
|
call SOCKET_find_port
|
2010-07-31 21:44:17 +02:00
|
|
|
@@:
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + TCP_SOCKET.timer_persist], 0
|
|
|
|
mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
|
2012-04-14 20:20:01 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push [TCP_sequence_num]
|
|
|
|
add [TCP_sequence_num], 6400
|
|
|
|
pop [eax + TCP_SOCKET.ISS]
|
|
|
|
mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-04-14 20:20:01 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
TCP_sendseqinit eax
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
; mov [ebx + TCP_SOCKET.timer_retransmission], ;; todo: create macro to set retransmission timer
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, eax
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
lea eax, [ebx + STREAM_SOCKET.snd]
|
|
|
|
call SOCKET_ring_create
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
lea eax, [ebx + STREAM_SOCKET.rcv]
|
|
|
|
call SOCKET_ring_create
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
2012-08-27 20:59:34 +02:00
|
|
|
lea ecx, [ebx + SOCKET.mutex]
|
2012-02-25 13:03:22 +01:00
|
|
|
call mutex_unlock
|
|
|
|
popa
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, ebx
|
|
|
|
call TCP_output
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
;;; TODO: wait for successfull connection if blocking socket
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
|
|
|
.ip:
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
|
|
|
|
|
|
|
pushd [edx + 4]
|
|
|
|
pop [eax + IP_SOCKET.RemoteIP]
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue
|
|
|
|
pop eax
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_unlock
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_listen
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
|
|
|
; backlog in edx
|
|
|
|
; OUT: eax is socket num, -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_listen:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Domain], AF_INET4
|
|
|
|
jne s_error
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
jne s_error
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + TCP_SOCKET.LocalPort], 0
|
|
|
|
je s_error
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + IP_SOCKET.LocalIP], 0
|
|
|
|
jne @f
|
|
|
|
push [IP_LIST]
|
|
|
|
pop [eax + IP_SOCKET.LocalIP]
|
2010-07-31 21:44:17 +02:00
|
|
|
@@:
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp edx, MAX_backlog
|
|
|
|
jbe @f
|
|
|
|
mov edx, MAX_backlog
|
2010-07-31 21:44:17 +02:00
|
|
|
@@:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.backlog], dx
|
|
|
|
or [eax + SOCKET.options], SO_ACCEPTCON
|
|
|
|
mov [eax + TCP_SOCKET.t_state], TCPS_LISTEN
|
2012-07-18 00:53:05 +02:00
|
|
|
mov [eax + TCP_SOCKET.timer_keepalive], 0 ; disable keepalive timer
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up sockets queue
|
|
|
|
pop eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_accept
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
|
|
|
; addr in edx
|
|
|
|
; addrlen in esi
|
|
|
|
; OUT: eax is socket num, -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_accept:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
test [eax + SOCKET.options], SO_ACCEPTCON
|
|
|
|
jz s_error
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Domain], AF_INET4
|
|
|
|
jne s_error
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
jne s_error
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
.loop:
|
|
|
|
get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
|
|
|
|
|
|
|
|
; Ok, we got a socket ptr
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [esi]
|
2012-04-05 15:52:26 +02:00
|
|
|
|
|
|
|
; Change PID to that of the current process
|
|
|
|
mov ebx, [TASK_BASE]
|
|
|
|
mov ebx, [ebx + TASKDATA.pid]
|
|
|
|
mov [eax + SOCKET.PID], ebx
|
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
; Convert it to a socket number
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_ptr_to_num
|
|
|
|
jz s_error
|
2012-10-30 20:46:04 +01:00
|
|
|
; and return it to caller
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [esp+32], eax
|
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
.block:
|
|
|
|
SOCKET_block eax, .loop, s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_close
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
|
|
|
; OUT: eax is socket num, -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_close:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_close: %u\n", ecx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Domain], AF_INET4
|
|
|
|
jne s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
|
|
je .free
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
|
|
|
|
je .free
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_IP
|
|
|
|
je .free
|
2010-07-31 13:17:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
je .tcp
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.tcp:
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED
|
|
|
|
jb .free
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-26 16:54:57 +02:00
|
|
|
call TCP_usrclosed
|
2012-07-27 01:21:35 +02:00
|
|
|
call TCP_output ;;;; Fixme: is this nescessary??
|
2012-10-30 20:46:04 +01:00
|
|
|
|
|
|
|
;;; TODO: wait for successfull termination if blocking socket
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.free:
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_free
|
|
|
|
mov dword [esp+32], 0
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_receive
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
2009-11-06 21:45:08 +01:00
|
|
|
; addr to buffer in edx
|
|
|
|
; length of buffer in esi
|
2009-09-17 13:55:38 +02:00
|
|
|
; flags in edi
|
|
|
|
; OUT: eax is number of bytes copied, -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_receive:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp [eax + SOCKET.rcv_proc]
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
align 4
|
2010-07-30 23:54:27 +02:00
|
|
|
SOCKET_receive_dgram:
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_receive: DGRAM\n"
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, esi
|
|
|
|
mov edi, edx ; addr to buffer
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
.loop:
|
|
|
|
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block ; destroys esi and ecx
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ecx, [esi + socket_queue_entry.data_size]
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_receive: %u bytes data\n", ecx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp ecx, ebx
|
|
|
|
ja .too_small
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later
|
|
|
|
mov esi, [esi + socket_queue_entry.data_ptr]
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_receive: Source buffer=%x real addr=%x\n", [esp], esi
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [esp+32+4], ecx ; return number of bytes copied
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; copy the data
|
2012-02-25 13:03:22 +01:00
|
|
|
shr ecx, 1
|
|
|
|
jnc .nb
|
|
|
|
movsb
|
2010-07-30 11:09:06 +02:00
|
|
|
.nb:
|
2012-02-25 13:03:22 +01:00
|
|
|
shr ecx, 1
|
|
|
|
jnc .nw
|
|
|
|
movsw
|
2010-07-30 11:09:06 +02:00
|
|
|
.nw:
|
2012-02-25 13:03:22 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jz .nd
|
|
|
|
rep movsd
|
2010-07-30 11:09:06 +02:00
|
|
|
.nd:
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call kernel_free ; remove the packet
|
|
|
|
ret
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
.too_small:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_receive: Buffer too small\n"
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp s_error
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
.block:
|
|
|
|
SOCKET_block eax, .loop, s_error
|
|
|
|
|
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_receive_tcp:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_receive: TCP\n"
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ecx, esi
|
|
|
|
mov edi, edx
|
2012-07-28 00:14:12 +02:00
|
|
|
xor edx, edx
|
2012-10-30 20:46:04 +01:00
|
|
|
add eax, STREAM_SOCKET.rcv
|
|
|
|
.loop: ;;;; FIXME: ecx!
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_ring_read
|
2012-10-30 20:46:04 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jz .block
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_ring_free
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [esp+32], ecx ; return number of bytes copied
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-10-30 20:46:04 +01:00
|
|
|
.block:
|
|
|
|
SOCKET_block (eax - STREAM_SOCKET.rcv), .loop, s_error
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; SOCKET_send
|
|
|
|
;
|
|
|
|
;
|
|
|
|
; IN: socket number in ecx
|
2009-10-12 16:39:59 +02:00
|
|
|
; pointer to data in edx
|
|
|
|
; datalength in esi
|
2009-09-17 13:55:38 +02:00
|
|
|
; flags in edi
|
|
|
|
; OUT: -1 on error
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_send:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ecx, esi
|
|
|
|
mov esi, edx
|
2011-01-24 23:01:54 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp [eax + SOCKET.snd_proc]
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_send_udp:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_send: UDP\n"
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
mov [esp+32], ecx
|
2012-02-25 13:03:22 +01:00
|
|
|
call UDP_output
|
2012-04-05 18:23:47 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je s_error
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_send_tcp:
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_send: TCP\n"
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
add eax, STREAM_SOCKET.snd
|
|
|
|
call SOCKET_ring_write
|
|
|
|
pop eax
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-04-17 20:41:58 +02:00
|
|
|
mov [esp+32], ecx
|
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
call TCP_output
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_send_ip:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_send: IPv4\n"
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
mov [esp+32], ecx
|
2012-02-25 13:03:22 +01:00
|
|
|
call IPv4_output_raw
|
2012-04-05 18:23:47 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je s_error
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
|
2010-07-30 23:54:27 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_send_icmp:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_send: ICMP\n"
|
2010-07-30 23:54:27 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
mov [esp+32], ecx
|
2012-02-25 13:03:22 +01:00
|
|
|
call ICMP_output_raw
|
2012-04-05 18:23:47 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je s_error
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-30 23:54:27 +02:00
|
|
|
|
|
|
|
|
2012-08-19 21:09:09 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_send_pppoe:
|
|
|
|
|
|
|
|
DEBUGF 1,"SOCKET_send: PPPoE\n"
|
|
|
|
|
|
|
|
mov [esp+32], ecx
|
|
|
|
mov ebx, [eax + SOCKET.device]
|
|
|
|
|
|
|
|
call PPPoE_discovery_output
|
|
|
|
cmp eax, -1
|
|
|
|
je s_error
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-11-09 12:34:51 +01:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
; SOCKET_get_options
|
2009-11-09 12:34:51 +01:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: ecx = socket number
|
|
|
|
; edx = pointer to the options:
|
2009-11-09 14:59:46 +01:00
|
|
|
; dd level, optname, optval, optlen
|
2009-11-09 12:34:51 +01:00
|
|
|
; OUT: -1 on error
|
|
|
|
;
|
|
|
|
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
|
|
|
|
; TODO: find best way to notify that send()'ed data were acknowledged
|
2011-02-01 18:00:04 +01:00
|
|
|
; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*.
|
2009-11-09 12:34:51 +01:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_get_opt:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_get_opt\n"
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2009-11-09 14:59:46 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp dword [edx], IP_PROTO_TCP
|
|
|
|
jne s_error
|
|
|
|
cmp dword [edx+4], -2
|
|
|
|
je @f
|
|
|
|
cmp dword [edx+4], -3
|
|
|
|
jne s_error
|
2009-11-30 12:19:59 +01:00
|
|
|
@@:
|
2010-07-12 01:13:12 +02:00
|
|
|
; mov eax, [edx+12]
|
|
|
|
; test eax, eax
|
|
|
|
; jz .fail
|
|
|
|
; cmp dword [eax], 4
|
|
|
|
; mov dword [eax], 4
|
|
|
|
; jb .fail
|
|
|
|
; stdcall net_socket_num_to_addr, ecx
|
|
|
|
; test eax, eax
|
|
|
|
; jz .fail
|
|
|
|
; ; todo: check that eax is really TCP socket
|
|
|
|
; mov ecx, [eax + TCP_SOCKET.last_ack_number]
|
|
|
|
; cmp dword [edx+4], -2
|
|
|
|
; jz @f
|
|
|
|
; mov ecx, [eax + TCP_SOCKET.state]
|
2009-11-30 12:19:59 +01:00
|
|
|
@@:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [edx+8]
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
mov [eax], ecx
|
2009-11-09 12:34:51 +01:00
|
|
|
@@:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-06-03 21:28:01 +02:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_set_options
|
|
|
|
;
|
|
|
|
; IN: ecx = socket number
|
|
|
|
; edx = pointer to the options:
|
2012-07-17 23:36:34 +02:00
|
|
|
; dd level, optname, optlen, optval
|
2012-06-03 21:28:01 +02:00
|
|
|
; OUT: -1 on error
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
2010-07-31 13:17:06 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_set_opt:
|
|
|
|
|
2012-06-03 21:28:01 +02:00
|
|
|
DEBUGF 1,"SOCKET_set_opt\n"
|
|
|
|
|
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
|
|
|
|
2012-07-17 23:36:34 +02:00
|
|
|
cmp dword [edx], SOL_SOCKET
|
|
|
|
jne s_error
|
|
|
|
|
|
|
|
cmp dword [edx+4], SO_BINDTODEVICE
|
|
|
|
je .bind
|
|
|
|
|
|
|
|
jmp s_error
|
|
|
|
|
|
|
|
.bind:
|
|
|
|
cmp dword [edx+8], 0
|
|
|
|
je .unbind
|
|
|
|
|
|
|
|
movzx edx, byte [edx + 9]
|
|
|
|
cmp edx, MAX_NET_DEVICES
|
|
|
|
ja s_error
|
|
|
|
|
|
|
|
mov edx, [NET_DRV_LIST + 4*edx]
|
|
|
|
test edx, edx
|
|
|
|
jz s_error
|
|
|
|
mov [eax + SOCKET.device], edx
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx
|
2012-07-17 23:36:34 +02:00
|
|
|
|
|
|
|
mov dword [esp+32], 0 ; success!
|
|
|
|
ret
|
2012-06-03 21:28:01 +02:00
|
|
|
|
2012-07-17 23:36:34 +02:00
|
|
|
.unbind:
|
|
|
|
mov [eax + SOCKET.device], 0
|
2012-06-03 21:28:01 +02:00
|
|
|
|
2012-07-17 23:36:34 +02:00
|
|
|
mov dword [esp+32], 0 ; success!
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-31 13:17:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_debug
|
|
|
|
;
|
|
|
|
; Copies socket variables to application buffer
|
|
|
|
;
|
|
|
|
; IN: ecx = socket number
|
|
|
|
; edx = pointer to buffer
|
|
|
|
;
|
|
|
|
; OUT: -1 on error
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_debug:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_debug\n"
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_num_to_ptr
|
|
|
|
jz s_error
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov esi, eax
|
|
|
|
mov edi, edx
|
|
|
|
mov ecx, SOCKETBUFFSIZE/4
|
|
|
|
rep movsd
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov dword [esp+32], 0
|
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; SOCKET_find_port
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; Fills in the local port number for TCP and UDP sockets
|
|
|
|
; This procedure always works because the number of sockets is
|
|
|
|
; limited to a smaller number then the number of possible ports
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: eax = socket pointer
|
|
|
|
; OUT: /
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_find_port:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_find_port\n"
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx esi ecx
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
|
|
je .udp
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
je .tcp
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp .error
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.done:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + UDP_SOCKET.LocalPort], bx
|
2010-07-12 01:13:12 +02:00
|
|
|
.error:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop ecx esi ebx
|
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
.udp:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov bx, [last_UDP_port]
|
|
|
|
call .findit
|
|
|
|
mov [last_UDP_port], bx
|
|
|
|
jmp .done
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
.tcp:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov bx, [last_TCP_port]
|
|
|
|
call .findit
|
|
|
|
mov [last_TCP_port], bx
|
|
|
|
jmp .done
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.restart:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov bx, MIN_EPHEMERAL_PORT
|
2010-07-12 01:13:12 +02:00
|
|
|
.findit:
|
2012-02-25 13:03:22 +01:00
|
|
|
inc bx
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp bx, MAX_EPHEMERAL_PORT
|
|
|
|
jz .restart
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_check_port
|
|
|
|
jz .findit
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-31 13:17:06 +02:00
|
|
|
; SOCKET_check_port (to be used with AF_INET only!)
|
2010-07-12 01:13:12 +02:00
|
|
|
;
|
|
|
|
; Checks if a local port number is unused
|
|
|
|
; If the proposed port number is unused, it is filled in in the socket structure
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: eax = socket ptr (to find out if its a TCP/UDP socket)
|
|
|
|
; bx = proposed socket number
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; OUT: ZF = cleared on error
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_check_port:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_check_port: "
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ecx, [eax + SOCKET.Protocol]
|
2012-04-17 21:00:13 +02:00
|
|
|
mov edx, [eax + IP_SOCKET.LocalIP]
|
2012-02-25 13:03:22 +01:00
|
|
|
mov esi, net_sockets
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
.next_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov esi, [esi + SOCKET.NextPtr]
|
|
|
|
or esi, esi
|
|
|
|
jz .port_ok
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [esi + SOCKET.Protocol], ecx
|
|
|
|
jne .next_socket
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-04-17 21:00:13 +02:00
|
|
|
cmp [esi + IP_SOCKET.LocalIP], edx
|
|
|
|
jne .next_socket
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [esi + UDP_SOCKET.LocalPort], bx
|
|
|
|
jne .next_socket
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"local port %u already in use\n", bx
|
|
|
|
ret
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
.port_ok:
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"local port %u is free\n", bx
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + UDP_SOCKET.LocalPort], bx
|
|
|
|
or bx, bx ; set the zero-flag
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; SOCKET_input
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-30 11:09:06 +02:00
|
|
|
; Updates a (stateless) socket with received data
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; Note: the mutex should already be set !
|
2009-11-06 21:45:08 +01:00
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
2010-07-12 01:13:12 +02:00
|
|
|
; ecx = data size
|
|
|
|
; esi = ptr to data
|
|
|
|
; [esp] = ptr to buf
|
|
|
|
; [esp + 4] = buf size
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; OUT: /
|
2009-10-12 16:39:59 +02:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-10-12 16:39:59 +02:00
|
|
|
align 4
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_input:
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
|
|
|
|
|
|
|
|
mov [esp+4], ecx
|
|
|
|
push esi
|
|
|
|
mov esi, esp
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_input: queued packet successfully\n"
|
|
|
|
add esp, sizeof.socket_queue_entry
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
|
|
|
jmp SOCKET_notify_owner
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.full:
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 2,"SOCKET_input: socket %x is full!\n", eax
|
|
|
|
|
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
|
|
|
call kernel_free
|
|
|
|
add esp, 8
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2010-07-29 01:59:42 +02:00
|
|
|
|
|
|
|
;--------------------------
|
|
|
|
;
|
|
|
|
; eax = ptr to ring struct (just a buffer of the right size)
|
|
|
|
;
|
|
|
|
align 4
|
|
|
|
SOCKET_ring_create:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push esi
|
|
|
|
mov esi, eax
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push edx
|
|
|
|
stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
|
|
|
|
pop edx
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_ring_created: %x\n", eax
|
|
|
|
mov [esi + RING_BUFFER.start_ptr], eax
|
|
|
|
mov [esi + RING_BUFFER.write_ptr], eax
|
|
|
|
mov [esi + RING_BUFFER.read_ptr], eax
|
|
|
|
mov [esi + RING_BUFFER.size], 0
|
2012-07-24 22:29:46 +02:00
|
|
|
add eax, SOCKET_MAXDATA
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [esi + RING_BUFFER.end_ptr], eax
|
|
|
|
mov eax, esi
|
|
|
|
pop esi
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
2010-07-29 01:59:42 +02:00
|
|
|
; SOCKET_ring_write
|
2010-07-27 20:53:38 +02:00
|
|
|
;
|
2010-07-29 01:59:42 +02:00
|
|
|
; Adds data to a stream socket, and updates write pointer and size
|
2010-07-27 20:53:38 +02:00
|
|
|
;
|
|
|
|
; IN: eax = ptr to ring struct
|
|
|
|
; ecx = data size
|
|
|
|
; esi = ptr to data
|
|
|
|
;
|
2010-07-29 01:59:42 +02:00
|
|
|
; OUT: ecx = number of bytes stored
|
2010-07-27 20:53:38 +02:00
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
2010-07-29 01:59:42 +02:00
|
|
|
SOCKET_ring_write:
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
add [eax + RING_BUFFER.size], ecx
|
2012-04-05 18:23:47 +02:00
|
|
|
jc .way_too_large
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + RING_BUFFER.size], SOCKET_MAXDATA
|
|
|
|
ja .too_large
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
.copy:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov edi, [eax + RING_BUFFER.write_ptr]
|
|
|
|
DEBUGF 2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ecx
|
|
|
|
shr ecx, 1
|
|
|
|
jnc .nb
|
|
|
|
movsb
|
2010-07-30 11:09:06 +02:00
|
|
|
.nb:
|
2012-02-25 13:03:22 +01:00
|
|
|
shr ecx, 1
|
|
|
|
jnc .nw
|
|
|
|
movsw
|
2010-07-30 11:09:06 +02:00
|
|
|
.nw:
|
2012-02-25 13:03:22 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jz .nd
|
|
|
|
rep movsd
|
2010-07-30 11:09:06 +02:00
|
|
|
.nd:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop ecx
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp edi, [eax + RING_BUFFER.end_ptr]
|
|
|
|
jae .wrap
|
|
|
|
mov [eax + RING_BUFFER.write_ptr], edi
|
2010-07-29 01:59:42 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-29 01:59:42 +02:00
|
|
|
|
|
|
|
.wrap:
|
2012-02-25 13:03:22 +01:00
|
|
|
sub edi, SOCKET_MAXDATA
|
|
|
|
mov [eax + RING_BUFFER.write_ptr], edi
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 14:02:09 +01:00
|
|
|
.too_large: ; update size, we will fill buffer completely
|
|
|
|
sub [eax + RING_BUFFER.size], SOCKET_MAXDATA
|
2012-02-25 13:03:22 +01:00
|
|
|
sub ecx, [eax + RING_BUFFER.size]
|
2012-02-25 14:02:09 +01:00
|
|
|
mov [eax + RING_BUFFER.size], SOCKET_MAXDATA
|
2012-04-05 18:23:47 +02:00
|
|
|
ja .copy
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
.full:
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 2,"SOCKET_ring_write: ring buffer is full!\n"
|
|
|
|
xor ecx, ecx
|
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-04-05 18:23:47 +02:00
|
|
|
.way_too_large:
|
|
|
|
sub [eax + RING_BUFFER.size], ecx
|
|
|
|
mov ecx, SOCKET_MAXDATA
|
|
|
|
sub ecx, [eax + RING_BUFFER.size]
|
|
|
|
ja .copy
|
|
|
|
jmp .full
|
|
|
|
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_ring_read
|
|
|
|
;
|
2012-07-28 00:14:12 +02:00
|
|
|
; IN: eax = ring struct ptr
|
|
|
|
; ecx = bytes to read
|
|
|
|
; edx = offset
|
2012-10-30 20:46:04 +01:00
|
|
|
; edi = ptr to buffer start
|
2010-07-27 20:53:38 +02:00
|
|
|
;
|
2012-10-30 20:46:04 +01:00
|
|
|
; OUT: eax = unchanged
|
|
|
|
; ecx = number of bytes read (0 on error)
|
|
|
|
; edx = destroyed
|
|
|
|
; esi = destroyed
|
|
|
|
; edi = ptr to buffer end
|
2010-07-27 20:53:38 +02:00
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_ring_read:
|
|
|
|
|
2012-07-28 00:14:12 +02:00
|
|
|
DEBUGF 1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx
|
|
|
|
|
|
|
|
mov esi, [eax + RING_BUFFER.read_ptr]
|
|
|
|
add esi, edx ; esi = start_ptr + offset
|
|
|
|
|
|
|
|
neg edx
|
|
|
|
add edx, [eax + RING_BUFFER.size] ; edx = snd.size - offset
|
|
|
|
jle .no_data_at_all
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-07-28 00:14:12 +02:00
|
|
|
cmp ecx, edx
|
2012-02-25 13:03:22 +01:00
|
|
|
ja .less_data
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
.copy:
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi
|
|
|
|
push ecx
|
|
|
|
shr ecx, 1
|
|
|
|
jnc .nb
|
|
|
|
movsb
|
2010-07-30 11:09:06 +02:00
|
|
|
.nb:
|
2012-02-25 13:03:22 +01:00
|
|
|
shr ecx, 1
|
|
|
|
jnc .nw
|
|
|
|
movsw
|
2010-07-30 11:09:06 +02:00
|
|
|
.nw:
|
2012-02-25 13:03:22 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jz .nd
|
|
|
|
rep movsd
|
2010-07-30 11:09:06 +02:00
|
|
|
.nd:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop ecx
|
2012-07-28 00:14:12 +02:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2011-02-01 17:14:18 +01:00
|
|
|
.no_data_at_all:
|
2012-07-28 00:24:08 +02:00
|
|
|
DEBUGF 1,"SOCKET_ring_read: no data at all!\n"
|
2012-10-30 19:04:04 +01:00
|
|
|
xor ecx, ecx
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2010-07-29 01:59:42 +02:00
|
|
|
.less_data:
|
2012-07-28 00:14:12 +02:00
|
|
|
mov ecx, edx
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp .copy
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_ring_free
|
|
|
|
;
|
|
|
|
; Free's some bytes from the ringbuffer
|
|
|
|
;
|
|
|
|
; IN: eax = ptr to ring struct
|
|
|
|
; ecx = data size
|
|
|
|
;
|
|
|
|
; OUT: ecx = number of bytes free-ed
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_ring_free:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
sub [eax + RING_BUFFER.size], ecx
|
2012-07-24 22:29:46 +02:00
|
|
|
jb .error
|
2012-02-25 13:03:22 +01:00
|
|
|
add [eax + RING_BUFFER.read_ptr], ecx
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov edx, [eax + RING_BUFFER.end_ptr]
|
|
|
|
cmp [eax + RING_BUFFER.read_ptr], edx
|
|
|
|
jb @f
|
|
|
|
sub [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA
|
2010-07-27 20:53:38 +02:00
|
|
|
@@:
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-07-24 22:29:46 +02:00
|
|
|
.error: ; we could free all available bytes, but that would be stupid, i guess..
|
|
|
|
DEBUGF 1,"SOCKET_ring_free: buffer=%x error!\n", eax
|
2012-02-25 13:03:22 +01:00
|
|
|
add [eax + RING_BUFFER.size], ecx
|
|
|
|
xor ecx, ecx
|
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_notify_owner
|
|
|
|
;
|
|
|
|
; notify's the owner of a socket that something happened
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_notify_owner:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_notify_owner: %x\n", eax
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_check
|
|
|
|
jz .error
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax ecx esi
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; socket exists, now try to flag an event to the application
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [eax + SOCKET.PID]
|
2012-04-18 18:01:38 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .error2
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ecx, 1
|
|
|
|
mov esi, TASK_DATA + TASKDATA.pid
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
.next_pid:
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [esi], eax
|
|
|
|
je .found_pid
|
|
|
|
inc ecx
|
|
|
|
add esi, 0x20
|
|
|
|
cmp ecx, [TASK_COUNT]
|
|
|
|
jbe .next_pid
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
; PID not found, TODO: close socket!
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp .error2
|
2009-10-12 16:39:59 +02:00
|
|
|
|
|
|
|
.found_pid:
|
2012-02-25 13:03:22 +01:00
|
|
|
shl ecx, 8
|
|
|
|
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
|
|
|
|
mov [check_idle_semaphore], 200
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_notify_owner: succes!\n"
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.error2:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop esi ecx eax
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.error:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
;--------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_alloc
|
|
|
|
;
|
2009-09-17 13:55:38 +02:00
|
|
|
; Allocate memory for socket data and put new socket into the list
|
|
|
|
; Newly created socket is initialized with calling PID and number and
|
|
|
|
; put into beginning of list (which is a fastest way).
|
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: /
|
|
|
|
; OUT: eax = 0 on error, socket ptr otherwise
|
|
|
|
; edi = socket number
|
|
|
|
; ZF = cleared on error
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
;--------------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_alloc:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
stdcall kernel_alloc, SOCKETBUFFSIZE
|
|
|
|
DEBUGF 1, "SOCKET_alloc: ptr=%x\n", eax
|
|
|
|
or eax, eax
|
|
|
|
jz .exit
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; zero-initialize allocated memory
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
mov edi, eax
|
|
|
|
mov ecx, SOCKETBUFFSIZE / 4
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
pop eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-30 11:09:06 +02:00
|
|
|
; set send-and receive procedures to return -1
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [eax + SOCKET.snd_proc], s_error
|
|
|
|
mov [eax + SOCKET.rcv_proc], s_error
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; find first free socket number and use it
|
2012-02-25 13:03:22 +01:00
|
|
|
mov edi, [last_socket_num]
|
2009-09-17 13:55:38 +02:00
|
|
|
.next_socket_number:
|
2012-02-25 13:03:22 +01:00
|
|
|
inc edi
|
|
|
|
jz .next_socket_number ; avoid socket nr 0
|
|
|
|
cmp edi, -1
|
|
|
|
je .next_socket_number ; avoid socket nr -1
|
|
|
|
mov ebx, net_sockets
|
2009-09-17 13:55:38 +02:00
|
|
|
.next_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .last_socket
|
2010-07-30 11:09:06 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [ebx + SOCKET.Number], edi
|
|
|
|
jne .next_socket
|
|
|
|
jmp .next_socket_number
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.last_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [last_socket_num], edi
|
|
|
|
mov [eax + SOCKET.Number], edi
|
|
|
|
DEBUGF 1, "SOCKET_alloc: number=%u\n", edi
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
; Fill in PID
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, [TASK_BASE]
|
|
|
|
mov ebx, [ebx + TASKDATA.pid]
|
|
|
|
mov [eax + SOCKET.PID], ebx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:07:41 +01:00
|
|
|
; init mutex
|
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_init
|
|
|
|
popa
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
; add socket to the list by re-arranging some pointers
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, [net_sockets + SOCKET.NextPtr]
|
|
|
|
|
|
|
|
mov [eax + SOCKET.PrevPtr], net_sockets
|
|
|
|
mov [eax + SOCKET.NextPtr], ebx
|
|
|
|
|
|
|
|
test ebx, ebx
|
|
|
|
jz @f
|
|
|
|
|
|
|
|
pusha
|
|
|
|
lea ecx, [ebx + SOCKET.mutex]
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
|
|
|
|
|
|
|
mov [ebx + SOCKET.PrevPtr], eax
|
|
|
|
|
|
|
|
pusha
|
|
|
|
lea ecx, [ebx + SOCKET.mutex]
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
2010-07-12 01:13:12 +02:00
|
|
|
@@:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [net_sockets + SOCKET.NextPtr], eax
|
|
|
|
or eax, eax ; used to clear zero flag
|
2009-09-17 13:55:38 +02:00
|
|
|
.exit:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;----------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; SOCKET_free
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; Free socket data memory and remove socket from the list
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;----------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_free:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1, "SOCKET_free: %x\n", eax
|
|
|
|
|
|
|
|
call SOCKET_check
|
|
|
|
jz .error
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
pusha
|
|
|
|
lea ecx, [eax + SOCKET.mutex]
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Domain], AF_INET4
|
|
|
|
jnz .no_tcp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
jnz .no_tcp
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, eax
|
|
|
|
stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr]
|
|
|
|
stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr]
|
|
|
|
mov eax, ebx
|
2010-07-30 11:09:06 +02:00
|
|
|
.no_tcp:
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax ; this will be passed to kernel_free
|
|
|
|
mov ebx, [eax + SOCKET.NextPtr]
|
|
|
|
mov eax, [eax + SOCKET.PrevPtr]
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
mov [eax + SOCKET.NextPtr], ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
@@:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz @f
|
|
|
|
mov [ebx + SOCKET.PrevPtr], eax
|
2010-07-12 01:13:12 +02:00
|
|
|
@@:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call kernel_free
|
|
|
|
pop ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1, "SOCKET_free: success!\n"
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.error:
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
;------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_fork
|
|
|
|
;
|
|
|
|
; Create a child socket
|
|
|
|
;
|
2010-07-29 01:59:42 +02:00
|
|
|
; IN: socket nr in ebx
|
2010-07-31 21:44:17 +02:00
|
|
|
; OUT: child socket nr in eax
|
|
|
|
;
|
|
|
|
;-----------------------------------
|
2010-07-27 20:53:38 +02:00
|
|
|
align 4
|
|
|
|
SOCKET_fork:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_fork: %x\n", ebx
|
2010-07-31 21:44:17 +02:00
|
|
|
|
|
|
|
; Exit if backlog queue is full
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size]
|
|
|
|
cmp ax, [ebx + SOCKET.backlog]
|
|
|
|
jae .fail
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
; Allocate new socket
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
|
|
|
call SOCKET_alloc
|
|
|
|
pop ebx
|
|
|
|
jz .fail
|
2010-07-31 21:44:17 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push eax
|
|
|
|
mov esi, esp
|
|
|
|
add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2
|
|
|
|
pop eax
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
; Copy structure from current socket to new
|
|
|
|
; We start at PID to preserve the socket num, and the 2 pointers at beginning of socket
|
2012-02-25 13:03:22 +01:00
|
|
|
lea esi, [ebx + SOCKET.PID]
|
|
|
|
lea edi, [eax + SOCKET.PID]
|
|
|
|
mov ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4
|
|
|
|
rep movsd
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
and [eax + SOCKET.options], not SO_ACCEPTCON
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2010-07-31 21:44:17 +02:00
|
|
|
.fail2:
|
2012-02-25 13:03:22 +01:00
|
|
|
add esp, 4+4+4
|
2010-07-31 21:44:17 +02:00
|
|
|
.fail:
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_fork: failed\n"
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
;---------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_num_to_ptr
|
|
|
|
;
|
2009-09-17 13:55:38 +02:00
|
|
|
; Get socket structure address by its number
|
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: ecx = socket number
|
2010-07-29 01:59:42 +02:00
|
|
|
; OUT: eax = 0 on error, socket ptr otherwise
|
2010-07-12 01:13:12 +02:00
|
|
|
; ZF = set on error
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
;---------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_num_to_ptr:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_num_to_ptr: num=%u ", ecx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, net_sockets
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.next_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [eax + SOCKET.NextPtr]
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
cmp [eax + SOCKET.Number], ecx
|
|
|
|
jne .next_socket
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
test eax, eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"ptr=%x\n", eax
|
|
|
|
ret
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.error:
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"not found\n", eax
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;---------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; SOCKET_ptr_to_num
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; Get socket number by its address
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: eax = 0 on error, socket num otherwise
|
|
|
|
; ZF = set on error
|
|
|
|
;
|
|
|
|
;---------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_ptr_to_num:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_ptr_to_num: ptr=%x ", eax
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
call SOCKET_check
|
|
|
|
jz .error
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, [eax + SOCKET.Number]
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"num=%u\n", eax
|
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.error:
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"not found\n", eax
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_check
|
|
|
|
;
|
|
|
|
; checks if the given value is really a socket ptr
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: eax = 0 on error, unchanged otherwise
|
|
|
|
; ZF = set on error
|
|
|
|
;
|
|
|
|
;---------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_check:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_check: %x\n", eax
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
|
|
|
mov ebx, net_sockets
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.next_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
|
|
|
or ebx, ebx
|
|
|
|
jz .done
|
|
|
|
cmp ebx, eax
|
|
|
|
jnz .next_socket
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.done:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, ebx
|
|
|
|
test eax, eax
|
|
|
|
pop ebx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_check_owner
|
|
|
|
;
|
|
|
|
; checks if the caller application owns the socket
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: ZF = true/false
|
|
|
|
;
|
|
|
|
;---------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_check_owner:
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
DEBUGF 1,"SOCKET_check_owner: %x\n", eax
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
|
|
|
mov ebx, [TASK_BASE]
|
|
|
|
mov ebx, [ecx + TASKDATA.pid]
|
|
|
|
cmp [eax + SOCKET.PID], ebx
|
|
|
|
pop ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-24 15:16:02 +01:00
|
|
|
;------------------------------------------------------
|
2010-07-12 01:13:12 +02:00
|
|
|
;
|
|
|
|
; SOCKET_process_end
|
|
|
|
;
|
|
|
|
; Kernel calls this function when a certain process ends
|
|
|
|
; This function will check if the process had any open sockets
|
|
|
|
; And update them accordingly
|
|
|
|
;
|
2012-07-13 16:02:54 +02:00
|
|
|
; IN: edx = pid
|
2010-07-12 01:13:12 +02:00
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
SOCKET_process_end:
|
|
|
|
|
2012-07-13 16:02:54 +02:00
|
|
|
DEBUGF 1,"SOCKET_process_end: %x\n", edx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
push ebx
|
|
|
|
mov ebx, net_sockets
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.next_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
2010-07-12 01:13:12 +02:00
|
|
|
.test_socket:
|
2012-02-25 13:03:22 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .done
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-07-13 16:02:54 +02:00
|
|
|
cmp [ebx + SOCKET.PID], edx
|
2012-02-25 13:03:22 +01:00
|
|
|
jne .next_socket
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_process_end: killing socket %x\n", ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov [ebx + SOCKET.PID], 0
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
je .tcp
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-04-18 18:01:38 +02:00
|
|
|
; The socket is stateless, just kill it right away!
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
mov eax, ebx
|
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
|
|
|
call SOCKET_free
|
|
|
|
jmp .test_socket
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.tcp:
|
2012-04-18 18:01:38 +02:00
|
|
|
push [ebx + SOCKET.NextPtr]
|
|
|
|
mov eax, ebx
|
2012-07-13 18:24:41 +02:00
|
|
|
call TCP_disconnect
|
2012-04-18 18:01:38 +02:00
|
|
|
pop ebx
|
|
|
|
jmp .test_socket
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
.done:
|
2012-02-25 13:03:22 +01:00
|
|
|
pop ebx
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2011-01-28 17:49:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-24 15:16:02 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_is_connecting
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
|
|
|
SOCKET_is_connecting:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_is_connecting: %x\n", eax
|
2011-02-24 15:16:02 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
|
|
|
|
or [eax + SOCKET.options], SS_ISCONNECTING
|
2011-02-24 15:16:02 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp SOCKET_notify_owner
|
2011-02-24 15:16:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_is_connected
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
|
|
|
SOCKET_is_connected:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_is_connected: %x\n", eax
|
2011-02-24 15:16:02 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
|
|
|
|
or [eax + SOCKET.options], SS_ISCONNECTED
|
2011-02-24 15:16:02 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp SOCKET_notify_owner
|
2011-01-28 17:49:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_is_disconnecting
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
|
|
|
SOCKET_is_disconnecting:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_is_disconnecting: %x\n", eax
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
and [eax + SOCKET.options], not (SS_ISCONNECTING)
|
|
|
|
or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
|
2011-01-28 17:49:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp SOCKET_notify_owner
|
2011-01-28 17:49:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_is_disconnected
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
|
|
|
SOCKET_is_disconnected:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_is_disconnected: %x\n", eax
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
|
|
|
|
or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE
|
2011-01-28 17:49:08 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
jmp SOCKET_notify_owner
|
2011-01-29 00:07:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; SOCKET_cant_recv_more
|
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
|
|
|
SOCKET_cant_recv_more:
|
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_cant_recv_more: %x\n", eax
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
or [eax + SOCKET.options], SS_CANTRCVMORE
|
2011-02-24 15:16:02 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|
2011-02-01 18:00:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
2011-02-24 15:16:02 +01:00
|
|
|
; SOCKET_cant_send_more
|
2011-02-01 18:00:04 +01:00
|
|
|
;
|
|
|
|
; IN: eax = socket ptr
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
|
|
|
|
align 4
|
2011-02-24 15:16:02 +01:00
|
|
|
SOCKET_cant_send_more:
|
2011-02-01 18:00:04 +01:00
|
|
|
|
2012-07-27 01:21:35 +02:00
|
|
|
DEBUGF 1,"SOCKET_cant_send_more: %x\n", eax
|
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
or [eax + SOCKET.options], SS_CANTSENDMORE
|
2011-02-01 18:00:04 +01:00
|
|
|
|
2012-02-25 13:03:22 +01:00
|
|
|
ret
|