Rev 2994 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2994 | Rev 2995 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; Version 2, June 1991 ;; |
14 | ;; Version 2, June 1991 ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 17... | Line 17... | ||
17 | 17 | ||
Line 18... | Line 18... | ||
18 | $Revision: 2994 $ |
18 | $Revision: 2995 $ |
Line 19... | Line 19... | ||
19 | 19 | ||
Line 42... | Line 42... | ||
42 | 42 | ||
Line 43... | Line 43... | ||
43 | ends |
43 | ends |
Line 44... | Line 44... | ||
44 | 44 | ||
45 | struct IP_SOCKET SOCKET |
45 | struct IP_SOCKET SOCKET |
Line 46... | Line 46... | ||
46 | 46 | ||
Line 47... | Line 47... | ||
47 | LocalIP rd 4 |
47 | LocalIP rd 4 ; network byte order |
Line 48... | Line 48... | ||
48 | RemoteIP rd 4 |
48 | RemoteIP rd 4 ; network byte order |
49 | 49 | ||
Line 50... | Line 50... | ||
50 | ends |
50 | ends |
51 | 51 | ||
52 | struct TCP_SOCKET IP_SOCKET |
52 | struct TCP_SOCKET IP_SOCKET |
53 | 53 | ||
Line 139... | Line 139... | ||
139 | 139 | ||
Line 140... | Line 140... | ||
140 | ends |
140 | ends |
Line 141... | Line 141... | ||
141 | 141 | ||
142 | struct UDP_SOCKET IP_SOCKET |
142 | struct UDP_SOCKET IP_SOCKET |
143 | 143 | ||
Line 144... | Line 144... | ||
144 | LocalPort dw ? |
144 | LocalPort dw ? ; network byte order |
Line 211... | Line 211... | ||
211 | pseudo_random eax |
211 | pseudo_random eax |
212 | cmp ax, MIN_EPHEMERAL_PORT |
212 | cmp ax, MIN_EPHEMERAL_PORT |
213 | jb @r |
213 | jb @r |
214 | cmp ax, MAX_EPHEMERAL_PORT |
214 | cmp ax, MAX_EPHEMERAL_PORT |
215 | ja @r |
215 | ja @r |
- | 216 | xchg al, ah |
|
216 | mov [last_UDP_port], ax |
217 | mov [last_UDP_port], ax |
Line 217... | Line 218... | ||
217 | 218 | ||
218 | @@: |
219 | @@: |
219 | pseudo_random eax |
220 | pseudo_random eax |
220 | cmp ax, MIN_EPHEMERAL_PORT |
221 | cmp ax, MIN_EPHEMERAL_PORT |
221 | jb @r |
222 | jb @r |
222 | cmp ax, MAX_EPHEMERAL_PORT |
223 | cmp ax, MAX_EPHEMERAL_PORT |
- | 224 | ja @r |
|
223 | ja @r |
225 | xchg al, ah |
Line 224... | Line 226... | ||
224 | mov [last_TCP_port], ax |
226 | mov [last_TCP_port], ax |
Line 444... | Line 446... | ||
444 | mov ebx, [NET_DEFAULT] |
446 | mov ebx, [NET_DEFAULT] |
445 | mov ebx, [IP_LIST + 4*ebx] |
447 | mov ebx, [IP_LIST + 4*ebx] |
446 | @@: |
448 | @@: |
447 | mov [eax + IP_SOCKET.LocalIP], ebx |
449 | mov [eax + IP_SOCKET.LocalIP], ebx |
Line 448... | Line 450... | ||
448 | 450 | ||
449 | mov bx, [edx + 2] ; Now fill in the port if it's still available |
451 | mov bx, [edx + 2] ; Now fill in the local port if it's still available |
450 | call SOCKET_check_port |
452 | call SOCKET_check_port |
Line 451... | Line 453... | ||
451 | jz s_error ; ZF is set by socket_check_port, on error |
453 | jz s_error ; ZF is set by socket_check_port, on error |
452 | 454 | ||
Line 1104... | Line 1106... | ||
1104 | je .udp |
1106 | je .udp |
Line 1105... | Line 1107... | ||
1105 | 1107 | ||
1106 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
1108 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
Line 1107... | Line -... | ||
1107 | je .tcp |
- | |
1108 | - | ||
1109 | jmp .error |
- | |
1110 | - | ||
1111 | .done: |
- | |
1112 | mov [eax + UDP_SOCKET.LocalPort], bx |
1109 | je .tcp |
1113 | .error: |
1110 | |
Line 1114... | Line 1111... | ||
1114 | pop ecx esi ebx |
1111 | pop ecx esi ebx |
1115 | ret |
1112 | ret |
1116 | 1113 | ||
1117 | .udp: |
1114 | .udp: |
- | 1115 | mov bx, [last_UDP_port] |
|
1118 | mov bx, [last_UDP_port] |
1116 | call .findit |
- | 1117 | mov [last_UDP_port], bx |
|
Line 1119... | Line 1118... | ||
1119 | call .findit |
1118 | |
1120 | mov [last_UDP_port], bx |
1119 | pop ecx esi ebx |
1121 | jmp .done |
1120 | ret |
1122 | 1121 | ||
- | 1122 | .tcp: |
|
1123 | .tcp: |
1123 | mov bx, [last_TCP_port] |
- | 1124 | call .findit |
|
Line 1124... | Line 1125... | ||
1124 | mov bx, [last_TCP_port] |
1125 | mov [last_TCP_port], bx |
1125 | call .findit |
1126 | |
1126 | mov [last_TCP_port], bx |
1127 | pop ecx esi ebx |
- | 1128 | ret |
|
1127 | jmp .done |
1129 | |
Line 1128... | Line 1130... | ||
1128 | 1130 | ||
1129 | 1131 | .restart: |
|
Line 1130... | Line 1132... | ||
1130 | .restart: |
1132 | mov bx, MIN_EPHEMERAL_PORT_N |
1131 | mov bx, MIN_EPHEMERAL_PORT |
1133 | .findit: |
1132 | .findit: |
- | |
1133 | inc bx |
1134 | cmp bx, MAX_EPHEMERAL_PORT_N |
Line 1134... | Line 1135... | ||
1134 | 1135 | je .restart |
|
Line 1148... | Line 1149... | ||
1148 | ; |
1149 | ; |
1149 | ; Checks if a local port number is unused |
1150 | ; Checks if a local port number is unused |
1150 | ; If the proposed port number is unused, it is filled in in the socket structure |
1151 | ; If the proposed port number is unused, it is filled in in the socket structure |
1151 | ; |
1152 | ; |
1152 | ; IN: eax = socket ptr (to find out if its a TCP/UDP socket) |
1153 | ; IN: eax = socket ptr (to find out if its a TCP/UDP socket) |
1153 | ; bx = proposed socket number |
1154 | ; bx = proposed socket number (network byte order) |
1154 | ; |
1155 | ; |
1155 | ; OUT: ZF = cleared on error |
1156 | ; OUT: ZF = set on error |
1156 | ; |
1157 | ; |
1157 | ;----------------------------------------------------------------- |
1158 | ;----------------------------------------------------------------- |
1158 | align 4 |
1159 | align 4 |
1159 | SOCKET_check_port: |
1160 | SOCKET_check_port: |
Line 1180... | Line 1181... | ||
1180 | 1181 | ||
1181 | DEBUGF 1,"local port %u already in use\n", bx |
1182 | DEBUGF 1,"local port %u already in use\n", bx |
Line 1182... | Line 1183... | ||
1182 | ret |
1183 | ret |
1183 | 1184 | ||
1184 | .port_ok: |
1185 | .port_ok: |
1185 | DEBUGF 1,"local port %u is free\n", bx |
1186 | DEBUGF 1,"local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf |
1186 | mov [eax + UDP_SOCKET.LocalPort], bx |
- | |
1187 | or bx, bx ; set the zero-flag |
1187 | mov [eax + UDP_SOCKET.LocalPort], bx |
Line 1188... | Line 1188... | ||
1188 | 1188 | or bx, bx ; clear the zero-flag |