1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// tests/dns1.c
|
4 |
|
|
//
|
5 |
|
|
// Simple test of DNS client support
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): andrew.lunn
|
44 |
|
|
// Contributors: andrew.lunn, jskov
|
45 |
|
|
// Date: 2001-09-18
|
46 |
|
|
// Purpose:
|
47 |
|
|
// Description: Test FTPClient functions. Note that the _XXX defines below
|
48 |
|
|
// control what addresses the test uses. These must be
|
49 |
|
|
// changed to match the particular testing network in which
|
50 |
|
|
// the test is to be run.
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//==========================================================================
|
55 |
|
|
|
56 |
|
|
#include <network.h>
|
57 |
|
|
#include <ftpclient.h>
|
58 |
|
|
#include <cyg/infra/testcase.h>
|
59 |
|
|
|
60 |
|
|
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
|
61 |
|
|
static char stack[STACK_SIZE];
|
62 |
|
|
static cyg_thread thread_data;
|
63 |
|
|
static cyg_handle_t thread_handle;
|
64 |
|
|
|
65 |
|
|
#define __string(_x) #_x
|
66 |
|
|
#define __xstring(_x) __string(_x)
|
67 |
|
|
|
68 |
|
|
#define _FTP_SRV __xstring(172.16.19.254) // farmnet dns0 address
|
69 |
|
|
|
70 |
|
|
#define FTPBUFSIZE (1024 * 64)
|
71 |
|
|
char ftpbuf[FTPBUFSIZE];
|
72 |
|
|
char ftpbuf1[FTPBUFSIZE];
|
73 |
|
|
|
74 |
|
|
void
|
75 |
|
|
ftp_test(cyg_addrword_t p)
|
76 |
|
|
{
|
77 |
|
|
int ret;
|
78 |
|
|
|
79 |
|
|
CYG_TEST_INIT();
|
80 |
|
|
|
81 |
|
|
init_all_network_interfaces();
|
82 |
|
|
|
83 |
|
|
CYG_TEST_INFO("Getting /etc/passwd from %s\n" _FTP_SRV);
|
84 |
|
|
ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
|
85 |
|
|
"/etc/passwd",ftpbuf,FTPBUFSIZE,
|
86 |
|
|
ftpclient_printf);
|
87 |
|
|
|
88 |
|
|
if (ret > 0) {
|
89 |
|
|
diag_printf("PASS:< %s bytes received>\n",ret);
|
90 |
|
|
} else {
|
91 |
|
|
diag_printf("FAIL:< ftp_get returned %d>\n",ret);
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
CYG_TEST_INFO("Putting passwd file back in /incoming/passwd\n");
|
95 |
|
|
ret = ftp_put(_FTP_SRV,"anonymous","ftpclient1",
|
96 |
|
|
"/incoming/passwd",ftpbuf,ret,
|
97 |
|
|
ftpclient_printf);
|
98 |
|
|
|
99 |
|
|
if (ret > 0) {
|
100 |
|
|
diag_printf("PASS:\n");
|
101 |
|
|
} else {
|
102 |
|
|
diag_printf("FAIL:< ftp_get returned %d>\n",ret);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
CYG_TEST_INFO("Reading back /incoming/passwd\n");
|
106 |
|
|
ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
|
107 |
|
|
"/incoming/passwd",ftpbuf1,FTPBUFSIZE,
|
108 |
|
|
ftpclient_printf);
|
109 |
|
|
|
110 |
|
|
if (ret > 0) {
|
111 |
|
|
diag_printf("PASS:< %s bytes received>\n",ret);
|
112 |
|
|
} else {
|
113 |
|
|
diag_printf("FAIL:< ftp_get returned %d>\n",ret);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
CYG_TEST_PASS_FAIL(!memcmp(ftpbuf,ftpbuf1,ret),"Transfer integrity");
|
117 |
|
|
|
118 |
|
|
CYG_TEST_INFO("ftp_Get'ing with a bad username\n");
|
119 |
|
|
ret = ftp_get(_FTP_SRV,"nosuchuser","ftpclient1",
|
120 |
|
|
"/incoming/passwd",ftpbuf1,FTPBUFSIZE,
|
121 |
|
|
ftpclient_printf);
|
122 |
|
|
CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad Username");
|
123 |
|
|
|
124 |
|
|
CYG_TEST_INFO("ftp_get'ting with a bad passwd\n");
|
125 |
|
|
ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
|
126 |
|
|
"/incoming/passwd",ftpbuf1,FTPBUFSIZE,
|
127 |
|
|
ftpclient_printf);
|
128 |
|
|
CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");
|
129 |
|
|
|
130 |
|
|
CYG_TEST_INFO("ftp_get'ing from a with a bad passwd\n");
|
131 |
|
|
ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
|
132 |
|
|
"/incoming/passwd",ftpbuf1,FTPBUFSIZE,
|
133 |
|
|
ftpclient_printf);
|
134 |
|
|
CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");
|
135 |
|
|
|
136 |
|
|
CYG_TEST_INFO("ftp_get'ing from a bad server\n");
|
137 |
|
|
ret = ftp_get("127.0.0.1","nobody","ftpclient1",
|
138 |
|
|
"/incoming/passwd",ftpbuf1,FTPBUFSIZE,
|
139 |
|
|
ftpclient_printf);
|
140 |
|
|
CYG_TEST_PASS_FAIL(ret==FTP_NOSUCHHOST,"Bad server");
|
141 |
|
|
|
142 |
|
|
CYG_TEST_INFO("ftp_get'ing a file which is too big");
|
143 |
|
|
ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
|
144 |
|
|
"/incoming/passwd",ftpbuf,2,
|
145 |
|
|
ftpclient_printf);
|
146 |
|
|
CYG_TEST_PASS_FAIL(ret==FTP_TOOBIG,"File too big");
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
void
|
150 |
|
|
cyg_start(void)
|
151 |
|
|
{
|
152 |
|
|
/* Create a main thread, so we can run the scheduler and have time 'pass' */
|
153 |
|
|
cyg_thread_create(10, // Priority - just a number
|
154 |
|
|
ftp_test, // entry
|
155 |
|
|
0, // entry parameter
|
156 |
|
|
"FTP test", // Name
|
157 |
|
|
&stack[0], // Stack
|
158 |
|
|
STACK_SIZE, // Size
|
159 |
|
|
&thread_handle, // Handle
|
160 |
|
|
&thread_data // Thread data structure
|
161 |
|
|
);
|
162 |
|
|
cyg_thread_resume(thread_handle); /* Start it */
|
163 |
|
|
cyg_scheduler_start();
|
164 |
|
|
}
|