Subversion Repositories Kolibri OS

Rev

Rev 1185 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1185 Rev 1196
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  SOCKET.INC                                                     ;;
6
;;  SOCKET.INC                                                     ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;                                                                 ;;
8
;;                                                                 ;;
Line 22... Line 22...
22
	 .NextPtr		dd ? ; pointer to next socket in list
22
	 .NextPtr		dd ? ; pointer to next socket in list
23
	 .Number		dd ? ; socket number (unique within single process)
23
	 .Number		dd ? ; socket number (unique within single process)
24
	 .PID			dd ? ; application process id
24
	 .PID			dd ? ; application process id
25
	 .Domain		dd ? ; INET/UNIX/..
25
	 .Domain		dd ? ; INET/UNIX/..
26
	 .Type			dd ? ; RAW/UDP/TCP/...
26
	 .Type			dd ? ; RAW/UDP/TCP/...
-
 
27
	 .Protocol		dd ? ; ICMP/IPv4/ARP/
27
	 .LocalIP		dd ? ; local IP address
28
	 .LocalIP		dd ? ; local IP address
28
	 .RemoteIP		dd ? ; remote IP address
29
	 .RemoteIP		dd ? ; remote IP address
29
	 .LocalPort		dw ? ; local port
30
	 .LocalPort		dw ? ; local port
30
	 .RemotePort		dw ? ; remote port
31
	 .RemotePort		dw ? ; remote port
31
;         .OrigRemoteIP          dd ? ; original remote IP address (used to reset to LISTEN state)
32
	 .OrigRemoteIP		dd ? ; original remote IP address (used to reset to LISTEN state)
32
;         .OrigRemotePort        dw ? ; original remote port (used to reset to LISTEN state)
33
	 .OrigRemotePort	dw ? ; original remote port (used to reset to LISTEN state)
33
	 .rxDataCount		dd ? ; rx data count
34
	 .rxDataCount		dd ? ; rx data count
34
;         .TCBState              dd ? ; TCB state
35
	 .TCBState		dd ? ; TCB state
35
;         .TCBTimer              dd ? ; TCB timer (seconds)
36
	 .TCBTimer		dd ? ; TCB timer (seconds)
36
;         .ISS                   dd ? ; initial send sequence
37
	 .ISS			dd ? ; initial send sequence
37
;         .IRS                   dd ? ; initial receive sequence
38
	 .IRS			dd ? ; initial receive sequence
38
;         .SND_UNA               dd ? ; sequence number of unack'ed sent Packets
39
	 .SND_UNA		dd ? ; sequence number of unack'ed sent Packets
39
;         .SND_NXT               dd ? ; bext send sequence number to use
40
	 .SND_NXT		dd ? ; bext send sequence number to use
40
;         .SND_WND               dd ? ; send window
41
	 .SND_WND		dd ? ; send window
41
;         .RCV_NXT               dd ? ; next receive sequence number to use
42
	 .RCV_NXT		dd ? ; next receive sequence number to use
42
;         .RCV_WND               dd ? ; receive window
43
	 .RCV_WND		dd ? ; receive window
43
;         .SEG_LEN               dd ? ; segment length
44
	 .SEG_LEN		dd ? ; segment length
44
;         .SEG_WND               dd ? ; segment window
45
	 .SEG_WND		dd ? ; segment window
45
	 .wndsizeTimer		dd ? ; window size timer
46
	 .wndsizeTimer		dd ? ; window size timer
46
	 .lock			dd ? ; lock mutex
47
	 .lock			dd ? ; lock mutex
47
	 .backlog		dw ? ; Backlog
48
	 .backlog		dw ? ; Backlog
48
	 .rxData:		     ; receive data buffer here
49
	 .rxData:		     ; receive data buffer here
49
ends
50
ends
Line 123... Line 124...
123
; SOCKET_open
124
; SOCKET_open
124
;
125
;
125
;
126
;
126
;  IN:  domain in ecx
127
;  IN:  domain in ecx
127
;       type in edx
128
;       type in edx
128
;       set esi to zero, it is reserved for future use
129
;       protocol in esi
129
;  OUT: eax is socket num, -1 on error
130
;  OUT: eax is socket num, -1 on error
130
;
131
;
131
;-----------------------------------------------
132
;-----------------------------------------------
132
socket_open:
133
socket_open:
Line 137... Line 138...
137
	or	eax, eax
138
	or	eax, eax
138
	jz	s_error
139
	jz	s_error
Line 139... Line 140...
139
 
140
 
140
	mov	[eax + SOCKET.Domain], ecx
141
	mov	[eax + SOCKET.Domain], ecx
-
 
142
	mov	[eax + SOCKET.Type], edx
Line 141... Line 143...
141
	mov	[eax + SOCKET.Type], edx
143
	mov	[eax + SOCKET.Protocol], esi
142
 
144
 
Line 143... Line 145...
143
	stdcall net_socket_addr_to_num, eax
145
	stdcall net_socket_addr_to_num, eax
Line 152... Line 154...
152
 
154
 
153
;-----------------------------------------------
155
;-----------------------------------------------
154
;
156
;
155
; SOCKET_bind
157
; SOCKET_bind
156
;
-
 
157
;
158
;
158
;  IN:  socket number in ecx
159
;  IN:  socket number in ecx
159
;       pointer to sockaddr struct in edx
160
;       pointer to sockaddr struct in edx
160
;       length of that struct in esi
161
;       length of that struct in esi
161
;  OUT: 0 on success
162
;  OUT: 0 on success
Line 182... Line 183...
182
 
183
 
183
	cmp	esi, 6
184
	cmp	esi, 6
Line 184... Line 185...
184
	jl	s_error
185
	jl	s_error
-
 
186
 
185
 
187
	mov	bx, word [edx + 2]
186
	mov	bx, word [edx + 2]
188
	rol	bx,8			;;;
187
	DEBUGF	1,"local port: %u ",bx
189
	DEBUGF	1,"local port: %u ",bx
Line 188... Line 190...
188
	test	bx, bx
190
	test	bx, bx
Line 278... Line 280...
278
	jmp	s_error
280
	jmp	s_error
Line 279... Line 281...
279
 
281
 
Line 280... Line 282...
280
  .udp:
282
  .udp:
-
 
283
 
281
 
284
	mov	bx , word [edx + 2]
Line 282... Line 285...
282
	mov	bx , word [edx + 2]
285
	rol	bx, 8
Line 283... Line 286...
283
	mov	word [eax + SOCKET.RemotePort], bx
286
	mov	word [eax + SOCKET.RemotePort], bx
Line 733... Line 736...
733
	DEBUGF	1,"type: UDP\n"
736
	DEBUGF	1,"type: UDP\n"
Line 734... Line 737...
734
 
737
 
735
	mov	ecx, esi
738
	mov	ecx, esi
736
	mov	esi, edx
739
	mov	esi, edx
737
	mov	edx, dword [eax + SOCKET.LocalPort] ; load local port and remote port at once
-
 
738
 
740
	mov	edx, dword [eax + SOCKET.LocalPort] ; load local port and remote port at once
-
 
741
	DEBUGF	1,"local port: %u, remote port:%u\n",[eax + SOCKET.LocalPort]:2, [eax + SOCKET.RemotePort]:2
-
 
742
	bswap	edx	 ;;;
739
	DEBUGF	1,"local port: %u, remote port:%u\n",[eax + SOCKET.LocalPort]:2, [eax + SOCKET.RemotePort]:2
743
	rol	edx, 16  ;;;
740
	mov	ebx, [eax + SOCKET.LocalIP]
744
	mov	ebx, [eax + SOCKET.LocalIP]
Line 741... Line 745...
741
	mov	eax, [eax + SOCKET.RemoteIP]
745
	mov	eax, [eax + SOCKET.RemoteIP]
Line 742... Line 746...
742
 
746
 
743
	call	UDP_create_Packet
747
	call	UDP_create_packet
Line 744... Line 748...
744
 
748
 
Line 763... Line 767...
763
	shl	edi, 16
767
	shl	edi, 16
764
	mov	di , [esi + ICMP_Packet.SequenceNumber]
768
	mov	di , [esi + ICMP_Packet.SequenceNumber]
765
	add	esi, ICMP_Packet.Data
769
	add	esi, ICMP_Packet.Data
766
	mov	ebx, [eax + SOCKET.LocalIP]
770
	mov	ebx, [eax + SOCKET.LocalIP]
767
	mov	eax, [eax + SOCKET.RemoteIP]
771
	mov	eax, [eax + SOCKET.RemoteIP]
768
	call	ICMP_create_Packet
772
	call	ICMP_create_packet
Line 769... Line 773...
769
 
773
 
770
	mov	[esp+32], eax
774
	mov	[esp+32], eax
Line 771... Line 775...
771
	ret
775
	ret