49 |
int server_lastseq; |
int server_lastseq; |
50 |
|
|
51 |
buffer_t access_in, access_out, if_in, if_out; |
buffer_t access_in, access_out, if_in, if_out; |
52 |
#define BUFFER_SIZE 1024*10 /* each buffer is 10Kb sized */ |
|
53 |
|
#define BUFFER_SIZE MAX_PACKET_SIZE*2 /* each buffer can handle 2 full packets */ |
54 |
|
|
55 |
int |
int |
56 |
prot30_start () |
prot30_start () |
103 |
case init: |
case init: |
104 |
case login: |
case login: |
105 |
case ipconfig: |
case ipconfig: |
106 |
|
case disconnect: |
107 |
/* Here we can't receive IP data from user since |
/* Here we can't receive IP data from user since |
108 |
IP stack isn't initialized |
IP stack isn't initialized |
109 |
*/ |
*/ |
110 |
maxfd = access_fd + 1; |
maxfd = access_fd + 1; |
|
/* $$$ TODO $$$ */ |
|
|
/* Verify that the buffer isn't full */ |
|
111 |
FD_SET (access_fd, &rfdset); |
FD_SET (access_fd, &rfdset); |
112 |
if (access_out.used > 0) |
if (access_out.used > 0) |
113 |
FD_SET (access_fd, &wfdset); |
FD_SET (access_fd, &wfdset); |
114 |
break; |
break; |
115 |
|
|
116 |
case normal: |
case normal: |
|
case disconnect: |
|
117 |
maxfd = MAX (access_fd, if_fd) + 1; |
maxfd = MAX (access_fd, if_fd) + 1; |
118 |
FD_SET (access_fd, &rfdset); |
FD_SET (access_fd, &rfdset); |
119 |
if (if_fd >= 0) /* FIXME: remove when ready */ |
if (if_fd >= 0 && /* FIXME: remove when ready */ |
120 |
FD_SET (if_fd, &rfdset); |
buffer_percent_free(&access_out) > 20 ) |
121 |
|
/* Make sure we have enough space for some ACK */ |
122 |
|
FD_SET (if_fd, &rfdset); |
123 |
|
|
124 |
if (access_out.used > 0) |
if (access_out.used > 0) |
125 |
FD_SET (access_fd, &wfdset); |
FD_SET (access_fd, &wfdset); |
126 |
if (if_out.used > 0) |
if (if_out.used > 0) |
134 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
135 |
timedout = 0; |
timedout = 0; |
136 |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
137 |
if (fds > 0) |
if( access_is_connected() ) |
138 |
{ |
{ |
139 |
if (access_fd != -1 && FD_ISSET (access_fd, &rfdset)) |
if (fds > 0) |
140 |
{ |
{ |
141 |
buffer_recv (&access_in, access_fd); |
if (FD_ISSET (access_fd, &rfdset)) |
142 |
prot30_treat_input (); |
{ |
143 |
} |
buffer_recv (&access_in, access_fd); |
144 |
|
prot30_treat_input (); |
145 |
if (if_fd != -1 && FD_ISSET (if_fd, &rfdset)) |
} |
146 |
buffer_recv (&if_in, if_fd); |
if (FD_ISSET (access_fd, &wfdset)) |
147 |
|
buffer_send (&access_out, access_fd); |
148 |
if (access_fd != -1 && FD_ISSET (access_fd, &wfdset)) |
|
149 |
buffer_send (&access_out, access_fd); |
if (if_fd != -1 && FD_ISSET (if_fd, &rfdset)) |
150 |
|
{ |
151 |
if (if_fd != -1 && FD_ISSET (if_fd, &wfdset)) |
buffer_recv (&if_in, if_fd); |
152 |
buffer_send (&if_out, if_fd); |
prot30_send_ip (); |
153 |
|
} |
154 |
|
if (if_fd != -1 && FD_ISSET (if_fd, &wfdset)) |
155 |
|
buffer_send (&if_out, if_fd); |
156 |
|
} |
157 |
|
else |
158 |
|
{ |
159 |
|
timedout = 1; |
160 |
|
printf ("Timed out\n"); |
161 |
|
} |
162 |
} |
} |
163 |
else |
else |
164 |
{ |
{ |
165 |
timedout = 1; |
printf("Your connection has been closed!\n"); |
166 |
printf ("Timed out\n"); |
prot30_set_state(exiting); |
167 |
} |
} |
168 |
} |
} |
169 |
} |
} |
170 |
|
|
315 |
*data_size = 0; |
*data_size = 0; |
316 |
if (access_in.used < AOL_DATA_OFFSET) |
if (access_in.used < AOL_DATA_OFFSET) |
317 |
return 0; |
return 0; |
318 |
|
|
319 |
p = memchr (buffer_start (&access_in), AOL_MAGIC, access_in.used); |
p = memchr (buffer_start (&access_in), AOL_MAGIC, access_in.used); |
320 |
if (p != buffer_start (&access_in)) |
if (p != buffer_start (&access_in)) |
321 |
{ |
{ |
322 |
/* There is some unknow data in the buffer they could have sense |
/* There is some unknow data in the buffer they could have sense |
323 |
but it is probably transmission error |
but it is probably transmission error |
324 |
*/ |
*/ |
325 |
len = (int) p - (int) buffer_start (&access_in); |
if(p) |
326 |
|
len = (int) p - (int) buffer_start (&access_in); |
327 |
|
else |
328 |
|
len = access_in.used; |
329 |
printf ("%d bytes dropped from buffer!\n", len); |
printf ("%d bytes dropped from buffer!\n", len); |
330 |
buffer_free (&access_in, len); |
buffer_free (&access_in, len); |
331 |
} |
} |
332 |
if (access_in.used < AOL_DATA_OFFSET) |
if (access_in.used < AOL_DATA_OFFSET) |
333 |
return 0; |
return 0; |
334 |
|
|
335 |
/* So here we have a full header */ |
/* So here we have a full header */ |
336 |
h = p; |
h = p; |
337 |
d = p + AOL_DATA_OFFSET; |
d = p + AOL_DATA_OFFSET; |
338 |
s = ntohs (h->size); |
s = ntohs (h->size); |
339 |
ds = s - AOL_SIZE_OFFSET; |
ds = s - AOL_SIZE_OFFSET; |
340 |
|
|
341 |
if (access_in.used < s + 1) |
if (access_in.used < s + 1) |
342 |
return 0; |
return 0; |
343 |
|
|
344 |
/* Good we have an entire packet */ |
/* Good we have an entire packet */ |
345 |
/* $$$ TODO $$$ */ |
/* $$$ TODO $$$ */ |
346 |
/* We should verify the CRC and that the packet is well 0x0d terminated */ |
/* We should verify the CRC and that the packet is well 0x0d terminated */ |
349 |
h->checksum = ntohs (h->checksum); |
h->checksum = ntohs (h->checksum); |
350 |
*data = d; |
*data = d; |
351 |
*data_size = ds; |
*data_size = ds; |
352 |
|
|
353 |
return 1; |
return 1; |
354 |
} |
} |
355 |
|
|