1 //==========================================================================
3 // tests/windows_telnet.c
5 // Test program showing how to create a client that dials into
6 // a Windows PPP server and waits for a telnet session.
8 //==========================================================================
9 //####ECOSGPLCOPYRIGHTBEGIN####
10 // -------------------------------------------
11 // This file is part of eCos, the Embedded Configurable Operating System.
12 // Portions created by Nick Garnett are
13 // Copyright (C) 2003 eCosCentric Ltd.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //####BSDCOPYRIGHTBEGIN####
42 // -------------------------------------------
44 // Portions of this software may have been derived from OpenBSD,
45 // FreeBSD or other sources, and are covered by the appropriate
46 // copyright disclaimers included herein.
48 // -------------------------------------------
50 //####BSDCOPYRIGHTEND####
51 //==========================================================================
52 //#####DESCRIPTIONBEGIN####
55 // Contributors: oyvind harboe
58 // Description: Example/test on how to connect to a Windows PPP server
61 //####DESCRIPTIONEND####
63 //==========================================================================
66 #include <pkgconf/system.h>
67 #include <pkgconf/net.h>
69 #include <cyg/ppp/ppp.h>
71 static char *windows_script[] =
74 "", "CLIENTCLIENT\\c",
75 "CLIENTSERVER", "\\c",
81 struct sockaddr_in sin;
82 struct sockaddr_in pin;
84 /* get an internet domain socket */
86 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
91 /* complete the socket structure */
92 memset(&sin, 0, sizeof(sin));
93 sin.sin_len = sizeof(sin);
94 sin.sin_family = AF_INET;
95 sin.sin_addr.s_addr = INADDR_ANY;
96 sin.sin_port = htons(23);
99 if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1)
104 /* bind the socket to the port number */
105 if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) == -1)
110 /* show that we are willing to listen */
111 if (listen(sd, SOMAXCONN) == -1)
117 /* wait for a client to talk to us */
118 socklen_t addrlen = sizeof(pin);
119 if ((sd_current = accept(sd, (struct sockaddr *) &pin, &addrlen)) == -1)
126 char *prompt="eCos>";
127 int promptlen = strlen(prompt);
129 if (write(sd_current, prompt, promptlen) != promptlen)
133 /* get a message from the client */
137 for (i=0; i<sizeof(dir)-1; i++)
139 // returns when a full line has been collected
140 len=read(sd_current, dir+i, 1);
145 if (write(sd_current, dir+i, 1)!=1)
156 // Break out on a new line
165 /* close up both sockets */
173 int main(int argc, char **argv)
175 // Bring up the TCP/IP network
176 init_all_network_interfaces();
180 cyg_ppp_options_t options;
181 cyg_ppp_handle_t ppp_handle;
183 // Initialize the options
184 cyg_ppp_options_init( &options );
186 options.script=windows_script;
187 options.baud = CYGNUM_SERIAL_BAUD_38400;
188 options.flowctl = CYG_PPP_FLOWCTL_NONE;
189 options.idle_time_limit = 0; // never shut down.
192 ppp_handle = cyg_ppp_up( "/dev/ser0", &options );
194 // Wait for it to get running
195 if( cyg_ppp_wait_up( ppp_handle ) == 0 )
203 // never reached, but for illustration:
205 // Bring PPP link down
206 cyg_ppp_down( ppp_handle );
208 // Wait for connection to go down.
209 cyg_ppp_wait_down( ppp_handle );