Rev 1255 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1255 | Rev 1256 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | ;; GNU GENERAL PUBLIC LICENSE ;; |
11 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; Version 2, June 1991 ;; |
12 | ;; Version 2, June 1991 ;; |
13 | ;; ;; |
13 | ;; ;; |
14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 15... | Line 15... | ||
15 | 15 | ||
Line 16... | Line 16... | ||
16 | $Revision: 1255 $ |
16 | $Revision: 1256 $ |
17 | 17 | ||
18 | struct SOCKET_head |
18 | struct SOCKET_head |
19 | .PrevPtr dd ? ; pointer to previous socket in list |
19 | .PrevPtr dd ? ; pointer to previous socket in list |
Line 41... | Line 41... | ||
41 | 41 | ||
42 | .LocalPort dw ? ; In INET byte order |
42 | .LocalPort dw ? ; In INET byte order |
Line 43... | Line 43... | ||
43 | .RemotePort dw ? ; In INET byte order |
43 | .RemotePort dw ? ; In INET byte order |
- | 44 | ||
- | 45 | .backlog dw ? ; Backlog |
|
- | 46 | .backlog_cur dw ? ; current size of queue for un-accept-ed connections |
|
- | 47 | .last_ack_number dd ? ; used only to let application know that ACK has been received |
|
- | 48 | ; todo: may be use SND_UNA instead |
|
44 | 49 | ; todo: may be use events which allow additional information instead |
|
45 | .backlog dw ? ; Backlog |
50 | ; todo: may be count acknowledged bytes (at least it has obvious sense) |
46 | ; .OrigRemoteIP dd ? ; original remote IP address (used to reset to LISTEN state) |
51 | ; .OrigRemoteIP dd ? ; original remote IP address (used to reset to LISTEN state) |
Line 47... | Line 52... | ||
47 | ; .OrigRemotePort dw ? ; original remote port (used to reset to LISTEN state) |
52 | ; .OrigRemotePort dw ? ; original remote port (used to reset to LISTEN state) |
Line 130... | Line 135... | ||
130 | ;----------------------------------------------- |
135 | ;----------------------------------------------- |
Line 131... | Line 136... | ||
131 | 136 | ||
132 | align 4 |
137 | align 4 |
133 | sys_socket: |
138 | sys_socket: |
134 | and ebx, 0x000000FF ; should i remove this line ? |
139 | and ebx, 0x000000FF ; should i remove this line ? |
135 | cmp bl , 7 ; highest possible number |
140 | cmp bl , 8 ; highest possible number |
136 | jg s_error |
141 | jg s_error |
137 | lea ebx, [.table + 4*ebx] |
142 | lea ebx, [.table + 4*ebx] |
Line 138... | Line 143... | ||
138 | jmp dword [ebx] |
143 | jmp dword [ebx] |
Line 144... | Line 149... | ||
144 | dd socket_listen ; 3 |
149 | dd socket_listen ; 3 |
145 | dd socket_connect ; 4 |
150 | dd socket_connect ; 4 |
146 | dd socket_accept ; 5 |
151 | dd socket_accept ; 5 |
147 | dd socket_send ; 6 |
152 | dd socket_send ; 6 |
148 | dd socket_recv ; 7 |
153 | dd socket_recv ; 7 |
149 | ; dd socket_get_opt ; 8 |
154 | dd socket_get_opt ; 8 |
150 | ; dd socket_set_opt ; 9 |
155 | ; dd socket_set_opt ; 9 |
Line 151... | Line 156... | ||
151 | 156 | ||
152 | 157 | ||
Line 396... | Line 401... | ||
396 | 401 | ||
397 | cmp [eax + SOCKET_head.Type], IP_PROTO_TCP |
402 | cmp [eax + SOCKET_head.Type], IP_PROTO_TCP |
Line 398... | Line 403... | ||
398 | jne s_error |
403 | jne s_error |
399 | 404 | ||
400 | cmp edx, MAX_backlog |
405 | cmp edx, MAX_backlog |
401 | jl .ok |
406 | jb .ok |
Line 402... | Line 407... | ||
402 | mov dx , 20 |
407 | mov dx , MAX_backlog |
403 | .ok: |
408 | .ok: |
Line 446... | Line 451... | ||
446 | 451 | ||
Line 447... | Line 452... | ||
447 | jmp s_error |
452 | jmp s_error |
Line 448... | Line -... | ||
448 | - | ||
449 | .tcp: |
- | |
450 | - | ||
451 | cmp [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog], 0 |
453 | |
452 | jz s_error |
- | |
453 | - | ||
454 | call net_socket_alloc |
454 | .tcp: |
455 | or eax, eax |
- | |
456 | jz s_error |
455 | |
457 | mov edi, eax |
- | |
458 | - | ||
459 | dec [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog] |
456 | lea ebx, [esi + SOCKET_head.lock] |
460 | - | ||
461 | mov ecx, (SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.end+3)/4 |
457 | call wait_mutex |
462 | push esi edi |
- | |
463 | rep movsd |
458 | movzx eax, [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog_cur] |
464 | pop edi esi |
- | |
465 | - | ||
466 | mov [edi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog], 0 |
- | |
467 | 459 | test eax, eax |
|
468 | ; TODO: fill in structure in ecx |
460 | jz .unlock_err |
469 | - | ||
470 | mov [esi + SOCKET_head.end + IPv4_SOCKET.RemoteIP], 0 |
461 | dec [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog_cur] |
471 | mov [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.RemotePort], 0 |
462 | mov eax, [eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.end + (eax-1)*4] |
472 | - | ||
473 | stdcall net_socket_addr_to_num, edi |
463 | mov [esi + SOCKET_head.lock], 0 |
- | 464 | stdcall net_socket_addr_to_num, eax |
|
- | 465 | mov [esp+32], eax |
|
474 | mov [esp+32], eax |
466 | ret |
Line 475... | Line 467... | ||
475 | 467 | .unlock_err: |
|
476 | ret |
468 | mov [esi + SOCKET_head.lock], 0 |
477 | 469 | jmp s_error |
|
Line 751... | Line 743... | ||
751 | ; call ICMP_create_packet |
743 | ; call ICMP_create_packet |
Line 752... | Line 744... | ||
752 | 744 | ||
753 | mov [esp+32], eax |
745 | mov [esp+32], eax |
Line -... | Line 746... | ||
- | 746 | ret |
|
- | 747 | ||
- | 748 | ;----------------------------------------------- |
|
- | 749 | ; |
|
- | 750 | ; SOCKET_send |
|
- | 751 | ; |
|
- | 752 | ; |
|
- | 753 | ; IN: socket number in ecx |
|
- | 754 | ; edx points to the options: |
|
- | 755 | ; dd level, optname, optval, optlen |
|
- | 756 | ; OUT: -1 on error |
|
- | 757 | ; |
|
- | 758 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
|
- | 759 | ; TODO: find best way to notify that send()'ed data were acknowledged |
|
- | 760 | ; |
|
- | 761 | ;----------------------------------------------- |
|
- | 762 | socket_get_opt: |
|
- | 763 | cmp dword [edx], IP_PROTO_TCP |
|
- | 764 | jnz .unknown |
|
- | 765 | cmp dword [edx+4], -2 |
|
- | 766 | jnz .unknown |
|
- | 767 | mov eax, [edx+12] |
|
- | 768 | test eax, eax |
|
- | 769 | jz .fail |
|
- | 770 | cmp dword [eax], 4 |
|
- | 771 | mov dword [eax], 4 |
|
- | 772 | jb .fail |
|
- | 773 | stdcall net_socket_num_to_addr, ecx |
|
- | 774 | test eax, eax |
|
- | 775 | jz .fail |
|
- | 776 | ; todo: check that eax is really TCP socket |
|
- | 777 | mov ecx, [eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.last_ack_number] |
|
- | 778 | mov eax, [edx+8] |
|
- | 779 | test eax, eax |
|
- | 780 | jz @f |
|
- | 781 | mov [eax], ecx |
|
- | 782 | @@: |
|
- | 783 | xor eax, eax |
|
- | 784 | ret |
|
- | 785 | .fail: |
|
- | 786 | .unknown: |
|
Line 754... | Line 787... | ||
754 | ret |
787 | or eax, -1 |
755 | 788 | ret |
|
756 | 789 | ||
Line 870... | Line 903... | ||
870 | 903 | ||
871 | push edi ; offset |
904 | push edi ; offset |
872 | push ecx ; size |
905 | push ecx ; size |
873 | push esi ; data_ptr |
906 | push esi ; data_ptr |
874 | mov esi, esp |
907 | mov esi, esp |
875 | add_to_queue (eax + 2048), SOCKET_QUEUE_SIZE, 3*4, .full |
908 | add_to_queue (eax + 2048), SOCKET_QUEUE_SIZE, 3*4, notify_network_event.full |
876 | DEBUGF 1,"Queued packet successfully\n" |
909 | DEBUGF 1,"Queued packet successfully\n" |
Line 877... | Line 910... | ||
877 | add esp, 4*3 |
910 | add esp, 4*3 |
Line -... | Line 911... | ||
- | 911 | ||
878 | 912 | mov [eax + SOCKET_head.lock], 0 |
|
879 | mov [eax + SOCKET_head.lock], 0 |
913 | |
880 | 914 | notify_network_event: |
|
881 | ; flag an event to the application |
915 | ; flag an event to the application |
Line 905... | Line 939... | ||
905 | add esp, 8 |
939 | add esp, 8 |
906 | ret |
940 | ret |
Line 907... | Line -... | ||
907 | - | ||
908 | 941 | ||
909 | 942 | ||
910 | 943 | ||
911 | ; Allocate memory for socket data and put new socket into the list |
944 | ; Allocate memory for socket data and put new socket into the list |
912 | ; Newly created socket is initialized with calling PID and number and |
945 | ; Newly created socket is initialized with calling PID and number and |