4 * AUTHOR : unknown (sources found on www.telnet.org)
5 * PROJECT : ReactOS Operating System
6 * DESCRIPTION: telnet client for the W32 subsystem
9 * 2001-02-21 ea Modified to compile under 0.0.16 src tree
19 // sock_loop is the thread dedicatd to reading socket input.
20 // It waits for data from the socket, and then gives it one byte at a time
21 // to the telnet vm to process.
24 DWORD sock_loop(SOCKET server)
30 while( (read = recv(server,buf,sizeof(buf),0)) && read != SOCKET_ERROR )
36 int x = WSAGetLastError();
40 DWORD input_loop(SOCKET server)
47 WaitForSingleObject(StandardInput, INFINITE);
48 ReadFile(StandardInput, buf, sizeof buf, & read, NULL);
50 while(SOCKET_ERROR != send(server, buf, read, 0));
56 void telnet(SOCKET server)
59 DWORD dwThreadIdinput;
63 threads[0] = CreateThread(
64 NULL, /* no security attributes */
65 0, /* use default stack size */
66 (LPTHREAD_START_ROUTINE) sock_loop, /* thread function */
67 (LPVOID)server, /* argument to thread function */
68 0, /* use default creation flags */
69 &dwThreadIdsock); /* returns the thread identifier */
71 //wait for the other thread to complete any setup negotiation...
72 //Sleep(500); //- this is not the problem - its just bloody stuffing up!
74 threads[1] = CreateThread(
75 NULL, /* no security attributes */
76 0, /* use default stack size */
77 (LPTHREAD_START_ROUTINE) input_loop, /* thread function */
78 (LPVOID)server, /* argument to thread function */
79 0, /* use default creation flags */
80 &dwThreadIdinput); /* returns the thread identifier */
83 WaitForMultipleObjects(2,threads,FALSE,INFINITE);
88 // connect to the hostname,port
91 char const* pszHostName,
95 if((*pszHostName <= '9') && (*pszHostName >= '0'))
97 if((ip = inet_addr(pszHostName)) == INADDR_NONE)
98 err("invalid host IP address given");
102 hostent* ent = gethostbyname(pszHostName);
104 err(sockmsg(WSAGetLastError()));
105 ip = *(unsigned long*)(ent->h_addr);
109 name.sin_family = AF_INET;
110 name.sin_port = htons(nPort);
111 name.sin_addr = *(in_addr*)&ip;
113 console_title_connecting (pszHostName, nPort);
117 if((server = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))==INVALID_SOCKET)
118 err(sockmsg(WSAGetLastError()));
120 if(SOCKET_ERROR == connect(server,(sockaddr*)&name,sizeof(sockaddr)))
121 err(sockmsg(WSAGetLastError()));
123 console_title_connected (pszHostName, nPort);