1 //==========================================================================
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
10 // -------------------------------------------
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
15 // -------------------------------------------
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
22 // Contributors: gthomas
28 //####DESCRIPTIONEND####
30 //==========================================================================
35 #ifndef CYGPKG_LIBC_STDIO
36 #define perror(s) diag_printf(#s ": %s\n", strerror(errno))
39 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
40 static char stack[STACK_SIZE];
41 static cyg_thread thread_data;
42 static cyg_handle_t thread_handle;
55 ftp_test(struct bootp *bp)
59 struct sockaddr_in host, local;
62 char _USER[] = "USER anonymous\r\n";
63 char _PASS[] = "PASS none@abc.com\r\n";
64 char _QUIT[] = "QUIT\r\n";
66 s = socket(AF_INET, SOCK_STREAM, 0);
68 pexit("stream socket");
70 sent = getservbyname("ftp", "tcp");
71 if (sent == (struct servent *)0) {
72 pexit("getservbyname");
74 // Set up host address
75 host.sin_family = AF_INET;
76 host.sin_len = sizeof(host);
77 host.sin_addr = bp->bp_siaddr;
78 host.sin_port = sent->s_port; // Network order already
79 if (connect(s, (struct sockaddr *)&host, sizeof(host)) < 0) {
83 if (getsockname(s, (struct sockaddr *)&local, &len) < 0) {
86 diag_printf("connected to %s.%d", inet_ntoa(host.sin_addr), ntohs(host.sin_port));
87 diag_printf(" as %s.%d\n", inet_ntoa(local.sin_addr), ntohs(local.sin_port));
88 if ((len = read(s, buf, sizeof(buf))) < 0) {
92 diag_printf(">> %s", buf);
93 // Try and log in as 'anonymous'
95 if ((len = write(s, _USER, slen)) != slen) {
99 diag_printf("wrote only %d bytes\n", len);
102 if ((len = read(s, buf, sizeof(buf))) < 0) {
106 diag_printf(">> %s", buf);
107 slen = strlen(_PASS);
108 if ((len = write(s, _PASS, slen)) != slen) {
112 diag_printf("wrote only %d bytes\n", len);
115 if ((len = read(s, buf, sizeof(buf))) < 0) {
119 diag_printf(">> %s", buf);
120 slen = strlen(_QUIT);
121 if ((len = write(s, _QUIT, slen)) != slen) {
125 diag_printf("wrote only %d bytes\n", len);
128 while ((len = read(s, buf, sizeof(buf))) > 0) {
130 diag_printf(">> %s", buf);
139 net_test(cyg_addrword_t param)
141 diag_printf("Start FTP test\n");
142 init_all_network_interfaces();
143 #ifdef CYGHWR_NET_DRIVER_ETH0
145 ftp_test(ð0_bootp_data);
148 #ifdef CYGHWR_NET_DRIVER_ETH1
150 ftp_test(ð1_bootp_data);
159 // Create a main thread, so we can run the scheduler and have time 'pass'
160 cyg_thread_create(10, // Priority - just a number
162 0, // entry parameter
163 "Network test", // Name
166 &thread_handle, // Handle
167 &thread_data // Thread data structure
169 cyg_thread_resume(thread_handle); // Start it
170 cyg_scheduler_start();