4
* Basilisk II (C) 1997-2001 Christian Bauer
6
* Windows platform specific code copyright (C) Lauri Pesonen
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#pragma optimize("",off)
35
static int m_ftp_port_count = 0;
36
#define MAX_FTP_PORTS 100
37
static uint16 m_ftp_ports[MAX_FTP_PORTS];
39
bool ftp_is_ftp_port( uint16 port )
41
for( int i=0; i<m_ftp_port_count; i++ ) {
42
if( m_ftp_ports[i] == port ) return true;
49
const char *str = PrefsFindString("ftp_port_list");
52
char *ftp = new char [ strlen(str) + 1 ];
57
char *pp = strchr( p, ',' );
59
if( m_ftp_port_count < MAX_FTP_PORTS ) {
60
m_ftp_ports[m_ftp_port_count++] = (uint16)strtoul(p,0,0);
69
void ftp_modify_port_command(
72
const uint32 max_size,
78
if( max_size < 100 ) {
85
(is_pasv ? "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d).%c%c" : "PORT %d,%d,%d,%d,%d,%d%c%c"),
97
D(bug("ftp_modify_port_command: \"%s\"\r\n", buf ));
100
// this should be robust. rather skip it than do anything dangerous.
101
void ftp_parse_port_command(
104
uint16 &ftp_data_port,
115
// make it a c-string
116
if( count >= sizeof(b) ) count = sizeof(b)-1;
117
memcpy( b, buf, count );
120
for( uint32 i=0; i<count; i++ ) {
121
if( b[i] < ' ' || b[i] > 'z' ) {
124
b[i] = tolower(b[i]);
128
// D(bug("FTP: \"%s\"\r\n", b ));
132
while( *s == ' ' ) s++;
136
LOCAL SERVER: ..227 Entering Passive Mode (192,168,0,2,6,236). 0d 0a
138
if( atoi(s) == 227 && strstr(s,"passive") ) {
139
while( *s && *s != '(' ) s++;
140
if( *s++ == 0 ) s = 0;
146
LOCAL CLIENT: PORT 192,168,0,1,14,147 0d 0a
148
if( strncmp(s,"port ",5) == 0 ) {
156
// get remote ip (used only for verification)
157
for( uint32 i=0; i<4; i++ ) {
158
while( *s == ' ' ) s++;
163
ftp_ip = (ftp_ip << 8) + atoi(s);
164
while( *s && *s != ',' ) s++;
174
for( uint32 i=0; i<2; i++ ) {
175
while( *s == ' ' ) s++;
180
ftp_data_port = (ftp_data_port << 8) + atoi(s);
181
while( *s && *s != ',' && *s != ')' ) s++;
190
D(bug("ftp_parse_port_command: \"%s\"; port is %d\r\n", b, ftp_data_port ));