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