1 /* $Id: main.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
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
10 * 2001-02-27 ea If run with no argument, it asks for a hostname.
12 ///////////////////////////////////////////////////////////////////////////////
18 // This file provdes the main entry point for the project, and all the
19 // global scope support routines.
22 // This file expects to be linked without the C-Runtime. If compiling,
23 // please force the entry point symbol to be "main", and do not link in
24 // the default librarys.
25 // This means that no c-runtime functions can be used anywhere in the
26 // project. I expect this will also exclude any MFC based additions.
28 ///////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
40 // Our simple replacement for the c-runtime includes getting the StandardInput,
41 // StandardOutput & StandardError handles, and providing new and delete operators, that work
42 // with the win32 heap functions.
46 // standard handles needed for CRT emulation
50 HANDLE StandardOutput
;
54 // new will use the win32 heap functions.
56 void* operator new(unsigned int nSize
)
58 return HeapAlloc(hHeap
,0,nSize
);
62 // delete operator provides all memory de-allocation.
63 // HeapFree doesn't accept NULL.
65 void operator delete(void* pMem
)
67 if(pMem
) HeapFree(hHeap
,0,pMem
);
72 void err(char const* s
, ...)
77 wvsprintf (buf
, s
, (char*)(s
+ sizeof(int)));
78 WriteFile (StandardError
,"Error: ", 7, & nout
, NULL
);
79 WriteFile (StandardError
, buf
, lstrlen(buf
), & nout
, NULL
);
80 WriteFile (StandardError
, "\r\n\r\n", 4, & nout
, NULL
);
82 OutputDebugString(buf
);
83 OutputDebugString("\n");
85 ExitProcess (ERROR_SUCCESS
);
89 int main(int argc
, char * argv
[])
93 char name
[256] = {'\0'};
94 short port
= IPPORT_TELNET
; /* default tcp port */
96 ///////////////////////////////////////
99 StandardInput
= GetStdHandle(STD_INPUT_HANDLE
);
100 StandardOutput
= GetStdHandle(STD_OUTPUT_HANDLE
);
101 StandardError
= GetStdHandle(STD_ERROR_HANDLE
);
104 hHeap
= GetProcessHeap();
106 // Explicitly force the console into a good mode (actually all we are doing is turning
110 (ENABLE_LINE_INPUT
| ENABLE_ECHO_INPUT
| ENABLE_PROCESSED_INPUT
)
113 ///////////////////////////////////////
116 if (errn
= WSAStartup (0x0101, & wd
))
124 lstrcpy (name
, argv
[1]);
127 * Default port is IPPORT_TELNET.
132 port
= atoi (argv
[2]);
135 struct servent
* service
= NULL
;
137 service
= getservbyname (argv
[2], "tcp");
140 err("Invalid service name specified");
142 port
= service
->s_port
;
146 err("Invalid port specified");
149 /* Too many arguments */
152 err("Usage: telnet <hostname> [<port>]");
160 WriteFile (StandardError
,"host: ", 6, & Count
, NULL
);
161 ReadFile (StandardInput
, name
, sizeof name
, & Count
, NULL
);
163 while (*c
> ' ') ++ c
;
167 // guess what this does.
173 // Exit process terminates any waiting threads.
174 // (Its the CRT that makes a process close when the main thread exits.
175 // The WinAPI will leave the process as is for as long as it has a
176 // thread any thread.
177 ExitProcess (EXIT_SUCCESS
);