Rev 2556 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2556 | Rev 2853 | ||
---|---|---|---|
- | 1 | format binary as "" |
|
- | 2 | ||
1 | use32 |
3 | use32 |
2 | ; standard header |
4 | ; standard header |
3 | db 'MENUET01' ; signature |
5 | db 'MENUET01' ; signature |
4 | dd 1 ; header version |
6 | dd 1 ; header version |
5 | dd start ; entry point |
7 | dd start ; entry point |
6 | dd i_end ; initialized size |
8 | dd i_end ; initialized size |
7 | dd mem ; required memory |
9 | dd mem ; required memory |
8 | dd mem ; stack pointer |
10 | dd mem ; stack pointer |
9 | dd 0 ; parameters |
11 | dd 0 ; parameters |
10 | dd 0 ; path |
12 | dd 0 ; path |
11 | 13 | ||
12 | 14 | ||
13 | BUFFERSIZE equ 1500 |
15 | BUFFERSIZE equ 1500 |
14 | ; useful includes |
16 | ; useful includes |
15 | include '../macros.inc' |
17 | include '../macros.inc' |
16 | purge mov,add,sub |
18 | purge mov,add,sub |
17 | include '../proc32.inc' |
19 | include '../proc32.inc' |
18 | include '../dll.inc' |
20 | include '../dll.inc' |
19 | 21 | ||
20 | include '../network.inc' |
22 | include '../network.inc' |
21 | 23 | ||
22 | ; entry point |
24 | ; entry point |
23 | start: |
25 | start: |
24 | ; load libraries |
26 | ; load libraries |
25 | stdcall dll.Load, @IMPORT |
27 | stdcall dll.Load, @IMPORT |
26 | test eax, eax |
28 | test eax, eax |
27 | jnz exit |
29 | jnz exit |
28 | 30 | ||
29 | ; initialize console |
31 | ; initialize console |
30 | push 1 |
32 | push 1 |
31 | call [con_start] |
33 | call [con_start] |
32 | push title |
34 | push title |
33 | push 25 |
35 | push 25 |
34 | push 80 |
36 | push 80 |
35 | push 25 |
37 | push 25 |
36 | push 80 |
38 | push 80 |
37 | call [con_init] |
39 | call [con_init] |
38 | 40 | ||
39 | mcall 40, 1 shl 7 ; we only want network events |
41 | mcall 40, 1 shl 7 ; we only want network events |
40 | 42 | ||
41 | push str1 |
43 | push str1 |
42 | call [con_write_asciiz] |
44 | call [con_write_asciiz] |
43 | 45 | ||
44 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
46 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
45 | cmp eax, -1 |
47 | cmp eax, -1 |
46 | je sock_err |
48 | je sock_err |
47 | 49 | ||
48 | mov [socketnum], eax |
50 | mov [socketnum], eax |
49 | 51 | ||
50 | ;; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes, |
52 | ;; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes, |
51 | ;; cmp eax, -1 |
53 | ;; cmp eax, -1 |
52 | ;; je opt_err |
54 | ;; je opt_err |
53 | 55 | ||
54 | mcall bind, [socketnum], sockaddr1, sockaddr1.length |
56 | mcall bind, [socketnum], sockaddr1, sockaddr1.length |
55 | cmp eax, -1 |
57 | cmp eax, -1 |
56 | je bind_err |
58 | je bind_err |
57 | 59 | ||
58 | mcall listen, [socketnum], 10 ; Backlog = 10 |
60 | mcall listen, [socketnum], 10 ; Backlog = 10 |
59 | cmp eax, -1 |
61 | cmp eax, -1 |
60 | je listen_err |
62 | je listen_err |
61 | 63 | ||
62 | push str2 |
64 | push str2 |
63 | call [con_write_asciiz] |
65 | call [con_write_asciiz] |
64 | 66 | ||
65 | mcall 10 |
67 | mcall 10 |
66 | 68 | ||
67 | mcall accept, [socketnum], sockaddr1, sockaddr1.length |
69 | mcall accept, [socketnum], sockaddr1, sockaddr1.length |
68 | cmp eax, -1 |
70 | cmp eax, -1 |
69 | je acpt_err |
71 | je acpt_err |
70 | 72 | ||
71 | mov [socketnum2], eax |
73 | mov [socketnum2], eax |
72 | 74 | ||
73 | ;; mcall close, [socketnum] |
75 | ;; mcall close, [socketnum] |
74 | 76 | ||
75 | mcall send, [socketnum2], hello, hello.length |
77 | mcall send, [socketnum2], hello, hello.length |
76 | 78 | ||
77 | .loop: |
79 | .loop: |
78 | mcall 10 |
80 | mcall 10 |
79 | 81 | ||
80 | mcall recv, [socketnum2], buffer, buffer.length |
82 | mcall recv, [socketnum2], buffer, buffer.length |
81 | cmp eax, -1 |
83 | cmp eax, -1 |
82 | je .loop |
84 | je .loop |
83 | 85 | ||
84 | mov byte [buffer + eax], 0 |
86 | mov byte [buffer + eax], 0 |
85 | 87 | ||
86 | push buffer |
88 | push buffer |
87 | call [con_write_asciiz] |
89 | call [con_write_asciiz] |
88 | 90 | ||
89 | jmp .loop |
91 | jmp .loop |
90 | 92 | ||
91 | acpt_err: |
93 | acpt_err: |
92 | push str8 |
94 | push str8 |
93 | call [con_write_asciiz] |
95 | call [con_write_asciiz] |
94 | jmp done |
96 | jmp done |
95 | 97 | ||
96 | listen_err: |
98 | listen_err: |
97 | push str3 |
99 | push str3 |
98 | call [con_write_asciiz] |
100 | call [con_write_asciiz] |
99 | jmp done |
101 | jmp done |
100 | 102 | ||
101 | bind_err: |
103 | bind_err: |
102 | push str4 |
104 | push str4 |
103 | call [con_write_asciiz] |
105 | call [con_write_asciiz] |
104 | jmp done |
106 | jmp done |
105 | 107 | ||
106 | sock_err: |
108 | sock_err: |
107 | push str6 |
109 | push str6 |
108 | call [con_write_asciiz] |
110 | call [con_write_asciiz] |
109 | jmp done |
111 | jmp done |
110 | 112 | ||
111 | done: |
113 | done: |
112 | call [con_getch2] |
114 | call [con_getch2] |
113 | push 1 |
115 | push 1 |
114 | call [con_exit] |
116 | call [con_exit] |
115 | exit: |
117 | exit: |
116 | mcall -1 |
118 | mcall -1 |
117 | 119 | ||
118 | 120 | ||
119 | 121 | ||
120 | ; data |
122 | ; data |
121 | title db 'TCP stream server - test',0 |
123 | title db 'TCP stream server - test',0 |
122 | str1 db 'Opening socket',10, 0 |
124 | str1 db 'Opening socket',10, 0 |
123 | str2 db 'Listening for incoming connections...',10,0 |
125 | str2 db 'Listening for incoming connections...',10,0 |
124 | str3 db 'Listen error',10,10,0 |
126 | str3 db 'Listen error',10,10,0 |
125 | str4 db 'Bind error',10,10,0 |
127 | str4 db 'Bind error',10,10,0 |
126 | str5 db 'Setsockopt error.',10,10,0 |
128 | str5 db 'Setsockopt error.',10,10,0 |
127 | str6 db 'Could not open socket',10,10,0 |
129 | str6 db 'Could not open socket',10,10,0 |
128 | str7 db 'Got data!',10,10,0 |
130 | str7 db 'Got data!',10,10,0 |
129 | str8 db 'Error accepting connection',10,10,0 |
131 | str8 db 'Error accepting connection',10,10,0 |
130 | 132 | ||
131 | hello db 'Hello world!',0 |
133 | hello db 'Hello world!',0 |
132 | .length = $ - hello |
134 | .length = $ - hello |
133 | 135 | ||
134 | sockaddr1: |
136 | sockaddr1: |
135 | dw AF_INET4 |
137 | dw AF_INET4 |
136 | .port dw 23 |
138 | .port dw 23 |
137 | .ip dd 0 |
139 | .ip dd 0 |
138 | rb 10 |
140 | rb 10 |
139 | .length = $ - sockaddr1 |
141 | .length = $ - sockaddr1 |
140 | 142 | ||
141 | ; import |
143 | ; import |
142 | align 4 |
144 | align 4 |
143 | @IMPORT: |
145 | @IMPORT: |
144 | 146 | ||
145 | library console, 'console.obj' |
147 | library console, 'console.obj' |
146 | 148 | ||
147 | import console, \ |
149 | import console, \ |
148 | con_start, 'START', \ |
150 | con_start, 'START', \ |
149 | con_init, 'con_init', \ |
151 | con_init, 'con_init', \ |
150 | con_write_asciiz, 'con_write_asciiz', \ |
152 | con_write_asciiz, 'con_write_asciiz', \ |
151 | con_exit, 'con_exit', \ |
153 | con_exit, 'con_exit', \ |
152 | con_gets, 'con_gets',\ |
154 | con_gets, 'con_gets',\ |
153 | con_cls, 'con_cls',\ |
155 | con_cls, 'con_cls',\ |
154 | con_printf, 'con_printf',\ |
156 | con_printf, 'con_printf',\ |
155 | con_getch2, 'con_getch2',\ |
157 | con_getch2, 'con_getch2',\ |
156 | con_set_cursor_pos, 'con_set_cursor_pos' |
158 | con_set_cursor_pos, 'con_set_cursor_pos' |
157 | i_end: |
159 | i_end: |
158 | 160 | ||
159 | socketnum dd ? |
161 | socketnum dd ? |
160 | socketnum2 dd ? |
162 | socketnum2 dd ? |
161 | buffer rb BUFFERSIZE |
163 | buffer rb BUFFERSIZE |
162 | .length = BUFFERSIZE |
164 | .length = BUFFERSIZE |
163 | 165 | ||
164 | align 4 |
166 | align 4 |
165 | rb 4096 ; stack |
167 | rb 4096 ; stack |
166 | mem: |
168 | mem: |