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)
58 struct sockaddr_in host, local;
61 char _USER[] = "USER anonymous\r\n";
62 char _PASS[] = "PASS none@abc.com\r\n";
63 char _QUIT[] = "QUIT\r\n";
65 s = socket(AF_INET, SOCK_STREAM, 0);
67 pexit("stream socket");
69 sent = getservbyname("ftp", "tcp");
70 if (sent == (struct servent *)0) {
71 pexit("getservbyname");
73 // Set up host address
74 host.sin_family = AF_INET;
75 host.sin_len = sizeof(host);
76 host.sin_addr = bp->bp_siaddr;
77 host.sin_port = sent->s_port; // Network order already
78 if (connect(s, (struct sockaddr *)&host, sizeof(host)) < 0) {
82 if (getsockname(s, (struct sockaddr *)&local, &len) < 0) {
85 diag_printf("connected to %s.%d", inet_ntoa(host.sin_addr), ntohs(host.sin_port));
86 diag_printf(" as %s.%d\n", inet_ntoa(local.sin_addr), ntohs(local.sin_port));
87 if ((len = read(s, buf, sizeof(buf))) < 0) {
91 diag_printf(">> %s", buf);
92 // Try and log in as 'anonymous'
94 if ((len = write(s, _USER, slen)) != slen) {
98 diag_printf("wrote only %d bytes\n", len);
101 if ((len = read(s, buf, sizeof(buf))) < 0) {
105 diag_printf(">> %s", buf);
106 slen = strlen(_PASS);
107 if ((len = write(s, _PASS, slen)) != slen) {
111 diag_printf("wrote only %d bytes\n", len);
114 if ((len = read(s, buf, sizeof(buf))) < 0) {
118 diag_printf(">> %s", buf);
119 slen = strlen(_QUIT);
120 if ((len = write(s, _QUIT, slen)) != slen) {
124 diag_printf("wrote only %d bytes\n", len);
127 while ((len = read(s, buf, sizeof(buf))) > 0) {
129 diag_printf(">> %s", buf);
138 net_test(cyg_addrword_t param)
140 diag_printf("Start FTP test\n");
141 init_all_network_interfaces();
142 #ifdef CYGHWR_NET_DRIVER_ETH0
144 ftp_test(ð0_bootp_data);
147 #ifdef CYGHWR_NET_DRIVER_ETH1
149 ftp_test(ð1_bootp_data);
158 // Create a main thread, so we can run the scheduler and have time 'pass'
159 cyg_thread_create(10, // Priority - just a number
161 0, // entry parameter
162 "Network test", // Name
165 &thread_handle, // Handle
166 &thread_data // Thread data structure
168 cyg_thread_resume(thread_handle); // Start it
169 cyg_scheduler_start();