2004-11-21 Casper S. Hornstrup <chorns@users.sourceforge.net>
authorCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 21 Nov 2004 22:27:01 +0000 (22:27 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 21 Nov 2004 22:27:01 +0000 (22:27 +0000)
* apps/utils/Makefile (UTIL_NET_APPS): Add arp, finger, ipconfig,
netstat, ping, telnet, and whois.
* bootdata/packages/reactos.dff: Add arp.exe, finger.exe, ipconfig.exe,
netstat.exe, ping.exe, telnet.exe, and whois.exe.
* apps\utils\net\arp: New directory; Move from rosapps.
* apps\utils\net\finger: Ditto.
* apps\utils\net\ipconfig: Ditto.
* apps\utils\net\netstat: Ditto.
* apps\utils\net\ping: Ditto.
* apps\utils\net\telnet: Ditto.
* apps\utils\net\whois: Ditto.

svn path=/trunk/; revision=11773

110 files changed:
reactos/apps/utils/Makefile
reactos/apps/utils/net/arp/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/arp/arp.c [new file with mode: 0644]
reactos/apps/utils/net/arp/arp.rc [new file with mode: 0644]
reactos/apps/utils/net/arp/makefile [new file with mode: 0644]
reactos/apps/utils/net/arp/trace.c [new file with mode: 0644]
reactos/apps/utils/net/arp/trace.h [new file with mode: 0644]
reactos/apps/utils/net/finger/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/finger/LICENSE.txt [new file with mode: 0644]
reactos/apps/utils/net/finger/err.c [new file with mode: 0644]
reactos/apps/utils/net/finger/err.h [new file with mode: 0644]
reactos/apps/utils/net/finger/finger.c [new file with mode: 0644]
reactos/apps/utils/net/finger/finger.rc [new file with mode: 0644]
reactos/apps/utils/net/finger/getopt.c [new file with mode: 0644]
reactos/apps/utils/net/finger/getopt.h [new file with mode: 0644]
reactos/apps/utils/net/finger/makefile [new file with mode: 0644]
reactos/apps/utils/net/finger/net.c [new file with mode: 0644]
reactos/apps/utils/net/finger/various.h [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/ipconfig.c [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/ipconfig.rc [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/makefile [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/trace.c [new file with mode: 0644]
reactos/apps/utils/net/ipconfig/trace.h [new file with mode: 0644]
reactos/apps/utils/net/netstat/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/netstat/makefile [new file with mode: 0644]
reactos/apps/utils/net/netstat/netstat.c [new file with mode: 0644]
reactos/apps/utils/net/netstat/netstat.rc [new file with mode: 0644]
reactos/apps/utils/net/netstat/resource.h [new file with mode: 0644]
reactos/apps/utils/net/netstat/trace.c [new file with mode: 0644]
reactos/apps/utils/net/netstat/trace.h [new file with mode: 0644]
reactos/apps/utils/net/ping/.cvsignore
reactos/apps/utils/net/ping/makefile [new file with mode: 0644]
reactos/apps/utils/net/ping/ping.c [new file with mode: 0644]
reactos/apps/utils/net/ping/ping.rc [new file with mode: 0644]
reactos/apps/utils/net/telnet/.cvsignore
reactos/apps/utils/net/telnet/Makefile
reactos/apps/utils/net/telnet/Makefile.mingw [new file with mode: 0644]
reactos/apps/utils/net/telnet/ansi.cpp [deleted file]
reactos/apps/utils/net/telnet/console.cpp [deleted file]
reactos/apps/utils/net/telnet/console.h [deleted file]
reactos/apps/utils/net/telnet/doc/00readme.avs [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/bugs.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/changes.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/license.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/options.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/readme.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/doc/ssh.txt [new file with mode: 0644]
reactos/apps/utils/net/telnet/helpsock.cpp [deleted file]
reactos/apps/utils/net/telnet/main.cpp [deleted file]
reactos/apps/utils/net/telnet/nvt.cpp [deleted file]
reactos/apps/utils/net/telnet/resource/tnmsg.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/resource/tnmsg.rc [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/ansiprsr.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/ansiprsr.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/keytrans.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/keytrans.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/stl_bids.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tcharmap.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tcharmap.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tconsole.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tconsole.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/telnet.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tkeydef.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tkeydef.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tkeymap.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tkeymap.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tmapldr.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tmapldr.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tmouse.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tmouse.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnclass.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnclass.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnclip.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnclip.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tncon.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tncon.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnconfig.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnconfig.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnerror.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnerror.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnetwork.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnetwork.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnmain.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnmain.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnmisc.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnmisc.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tnmsg.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tparams.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tparser.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tscript.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tscript.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tscroll.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/tscroll.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/ttelhndl.cpp [new file with mode: 0644]
reactos/apps/utils/net/telnet/src/ttelhndl.h [new file with mode: 0644]
reactos/apps/utils/net/telnet/telnet.cfg [new file with mode: 0644]
reactos/apps/utils/net/telnet/telnet.cpp [deleted file]
reactos/apps/utils/net/telnet/telnet.h [deleted file]
reactos/apps/utils/net/telnet/telnet.ico [new file with mode: 0644]
reactos/apps/utils/net/telnet/telnet.ini [new file with mode: 0644]
reactos/apps/utils/net/telnet/telnet.rc
reactos/apps/utils/net/telnet/vm.cpp [deleted file]
reactos/apps/utils/net/whois/.cvsignore [new file with mode: 0644]
reactos/apps/utils/net/whois/LICENSE.txt [new file with mode: 0644]
reactos/apps/utils/net/whois/makefile [new file with mode: 0644]
reactos/apps/utils/net/whois/whois.c [new file with mode: 0644]
reactos/apps/utils/net/whois/whois.rc [new file with mode: 0644]
reactos/bootdata/packages/reactos.dff

index c5348df..b3f39e0 100644 (file)
@@ -11,7 +11,7 @@ include $(PATH_TO_TOP)/rules.mak
 # cabman cat net objdir partinfo pice ps sc stats
 UTIL_APPS = cat objdir partinfo pnpdump sc shutdown stats tickcount consw rundll32 regsvr32 ps
 
-UTIL_NET_APPS = 
+UTIL_NET_APPS = arp finger ipconfig netstat ping telnet whois
 
 
 all: $(UTIL_APPS) $(UTIL_NET_APPS)
diff --git a/reactos/apps/utils/net/arp/.cvsignore b/reactos/apps/utils/net/arp/.cvsignore
new file mode 100644 (file)
index 0000000..954ada3
--- /dev/null
@@ -0,0 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.map
diff --git a/reactos/apps/utils/net/arp/arp.c b/reactos/apps/utils/net/arp/arp.c
new file mode 100644 (file)
index 0000000..4468cac
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * arp - display ARP cache from the IP stack parameters.
+ *
+ * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
+ *
+ * Robert Dickenson <robd@reactos.org>, August 15, 2002.
+ */
+#include <stdio.h>
+#include <windows.h>
+#include <tchar.h>
+#include <time.h>
+
+#include <iptypes.h>
+#include <ipexport.h>
+#include <iphlpapi.h>
+#include <snmp.h>
+
+#include "trace.h"
+
+
+VOID SNMP_FUNC_TYPE SnmpSvcInitUptime();
+DWORD SNMP_FUNC_TYPE SnmpSvcGetUptime();
+
+////////////////////////////////////////////////////////////////////////////////
+
+const char szUsage[] = { "\n" \
+    "Displays and modifies the IP Protocol to physical address translation tables\n" \
+    "used by address resolution protocol (ARP).\n" \
+    "\n" \
+    "ARP -s inet_addr eth_addr [if_addr]\n" \
+    "ARP -d inet_addr [if_addr]\n" \
+    "ARP -a [inet_addr] [-N if_addr]\n" \
+    "\n" \
+    "  -a            Displays the active ARP table by querying the current protocol\n" \
+    "                data. If inet_addr is specified, the IP and physical addresses\n" \
+    "                for the specified address are displayed. If more than one\n" \
+    "                network interface is using ARP, each interfaces ARP table is\n" \
+    "                displayed.\n" \
+    "  -g            Indentical to -a.\n" \
+    "  inet_addr     Specifies the IP address.\n" \
+    "  -N if_addr    Displays the ARP table for the specified interface only\n" \
+    "  -d            Deletes the host entry specified by inet_addr. inet_addr may be\n" \
+    "                wildcarded with * to delete all host entries in the ARP table.\n" \
+    "  -s            Adds the host and associates the IP address inet_addr with the\n" \
+    "                physical address eth_addr. The physical address must be specified\n" \
+    "                as 6 hexadecimal characters delimited by hyphens. The new entry\n" \
+    "                will become permanent in the ARP table.\n" \
+    "  eth_addr      Specifies the interface physical address.\n" \
+    "  if_addr       If present, this specifies the IP address of the interface whose\n" \
+    "                address translation table should be modified. If not present, the\n" \
+    "                first applicable interface will be used.\n" \
+    "Example:\n" \
+    "  > arp -s 192.168.0.12   55-AA-55-01-02-03   .... Static entry creation.\n" \
+    "  > arp -a                                    .... ARP table display.\n" \
+    "  > arp -d *                                  .... Delete all ARP table entries.\n"
+};
+
+void usage(void)
+{
+//     fprintf(stderr,"USAGE:\n");
+       fputs(szUsage, stderr);
+}
+
+int main(int argc, char *argv[])
+{
+    TCHAR szComputerName[50];
+    DWORD dwSize = 50;
+
+    int nBytes = 500;
+    BYTE* pCache;
+
+    if (argc > 1) {
+        usage();
+        return 1;
+    }
+
+    SnmpSvcInitUptime();
+
+    GetComputerName(szComputerName, &dwSize);
+    _tprintf(_T("ReactOS ARP cache on Computer Name: %s\n"), szComputerName);
+
+    pCache = (BYTE*)SnmpUtilMemAlloc(nBytes);
+
+        Sleep(2500);
+
+    if (pCache != NULL) {
+
+        DWORD dwUptime = SnmpSvcGetUptime();
+
+        _tprintf(_T("SNMP uptime: %d\n"), dwUptime);
+
+        SnmpUtilMemFree(pCache);
+    } else {
+        _tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n"));
+        return 1;
+    }
+       return 0;
+}
+
diff --git a/reactos/apps/utils/net/arp/arp.rc b/reactos/apps/utils/net/arp/arp.rc
new file mode 100644 (file)
index 0000000..40e0233
--- /dev/null
@@ -0,0 +1,6 @@
+/* $Id: arp.rc,v 1.1 2004/11/21 22:25:36 chorns Exp $ */
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS TCP/IPv4 Win32 arp\0"
+#define REACTOS_STR_INTERNAL_NAME      "arp\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "arp.exe\0"
+#include <reactos/version.rc>
diff --git a/reactos/apps/utils/net/arp/makefile b/reactos/apps/utils/net/arp/makefile
new file mode 100644 (file)
index 0000000..6b6057d
--- /dev/null
@@ -0,0 +1,17 @@
+PATH_TO_TOP = ../../../..
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = arp
+
+TARGET_CFLAGS = -D__USE_W32API
+
+TARGET_SDKLIBS = user32.a snmpapi.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
diff --git a/reactos/apps/utils/net/arp/trace.c b/reactos/apps/utils/net/arp/trace.c
new file mode 100644 (file)
index 0000000..d225a22
--- /dev/null
@@ -0,0 +1,53 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#include <stdio.h> 
+#include <stdarg.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <tchar.h>
+#include "trace.h"
+
+
+#ifdef _DEBUG
+
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+
+void _DebugBreak(void)
+{
+    DebugBreak();
+}
+
+void Trace(TCHAR* lpszFormat, ...)
+{
+    va_list args;
+    int nBuf;
+    TCHAR szBuffer[512];
+
+    va_start(args, lpszFormat);
+    nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
+    OutputDebugString(szBuffer);
+    // was there an error? was the expanded string too long?
+    //ASSERT(nBuf >= 0);
+    va_end(args);
+}
+
+void Assert(void* assert, TCHAR* file, int line, void* msg)
+{
+    if (msg == NULL) {
+        printf("ASSERT -- %s occured on line %u of file %s.\n",
+               assert, line, file);
+    } else {
+        printf("ASSERT -- %s occured on line %u of file %s: Message = %s.\n",
+               assert, line, file, msg);
+    }
+}
+
+#else
+
+void Trace(TCHAR* lpszFormat, ...) { };
+void Assert(void* assert, TCHAR* file, int line, void* msg) { };
+
+#endif //_DEBUG
+/////////////////////////////////////////////////////////////////////////////
diff --git a/reactos/apps/utils/net/arp/trace.h b/reactos/apps/utils/net/arp/trace.h
new file mode 100644 (file)
index 0000000..7f3318e
--- /dev/null
@@ -0,0 +1,61 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#ifndef __TRACE_H__
+#define __TRACE_H__
+
+#ifdef _DEBUG
+
+#ifdef _X86_
+#define BreakPoint()        _asm { int 3h }
+#else
+#define BreakPoint()        _DebugBreak()
+#endif
+
+#ifndef ASSERT
+#define ASSERT(exp)                                 \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, NULL);     \
+        BreakPoint();                               \
+    }                                               \
+}                                                   \
+
+#define ASSERTMSG(exp, msg)                         \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, msg);      \
+        BreakPoint();                               \
+    }                                               \
+}
+#endif
+
+//=============================================================================
+//  MACRO: TRACE()
+//=============================================================================
+
+#define TRACE  Trace
+
+
+#else   // _DEBUG
+
+//=============================================================================
+//  Define away MACRO's ASSERT() and TRACE() in non debug builds
+//=============================================================================
+
+#ifndef ASSERT
+#define ASSERT(exp)
+#define ASSERTMSG(exp, msg)
+#endif
+
+#define TRACE 0 ? (void)0 : Trace
+
+#endif // !_DEBUG
+
+
+void Assert(void* assert, TCHAR* file, int line, void* msg);
+void Trace(TCHAR* lpszFormat, ...);
+
+
+#endif // __TRACE_H__
+/////////////////////////////////////////////////////////////////////////////
diff --git a/reactos/apps/utils/net/finger/.cvsignore b/reactos/apps/utils/net/finger/.cvsignore
new file mode 100644 (file)
index 0000000..954ada3
--- /dev/null
@@ -0,0 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.map
diff --git a/reactos/apps/utils/net/finger/LICENSE.txt b/reactos/apps/utils/net/finger/LICENSE.txt
new file mode 100644 (file)
index 0000000..3f506f7
--- /dev/null
@@ -0,0 +1,23 @@
+July 22, 1999 
+
+To All Licensees, Distributors of Any Version of BSD: 
+
+As you know, certain of the Berkeley Software Distribution ("BSD") source code files 
+require that further distributions of products containing all or portions of the 
+software, acknowledge within their advertising materials that such products contain 
+software developed by UC Berkeley and its contributors. 
+
+Specifically, the provision reads: 
+
+      * 3. All advertising materials mentioning features or use of this software
+      *    must display the following acknowledgement:
+      *    This product includes software developed by the University of
+      *    California, Berkeley and its contributors.
+
+Effective immediately, licensees and distributors are no longer required to include 
+the acknowledgement within advertising materials. Accordingly, the foregoing paragraph 
+of those BSD Unix files containing it is hereby deleted in its entirety. 
+
+William Hoskins
+Director, Office of Technology Licensing
+University of California, Berkeley " 
diff --git a/reactos/apps/utils/net/finger/err.c b/reactos/apps/utils/net/finger/err.c
new file mode 100644 (file)
index 0000000..5f96668
--- /dev/null
@@ -0,0 +1,180 @@
+/*-
+ * Copyright (c) 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)err.c      8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include "err.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+extern char *__progname;               /* Program name, from crt0. */
+
+void
+#ifdef __STDC__
+err(int eval, const char *fmt, ...)
+#else
+err(eval, fmt, va_alist)
+       int eval;
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       verr(eval, fmt, ap);
+       va_end(ap);
+}
+
+void
+verr(int eval, const char *fmt, va_list ap)
+{
+       int sverrno;
+
+       sverrno = errno;
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
+       exit(eval);
+}
+
+void
+#if __STDC__
+errx(int eval, const char *fmt, ...)
+#else
+errx(eval, fmt, va_alist)
+       int eval;
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       verrx(eval, fmt, ap);
+       va_end(ap);
+}
+
+void
+verrx(int eval, const char *fmt, va_list ap)
+{
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
+       (void)fprintf(stderr, "\n");
+       exit(eval);
+}
+
+void
+#if __STDC__
+warn(const char *fmt, ...)
+#else
+warn(fmt, va_alist)
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       vwarn(fmt, ap);
+       va_end(ap);
+}
+
+void
+vwarn(fmt, ap)
+       const char *fmt;
+       va_list ap;
+{
+       int sverrno;
+
+       sverrno = errno;
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
+}
+
+void
+#ifdef __STDC__
+warnx(const char *fmt, ...)
+#else
+warnx(fmt, va_alist)
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#ifdef __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       vwarnx(fmt, ap);
+       va_end(ap);
+}
+
+void
+vwarnx(fmt, ap)
+       const char *fmt;
+       va_list ap;
+{
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
+       (void)fprintf(stderr, "\n");
+}
diff --git a/reactos/apps/utils/net/finger/err.h b/reactos/apps/utils/net/finger/err.h
new file mode 100644 (file)
index 0000000..bbc7397
--- /dev/null
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)err.h       8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ERR_H_
+#define        _ERR_H_
+
+/*
+ * Don't use va_list in the err/warn prototypes.   Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes.  It's unreasonable
+ * for utilities to have to include one of them to include err.h, so we get
+ * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ */
+/*#include <machine/ansi.h>*/
+/*#include <sys/cdefs.h>*/
+#include "various.h"
+#include <stdarg.h>
+
+void   err __P((int, const char *, ...));
+void   verr __P((int, const char *, va_list));
+void   errx __P((int, const char *, ...));
+void   verrx __P((int, const char *, va_list));
+void           warn __P((const char *, ...));
+void           vwarn __P((const char *, va_list));
+void           warnx __P((const char *, ...));
+void           vwarnx __P((const char *, va_list));
+
+#endif /* !_ERR_H_ */
diff --git a/reactos/apps/utils/net/finger/finger.c b/reactos/apps/utils/net/finger/finger.c
new file mode 100644 (file)
index 0000000..125f878
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * 8/2/97 - Ted Felix <tfelix@fred.net>
+ *          Ported to Win32 from 4.4BSD-LITE2 at wcarchive.
+ *          NT Workstation already has finger, and it runs fine under
+ *          Win95.  Thought I'd do this anyways since not everyone has
+ *          access to NT.
+ *          Had to remove local handling.       Otherwise, same as whois.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1989, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)finger.c   8.5 (Berkeley) 5/4/95";
+#endif /* not lint */
+
+/*
+ * Finger prints out information about users.  It is not portable since
+ * certain fields (e.g. the full user name, office, and phone numbers) are
+ * extracted from the gecos field of the passwd file which other UNIXes
+ * may not have or may use for other things.
+ *
+ * There are currently two output formats; the short format is one line
+ * per user and displays login name, tty, login time, real name, idle time,
+ * and office location/phone number.  The long format gives the same
+ * information (in a more legible format) as well as home directory, shell,
+ * mail info, and .plan/.project files.
+ */
+
+#include <winsock2.h>
+#include "err.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "unistd.h"
+
+#include "various.h"
+#include "getopt.h"
+
+char *__progname;
+
+time_t now;
+int lflag, mflag, pplan, sflag;
+
+static void userlist(int, char **);
+void usage();
+void netfinger(char *);
+
+int
+main(int argc, char **argv)
+{
+       int ch;
+
+       while ((ch = getopt(argc, argv, "lmps")) != EOF)
+               switch(ch) {
+               case 'l':
+                       lflag = 1;              /* long format */
+                       break;
+               case 'm':
+                       mflag = 1;              /* force exact match of names */
+                       break;
+               case 'p':
+                       pplan = 1;              /* don't show .plan/.project */
+                       break;
+               case 's':
+                       sflag = 1;              /* short format */
+                       break;
+               case '?':
+               default:
+                       (void)fprintf(stderr,
+                           "usage: finger [-lmps] login [...]\n");
+                       exit(1);
+               }
+       argc -= optind;
+       argv += optind;
+
+       (void)time(&now);
+       if (!*argv) {
+               usage();
+       } else {
+               userlist(argc, argv);
+               /*
+                * Assign explicit "large" format if names given and -s not
+                * explicitly stated.  Force the -l AFTER we get names so any
+                * remote finger attempts specified won't be mishandled.
+                */
+               if (!sflag)
+                       lflag = 1;      /* if -s not explicit, force -l */
+       }
+       return 0;
+}
+
+
+static void
+userlist(int argc, char **argv)
+{
+       int *used;
+       char **ap, **nargv, **np, **p;
+       WORD wVersionRequested;
+       WSADATA wsaData;
+       int iErr;
+
+
+       if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL ||
+           (used = calloc(argc, sizeof(int))) == NULL)
+               err(1, NULL);
+
+       /* Pull out all network requests into nargv. */
+       for (ap = p = argv, np = nargv; *p; ++p)
+               if (index(*p, '@'))
+                       *np++ = *p;
+               else
+                       *ap++ = *p;
+
+       *np++ = NULL;
+       *ap++ = NULL;
+
+       /* If there are local requests */
+       if (*argv)
+       {
+               fprintf(stderr, "Warning: Can't do local finger\n");
+       }
+
+       /* Start winsock */ 
+       wVersionRequested = MAKEWORD( 1, 1 );
+       iErr = WSAStartup( wVersionRequested, &wsaData );
+       if ( iErr != 0 ) 
+       {
+               /* Tell the user that we couldn't find a usable */
+               /* WinSock DLL.                                  */
+               fprintf(stderr, "WSAStartup failed\n");
+               return;
+       }
+
+       /* Handle network requests. */
+       for (p = nargv; *p;)
+               netfinger(*p++);
+
+       /* Bring down winsock */
+       WSACleanup();
+       exit(0);
+}
+
+void usage()
+{
+       (void)fprintf(stderr,
+                     "usage: finger [-lmps] login [...]\n");
+       exit(1);
+}
+
diff --git a/reactos/apps/utils/net/finger/finger.rc b/reactos/apps/utils/net/finger/finger.rc
new file mode 100644 (file)
index 0000000..4ad72fc
--- /dev/null
@@ -0,0 +1,6 @@
+/* $Id: finger.rc,v 1.1 2004/11/21 22:26:13 chorns Exp $ */
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS TCP/IPv4 Win32 finger\0"
+#define REACTOS_STR_INTERNAL_NAME      "finger\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "finger.exe\0"
+#include <reactos/version.rc>
diff --git a/reactos/apps/utils/net/finger/getopt.c b/reactos/apps/utils/net/finger/getopt.c
new file mode 100644 (file)
index 0000000..eacc86e
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Fri Jun 13 10:39:00 1997, tfelix@fred.net:
+ *     Ported to Win32, changed index/rindex to strchr/strrchr
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c   4.13 (Berkeley) 2/23/91";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * get option letter from argument vector
+ */
+int    opterr = 1,             /* if error message should be printed */
+       optind = 1,             /* index into parent argv vector */
+       optopt;                 /* character checked for validity */
+char   *optarg;                /* argument associated with option */
+
+#define        BADCH   (int)'?'
+#define        EMSG    ""
+
+int
+getopt(int nargc, char * const *nargv, const char *ostr)
+{
+       static char *place = EMSG;              /* option letter processing */
+       register char *oli;                     /* option letter list index */
+       char *p;
+
+       if (!*place) {                          /* update scanning pointer */
+               if (optind >= nargc || *(place = nargv[optind]) != '-') {
+                       place = EMSG;
+                       return(EOF);
+               }
+               if (place[1] && *++place == '-') {      /* found "--" */
+                       ++optind;
+                       place = EMSG;
+                       return(EOF);
+               }
+       }                                       /* option letter okay? */
+       if ((optopt = (int)*place++) == (int)':' ||
+           !(oli = strchr(ostr, optopt))) {
+               /*
+                * if the user didn't specify '-' as an option,
+                * assume it means EOF.
+                */
+               if (optopt == (int)'-')
+                       return(EOF);
+               if (!*place)
+                       ++optind;
+               if (opterr) {
+                       if (!(p = strrchr(*nargv, '/')))
+                               p = *nargv;
+                       else
+                               ++p;
+                       (void)fprintf(stderr, "%s: illegal option -- %c\n",
+                           p, optopt);
+               }
+               return(BADCH);
+       }
+       if (*++oli != ':') {                    /* don't need argument */
+               optarg = NULL;
+               if (!*place)
+                       ++optind;
+       }
+       else {                                  /* need an argument */
+               if (*place)                     /* no white space */
+                       optarg = place;
+               else if (nargc <= ++optind) {   /* no arg */
+                       place = EMSG;
+                       if (!(p = strrchr(*nargv, '/')))
+                               p = *nargv;
+                       else
+                               ++p;
+                       if (opterr)
+                               (void)fprintf(stderr,
+                                   "%s: option requires an argument -- %c\n",
+                                   p, optopt);
+                       return(BADCH);
+               }
+               else                            /* white space */
+                       optarg = nargv[optind];
+               place = EMSG;
+               ++optind;
+       }
+       return(optopt);                         /* dump back option letter */
+}
diff --git a/reactos/apps/utils/net/finger/getopt.h b/reactos/apps/utils/net/finger/getopt.h
new file mode 100644 (file)
index 0000000..bad5c84
--- /dev/null
@@ -0,0 +1,7 @@
+/* getopt.h */
+
+extern char *optarg;
+extern int optind;
+
+int
+getopt(int nargc, char * const *nargv, const char *ostr);
diff --git a/reactos/apps/utils/net/finger/makefile b/reactos/apps/utils/net/finger/makefile
new file mode 100644 (file)
index 0000000..703dca6
--- /dev/null
@@ -0,0 +1,22 @@
+PATH_TO_TOP = ../../../..
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = finger
+
+TARGET_SDKLIBS = ws2_32.a
+
+TARGET_CFLAGS = -D__USE_W32_SOCKETS
+
+TARGET_OBJECTS = $(TARGET_NAME).o \
+  err.o \
+  getopt.o \
+  net.o 
+
+TARGET_GCCLIBS = iberty
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
diff --git a/reactos/apps/utils/net/finger/net.c b/reactos/apps/utils/net/finger/net.c
new file mode 100644 (file)
index 0000000..3cf4bdb
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)net.c      8.4 (Berkeley) 4/28/95";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <winsock2.h>
+#include "unistd.h"
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "various.h"
+
+void
+netfinger(char *name)
+{
+       extern int lflag;
+       char c, lastc;
+       struct in_addr defaddr;
+       struct hostent *hp, def;
+       struct servent *sp;
+       struct sockaddr_in sin;
+       int s;
+       char *alist[1], *host;
+
+       /* If this is a local request */
+       if (!(host = rindex(name, '@')))
+               return;
+
+       *host++ = NULL;
+       if (isdigit(*host) && (defaddr.s_addr = inet_addr(host)) != -1) {
+               def.h_name = host;
+               def.h_addr_list = alist;
+               def.h_addr = (char *)&defaddr;
+               def.h_length = sizeof(struct in_addr);
+               def.h_addrtype = AF_INET;
+               def.h_aliases = 0;
+               hp = &def;
+       } else if (!(hp = gethostbyname(host))) {
+               (void)fprintf(stderr,
+                   "finger: unknown host: %s\n", host);
+               return;
+       }
+       if (!(sp = getservbyname("finger", "tcp"))) {
+               (void)fprintf(stderr, "finger: tcp/finger: unknown service\n");
+               return;
+       }
+       sin.sin_family = hp->h_addrtype;
+       bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
+       sin.sin_port = sp->s_port;
+       if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
+               perror("finger: socket");
+               return;
+       }
+
+       /* have network connection; identify the host connected with */
+       (void)printf("[%s]\n", hp->h_name);
+       if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+               fprintf(stderr, "finger: connect rc = %d", WSAGetLastError());
+               (void)close(s);
+               return;
+       }
+
+       /* -l flag for remote fingerd  */
+       if (lflag)
+               send(s, "/W ", 3, 0);
+       /* send the name followed by <CR><LF> */
+       send(s, name, strlen(name), 0);
+       send(s, "\r\n", 2, 0);
+
+       /*
+        * Read from the remote system; once we're connected, we assume some
+        * data.  If none arrives, we hang until the user interrupts.
+        *
+        * If we see a <CR> or a <CR> with the high bit set, treat it as
+        * a newline; if followed by a newline character, only output one
+        * newline.
+        *
+        * Otherwise, all high bits are stripped; if it isn't printable and
+        * it isn't a space, we can simply set the 7th bit.  Every ASCII
+        * character with bit 7 set is printable.
+        */ 
+       lastc = 0;
+       while (recv(s, &c, 1, 0) == 1) {
+               c &= 0x7f;
+               if (c == 0x0d) {
+                       if (lastc == '\r')      /* ^M^M - skip dupes */
+                               continue;
+                       c = '\n';
+                       lastc = '\r';
+               } else {
+                       if (!isprint(c) && !isspace(c))
+                               c |= 0x40;
+                       if (lastc != '\r' || c != '\n')
+                               lastc = c;
+                       else {
+                               lastc = '\n';
+                               continue;
+                       }
+               }
+               putchar(c);
+       }
+       if (lastc != '\n')
+               putchar('\n');
+       putchar('\n');
+}
diff --git a/reactos/apps/utils/net/finger/various.h b/reactos/apps/utils/net/finger/various.h
new file mode 100644 (file)
index 0000000..5ddbd8c
--- /dev/null
@@ -0,0 +1,34 @@
+// Various things you need when porting BSD and GNU utilities to
+// Win32.
+
+#ifndef VARIOUS_H
+#define VARIOUS_H
+
+
+typedef float f4byte_t;
+typedef double f8byte_t;
+typedef long uid_t;  // SunOS 5.5
+
+#define __P(x) x
+
+/* utmp.h */
+#define UT_LINESIZE 8
+#define UT_HOSTSIZE 16
+
+/* stat.h */
+#define  S_ISREG(mode)   (((mode)&0xF000) == 0x8000)
+#define  S_ISDIR(mode)   (((mode)&0xF000) == 0x4000)
+
+#undef MIN //take care of windows default
+#undef MAX //take care of windows default
+#define MIN(a, b) ((a) <= (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+#define bcopy(s1, s2, n)  memmove(s2, s1, n)
+#define bcmp(s1, s2, n)  (memcmp(s1, s2, n) != 0)
+#define bzero(s, n)  memset(s, 0, n)
+
+#define index(s, c)  strchr(s, c)
+#define rindex(s, c)  strrchr(s, c)
+
+#endif
diff --git a/reactos/apps/utils/net/ipconfig/.cvsignore b/reactos/apps/utils/net/ipconfig/.cvsignore
new file mode 100644 (file)
index 0000000..954ada3
--- /dev/null
@@ -0,0 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.map
diff --git a/reactos/apps/utils/net/ipconfig/ipconfig.c b/reactos/apps/utils/net/ipconfig/ipconfig.c
new file mode 100644 (file)
index 0000000..c2a6563
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * ipconfig - display IP stack parameters.
+ *
+ * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
+ *
+ * Robert Dickenson <robd@reactos.org>, August 15, 2002.
+ */
+#include <stdio.h>
+#include <windows.h>
+#include <tchar.h>
+#include <time.h>
+
+#include <iptypes.h>
+#include <ipexport.h>
+#include <iphlpapi.h>
+
+#ifdef _DEBUG
+#include "trace.h"
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+/* imported from iphlpapi.dll
+
+GetAdapterOrderMap
+GetInterfaceInfo
+GetIpStatsFromStack
+NhGetInterfaceNameFromGuid
+NhpAllocateAndGetInterfaceInfoFromStack
+
+ */
+
+static TCHAR* GetNodeTypeName(int nNodeType)
+{
+    switch (nNodeType) {
+    case 0:  return _T("zero");
+    case 1:  return _T("one");
+    case 2:  return _T("two");
+    case 3:  return _T("three");
+    case 4:  return _T("mixed");
+    default: return _T("unknown");
+    }
+}
+
+static void ShowNetworkFixedInfo()
+{
+    FIXED_INFO* pFixedInfo = NULL;
+    ULONG OutBufLen = 0;
+    DWORD result;
+
+    result = GetNetworkParams(NULL, &OutBufLen);
+    if (result == ERROR_BUFFER_OVERFLOW) {
+        pFixedInfo = (FIXED_INFO*)malloc(OutBufLen);
+        if (!pFixedInfo) {
+            _tprintf(_T("ERROR: failed to allocate 0x%08X bytes of memory\n"), OutBufLen);
+            return;
+        }
+    } else {
+        _tprintf(_T("ERROR: GetNetworkParams() failed to report required buffer size.\n"));
+        return;
+    }
+
+    result = GetNetworkParams(pFixedInfo, &OutBufLen);
+    if (result == ERROR_SUCCESS) {
+        IP_ADDR_STRING* pIPAddr;
+
+             printf("\tHostName. . . . . . . . . . . : %s\n",  pFixedInfo->HostName);
+             printf("\tDomainName. . . . . . . . . . : %s\n",  pFixedInfo->DomainName);
+//
+             printf("\tDNS Servers . . . . . . . . . : %s\n",  pFixedInfo->DnsServerList.IpAddress.String);
+             pIPAddr = pFixedInfo->DnsServerList.Next;
+             while (pIPAddr) {
+                 printf("\t\t\t\t      : %s\n",  pIPAddr->IpAddress.String);
+                 pIPAddr = pIPAddr->Next;
+             }
+//
+        _tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo->NodeType, GetNodeTypeName(pFixedInfo->NodeType));
+             printf("\tScopeId . . . . . . . . . . . : %s\n",  pFixedInfo->ScopeId);
+        _tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo->EnableRouting ? _T("yes") : _T("no"));
+        _tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo->EnableProxy ? _T("yes") : _T("no"));
+        _tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
+        _tprintf(_T("\n"));
+        //_tprintf(_T("\n"),);
+        //_tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
+
+//      _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
+
+    } else {
+        switch (result) {
+        case ERROR_BUFFER_OVERFLOW:
+            _tprintf(_T("The buffer size indicated by the pOutBufLen parameter is too small to hold the adapter information. The pOutBufLen parameter points to the required size\n"));
+            break;
+        case ERROR_INVALID_PARAMETER:
+            _tprintf(_T("The pOutBufLen parameter is NULL, or the calling process does not have read/write access to the memory pointed to by pOutBufLen, or the calling process does not have write access to the memory pointed to by the pAdapterInfo parameter\n"));
+            break;
+        case ERROR_NO_DATA:
+            _tprintf(_T("No adapter information exists for the local computer\n"));
+            break;
+        case ERROR_NOT_SUPPORTED:
+            _tprintf(_T("This function is not supported on the operating system in use on the local system\n"));
+            break;
+        default:
+            _tprintf(_T("0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result);
+            break;
+        }
+    }
+}
+
+static void ShowNetworkInterfaces()
+{
+    IP_INTERFACE_INFO* pIfTable = NULL;
+    DWORD result;
+    DWORD dwNumIf;
+    DWORD dwOutBufLen = 0;
+
+    if ((result = GetNumberOfInterfaces(&dwNumIf)) != NO_ERROR) {
+        _tprintf(_T("GetNumberOfInterfaces() failed with code 0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result);
+        return;
+    } else {
+        _tprintf(_T("GetNumberOfInterfaces() returned %d\n"), dwNumIf);
+    }
+
+    result = GetInterfaceInfo(pIfTable, &dwOutBufLen);
+//    dwOutBufLen = sizeof(IP_INTERFACE_INFO) + dwNumIf * sizeof(IP_ADAPTER_INDEX_MAP);
+//    _tprintf(_T("GetNumberOfInterfaces() returned %d, dwOutBufLen %d\n"), dwNumIf, dwOutBufLen);
+//    _tprintf(_T("sizeof(IP_INTERFACE_INFO) %d, sizeof(IP_ADAPTER_INDEX_MAP) %d\n"), sizeof(IP_INTERFACE_INFO), sizeof(IP_ADAPTER_INDEX_MAP));
+
+    pIfTable = (IP_INTERFACE_INFO*)malloc(dwOutBufLen);
+    if (!pIfTable) {
+        _tprintf(_T("ERROR: failed to allocate 0x%08X bytes of memory\n"), dwOutBufLen);
+        return;
+    }
+/*
+typedef struct _IP_ADAPTER_INDEX_MAP {
+  ULONG Index;                     // adapter index 
+  WCHAR Name[MAX_ADAPTER_NAME];    // name of the adapter 
+} IP_ADAPTER_INDEX_MAP, * PIP_ADAPTER_INDEX_MAP;
+
+typedef struct _IP_INTERFACE_INFO {
+  LONG NumAdapters;                 // number of adapters in array 
+  IP_ADAPTER_INDEX_MAP Adapter[1];  // adapter indices and names 
+} IP_INTERFACE_INFO,*PIP_INTERFACE_INFO;
+ */
+    result = GetInterfaceInfo(pIfTable, &dwOutBufLen);
+    if (result == NO_ERROR) {
+        int i;
+        _tprintf(_T("GetInterfaceInfo() returned with %d adaptor entries\n"), pIfTable->NumAdapters);
+        for (i = 0; i < pIfTable->NumAdapters; i++) {
+           wprintf(L"[%d] %s\n", i + 1, pIfTable->Adapter[i].Name);
+           //wprintf(L"[%d] %s\n", pIfTable->Adapter[i].Index, pIfTable->Adapter[i].Name);
+
+//  \DEVICE\TCPIP_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357}
+//  \DEVICE\TCPIP_{BD445697-0945-4591-AE7F-2AB0F383CA87}
+//  \DEVICE\TCPIP_{6D87DC08-6BC5-4E78-AB5F-18CAB785CFFE}
+
+//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357}
+        }
+    } else {
+        switch (result) {
+        case ERROR_INVALID_PARAMETER:
+            _tprintf(_T("The dwOutBufLen parameter is NULL, or GetInterfaceInterface is unable to write to the memory pointed to by the dwOutBufLen parameter\n"));
+            break;
+        case ERROR_INSUFFICIENT_BUFFER:
+            _tprintf(_T("The buffer pointed to by the pIfTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the dwOutBufLen parameter\n"));
+            _tprintf(_T("\tdwOutBufLen: %d\n"), dwOutBufLen);
+            break;
+        case ERROR_NOT_SUPPORTED:
+            _tprintf(_T("This function is not supported on the operating system in use on the local system\n"));
+            break;
+        default:
+            _tprintf(_T("0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result);
+            break;
+        }
+    }
+    free(pIfTable);
+}
+
+/*
+typedef struct _IP_ADAPTER_INFO {
+  struct _IP_ADAPTER_INFO* Next;
+  DWORD ComboIndex;
+  char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
+1  char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
+  UINT AddressLength;
+2  BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
+  DWORD Index;
+  UINT Type;
+3  UINT DhcpEnabled;
+5  PIP_ADDR_STRING CurrentIpAddress;
+  IP_ADDR_STRING IpAddressList;
+7  IP_ADDR_STRING GatewayList;
+8  IP_ADDR_STRING DhcpServer;
+  BOOL HaveWins;
+  IP_ADDR_STRING PrimaryWinsServer;
+  IP_ADDR_STRING SecondaryWinsServer;
+a  time_t LeaseObtained;
+b  time_t LeaseExpires; 
+} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
+ */
+/*
+Ethernet adapter VMware Virtual Ethernet Adapter (Network Address Translation (NAT) for VMnet8):
+
+        Connection-specific DNS Suffix  . :
+1        Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter (Network Address Translation (NAT) for VMnet8)
+2        Physical Address. . . . . . . . . : 00-50-56-C0-00-08
+3        DHCP Enabled. . . . . . . . . . . : Yes
+        Autoconfiguration Enabled . . . . : Yes
+5        IP Address. . . . . . . . . . . . : 192.168.136.1
+        Subnet Mask . . . . . . . . . . . : 255.255.255.0
+7        Default Gateway . . . . . . . . . :
+8        DHCP Server . . . . . . . . . . . : 192.168.136.254
+        DNS Servers . . . . . . . . . . . :
+a        Lease Obtained. . . . . . . . . . : Monday, 30 December 2002 5:56:53 PM
+b        Lease Expires . . . . . . . . . . : Monday, 30 December 2002 6:26:53 PM
+ */
+static void ShowAdapterInfo()
+{
+    IP_ADAPTER_INFO* pAdaptorInfo;
+    ULONG ulOutBufLen;
+    DWORD dwRetVal;
+
+    _tprintf(_T("\nAdaptor Information\t\n"));
+    pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, sizeof(IP_ADAPTER_INFO));
+    ulOutBufLen = sizeof(IP_ADAPTER_INFO);
+
+    if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
+        GlobalFree(pAdaptorInfo);
+        pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
+    }
+    if (dwRetVal = GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
+        _tprintf(_T("Call to GetAdaptersInfo failed. Return Value: %08x\n"), dwRetVal);
+    } else {
+        while (pAdaptorInfo) {
+            printf("  AdapterName: %s\n", pAdaptorInfo->AdapterName);
+            printf("  Description: %s\n", pAdaptorInfo->Description);
+            pAdaptorInfo = pAdaptorInfo->Next;
+        }
+    }
+}
+
+const char szUsage[] = { "USAGE:\n" \
+    "   ipconfig [/? | /all | /release [adapter] | /renew [adapter]\n" \
+    "            | /flushdns | /registerdns\n" \
+    "            | /showclassid adapter\n" \
+    "            | /showclassid adapter\n" \
+    "            | /setclassid adapter [classidtoset] ]\n" \
+    "\n" \
+    "adapter    Full name or pattern with '*' and '?' to 'match',\n" \
+    "           * matches any character, ? matches one character.\n" \
+    "   Options\n" \
+    "       /?           Display this help message.\n" \
+    "       /all         Display full configuration information.\n" \
+    "       /release     Release the IP address for the specified adapter.\n" \
+    "       /renew       Renew the IP address for the specified adapter.\n" \
+    "       /flushdns    Purges the DNS Resolver cache.\n" \
+    "       /registerdns Refreshes all DHCP leases and re-registers DNS names\n" \
+    "       /displaydns  Display the contents of the DNS Resolver Cache.\n" \
+    "       /showclassid Displays all the dhcp class IDs allowed for adapter.\n" \
+    "       /setclassid  Modifies the dhcp class id.\n" \
+    "\n" \
+    "The default is to display only the IP address, subnet mask and\n" \
+    "default gateway for each adapter bound to TCP/IP.\n"
+};
+/*
+    "\n" \
+    "For Release and Renew, if no adapter name is specified, then the IP address\n" \
+    "leases for all adapters bound to TCP/IP will be released or renewed.\n" \
+    "\n" \
+    "For SetClassID, if no class id is specified, then the classid is removed.\n" \
+    "\n" \
+    "Examples:\n" \
+    "    > ipconfig                       ... Show information.\n" \
+    "    > ipconfig /all                  ... Show detailed information\n" \
+    "    > ipconfig /renew                ... renew all adapaters\n" \
+    "    > ipconfig /renew EL*            ... renew adapters named EL....\n" \
+    "    > ipconfig /release *ELINK?21*   ... release all matching adapters,\n" \
+                                         eg. ELINK-21, myELELINKi21adapter.\n"
+ */
+
+static void usage(void)
+{
+       fputs(szUsage, stderr);
+}
+
+
+int main(int argc, char *argv[])
+{
+    // 10.0.0.100    // As of build 0.0.20 this is hardcoded in the ip stack
+
+    if (argc > 1) {
+        usage();
+        return 1;
+    }
+    _tprintf(_T("ReactOS IP Configuration\n"));
+    ShowNetworkFixedInfo();
+    ShowNetworkInterfaces();
+    ShowAdapterInfo();
+       return 0;
+}
diff --git a/reactos/apps/utils/net/ipconfig/ipconfig.rc b/reactos/apps/utils/net/ipconfig/ipconfig.rc
new file mode 100644 (file)
index 0000000..6dbcb81
--- /dev/null
@@ -0,0 +1,6 @@
+/* $Id: ipconfig.rc,v 1.1 2004/11/21 22:26:13 chorns Exp $ */
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS TCP/IPv4 Win32 ipconfig\0"
+#define REACTOS_STR_INTERNAL_NAME      "ipconfig\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "ipconfig.exe\0"
+#include <reactos/version.rc>
diff --git a/reactos/apps/utils/net/ipconfig/makefile b/reactos/apps/utils/net/ipconfig/makefile
new file mode 100644 (file)
index 0000000..a593685
--- /dev/null
@@ -0,0 +1,17 @@
+PATH_TO_TOP = ../../../..
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = ipconfig
+
+TARGET_CFLAGS = -D__USE_W32API
+
+TARGET_SDKLIBS = user32.a iphlpapi.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
diff --git a/reactos/apps/utils/net/ipconfig/trace.c b/reactos/apps/utils/net/ipconfig/trace.c
new file mode 100644 (file)
index 0000000..d225a22
--- /dev/null
@@ -0,0 +1,53 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#include <stdio.h> 
+#include <stdarg.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <tchar.h>
+#include "trace.h"
+
+
+#ifdef _DEBUG
+
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+
+void _DebugBreak(void)
+{
+    DebugBreak();
+}
+
+void Trace(TCHAR* lpszFormat, ...)
+{
+    va_list args;
+    int nBuf;
+    TCHAR szBuffer[512];
+
+    va_start(args, lpszFormat);
+    nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
+    OutputDebugString(szBuffer);
+    // was there an error? was the expanded string too long?
+    //ASSERT(nBuf >= 0);
+    va_end(args);
+}
+
+void Assert(void* assert, TCHAR* file, int line, void* msg)
+{
+    if (msg == NULL) {
+        printf("ASSERT -- %s occured on line %u of file %s.\n",
+               assert, line, file);
+    } else {
+        printf("ASSERT -- %s occured on line %u of file %s: Message = %s.\n",
+               assert, line, file, msg);
+    }
+}
+
+#else
+
+void Trace(TCHAR* lpszFormat, ...) { };
+void Assert(void* assert, TCHAR* file, int line, void* msg) { };
+
+#endif //_DEBUG
+/////////////////////////////////////////////////////////////////////////////
diff --git a/reactos/apps/utils/net/ipconfig/trace.h b/reactos/apps/utils/net/ipconfig/trace.h
new file mode 100644 (file)
index 0000000..7f3318e
--- /dev/null
@@ -0,0 +1,61 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#ifndef __TRACE_H__
+#define __TRACE_H__
+
+#ifdef _DEBUG
+
+#ifdef _X86_
+#define BreakPoint()        _asm { int 3h }
+#else
+#define BreakPoint()        _DebugBreak()
+#endif
+
+#ifndef ASSERT
+#define ASSERT(exp)                                 \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, NULL);     \
+        BreakPoint();                               \
+    }                                               \
+}                                                   \
+
+#define ASSERTMSG(exp, msg)                         \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, msg);      \
+        BreakPoint();                               \
+    }                                               \
+}
+#endif
+
+//=============================================================================
+//  MACRO: TRACE()
+//=============================================================================
+
+#define TRACE  Trace
+
+
+#else   // _DEBUG
+
+//=============================================================================
+//  Define away MACRO's ASSERT() and TRACE() in non debug builds
+//=============================================================================
+
+#ifndef ASSERT
+#define ASSERT(exp)
+#define ASSERTMSG(exp, msg)
+#endif
+
+#define TRACE 0 ? (void)0 : Trace
+
+#endif // !_DEBUG
+
+
+void Assert(void* assert, TCHAR* file, int line, void* msg);
+void Trace(TCHAR* lpszFormat, ...);
+
+
+#endif // __TRACE_H__
+/////////////////////////////////////////////////////////////////////////////
diff --git a/reactos/apps/utils/net/netstat/.cvsignore b/reactos/apps/utils/net/netstat/.cvsignore
new file mode 100644 (file)
index 0000000..954ada3
--- /dev/null
@@ -0,0 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.map
diff --git a/reactos/apps/utils/net/netstat/makefile b/reactos/apps/utils/net/netstat/makefile
new file mode 100644 (file)
index 0000000..9e986d7
--- /dev/null
@@ -0,0 +1,20 @@
+PATH_TO_TOP = ../../../..
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = netstat
+
+TARGET_CFLAGS = \
+       -D__USE_W32API \
+       -D_WIN32_IE=0x600 \
+       -D_WIN32_WINNT=0x501 
+
+TARGET_SDKLIBS = user32.a snmpapi.a iphlpapi.a ws2_32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
diff --git a/reactos/apps/utils/net/netstat/netstat.c b/reactos/apps/utils/net/netstat/netstat.c
new file mode 100644 (file)
index 0000000..666c94c
--- /dev/null
@@ -0,0 +1,518 @@
+/*
+ * netstat - display IP stack statistics.
+ *
+ * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
+ *
+ * Robert Dickenson <robd@reactos.org>, August 15, 2002.
+ */
+
+// Extensive reference made and use of source to netstatp by:
+// Copyright (C) 1998-2002 Mark Russinovich
+// www.sysinternals.com
+
+#define ANY_SIZE 1
+
+#include <windows.h>
+#include <winsock.h>
+#include <tchar.h>
+#include <stdio.h>
+#include <time.h>
+
+#include <iptypes.h>
+#include <ipexport.h>
+#include <tlhelp32.h>
+#include <iphlpapi.h>
+#include <snmp.h>
+
+#include "trace.h"
+#include "resource.h"
+
+
+#define MAX_RESLEN 4000
+
+//
+// Possible TCP endpoint states
+//
+static char TcpState[][32] = {
+       "???",
+       "CLOSED",
+       "LISTENING",
+       "SYN_SENT",
+       "SYN_RCVD",
+       "ESTABLISHED",
+       "FIN_WAIT1",
+       "FIN_WAIT2",
+       "CLOSE_WAIT",
+       "CLOSING",
+       "LAST_ACK",
+       "TIME_WAIT",
+       "DELETE_TCB"
+};
+
+VOID PrintError(DWORD ErrorCode)
+{
+       LPVOID lpMsgBuf;
+       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                                 NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                                 (LPTSTR)&lpMsgBuf, 0, NULL);
+       printf("%s\n", lpMsgBuf);
+       LocalFree(lpMsgBuf);
+}
+
+static void ShowTcpStatistics()
+{
+    MIB_TCPSTATS TcpStatsMIB;
+    GetTcpStatistics(&TcpStatsMIB);
+
+    _tprintf(_T("TCP/IP Statistics\t\n"));
+    _tprintf(_T("  time-out algorithm:\t\t%d\n"), TcpStatsMIB.dwRtoAlgorithm);    
+    _tprintf(_T("  minimum time-out:\t\t%d\n"), TcpStatsMIB.dwRtoMin);         
+    _tprintf(_T("  maximum time-out:\t\t%d\n"), TcpStatsMIB.dwRtoMax);         
+    _tprintf(_T("  maximum connections:\t\t%d\n"), TcpStatsMIB.dwMaxConn);        
+    _tprintf(_T("  active opens:\t\t\t%d\n"), TcpStatsMIB.dwActiveOpens);    
+    _tprintf(_T("  passive opens:\t\t\t%d\n"), TcpStatsMIB.dwPassiveOpens);   
+    _tprintf(_T("  failed attempts:\t\t%d\n"), TcpStatsMIB.dwAttemptFails);   
+    _tprintf(_T("  established connections reset:\t%d\n"), TcpStatsMIB.dwEstabResets);    
+    _tprintf(_T("  established connections:\t%d\n"), TcpStatsMIB.dwCurrEstab);      
+    _tprintf(_T("  segments received:\t\t%d\n"), TcpStatsMIB.dwInSegs);         
+    _tprintf(_T("  segment sent:\t\t\t%d\n"), TcpStatsMIB.dwOutSegs);        
+    _tprintf(_T("  segments retransmitted:\t\t%d\n"), TcpStatsMIB.dwRetransSegs);    
+    _tprintf(_T("  incoming errors:\t\t%d\n"), TcpStatsMIB.dwInErrs);         
+    _tprintf(_T("  outgoing resets:\t\t%d\n"), TcpStatsMIB.dwOutRsts);        
+    _tprintf(_T("  cumulative connections:\t\t%d\n"), TcpStatsMIB.dwNumConns);       
+}
+
+static void ShowUdpStatistics()
+{
+    MIB_UDPSTATS UDPStatsMIB;
+    GetUdpStatistics(&UDPStatsMIB);
+
+    _tprintf(_T("UDP Statistics\t\n"));
+    _tprintf(_T("  received datagrams:\t\t\t%d\n"), UDPStatsMIB.dwInDatagrams);
+    _tprintf(_T("  datagrams for which no port exists:\t%d\n"), UDPStatsMIB.dwNoPorts); 
+    _tprintf(_T("  errors on received datagrams:\t\t%d\n"), UDPStatsMIB.dwInErrors);
+    _tprintf(_T("  sent datagrams:\t\t\t\t%d\n"), UDPStatsMIB.dwOutDatagrams);
+    _tprintf(_T("  number of entries in listener table:\t%d\n"), UDPStatsMIB.dwNumAddrs);
+}
+
+static void ShowIpStatistics()
+{
+    MIB_IPSTATS IPStatsMIB;
+    GetIpStatistics(&IPStatsMIB);
+
+    _tprintf(_T("IP Statistics\t\n"));
+    _tprintf(_T("  IP forwarding enabled or disabled:\t%d\n"), IPStatsMIB.dwForwarding);      
+    _tprintf(_T("  default time-to-live:\t\t\t%d\n"), IPStatsMIB.dwDefaultTTL);      
+    _tprintf(_T("  datagrams received:\t\t\t%d\n"), IPStatsMIB.dwInReceives);      
+    _tprintf(_T("  received header errors:\t\t\t%d\n"), IPStatsMIB.dwInHdrErrors);     
+    _tprintf(_T("  received address errors:\t\t%d\n"), IPStatsMIB.dwInAddrErrors);    
+    _tprintf(_T("  datagrams forwarded:\t\t\t%d\n"), IPStatsMIB.dwForwDatagrams);   
+    _tprintf(_T("  datagrams with unknown protocol:\t%d\n"), IPStatsMIB.dwInUnknownProtos); 
+    _tprintf(_T("  received datagrams discarded:\t\t%d\n"), IPStatsMIB.dwInDiscards);      
+    _tprintf(_T("  received datagrams delivered:\t\t%d\n"), IPStatsMIB.dwInDelivers);      
+    _tprintf(_T("  sent datagrams discarded:\t\t%d\n"), IPStatsMIB.dwOutDiscards);     
+    _tprintf(_T("  datagrams for which no route exists:\t%d\n"), IPStatsMIB.dwOutNoRoutes);     
+    _tprintf(_T("  datagrams for which frags didn't arrive:%d\n"), IPStatsMIB.dwReasmTimeout);    
+    _tprintf(_T("  datagrams requiring reassembly:\t\t%d\n"), IPStatsMIB.dwReasmReqds);      
+    _tprintf(_T("  successful reassemblies:\t\t%d\n"), IPStatsMIB.dwReasmOks);        
+    _tprintf(_T("  failed reassemblies:\t\t\t%d\n"), IPStatsMIB.dwReasmFails);      
+    _tprintf(_T("  successful fragmentations:\t\t%d\n"), IPStatsMIB.dwFragOks);         
+    _tprintf(_T("  failed fragmentations:\t\t\t%d\n"), IPStatsMIB.dwFragFails);       
+    _tprintf(_T("  datagrams fragmented:\t\t\t%d\n"), IPStatsMIB.dwFragCreates);     
+    _tprintf(_T("  number of interfaces on computer:\t%d\n"), IPStatsMIB.dwNumIf);           
+    _tprintf(_T("  number of IP address on computer:\t%d\n"), IPStatsMIB.dwNumAddr);         
+    _tprintf(_T("  number of routes in routing table:\t%d\n"), IPStatsMIB.dwNumRoutes);       
+}
+
+static void ShowNetworkParams()
+{
+    FIXED_INFO* FixedInfo;
+    IP_ADDR_STRING* pIPAddr;
+    ULONG ulOutBufLen;
+    DWORD dwRetVal;
+
+    _tprintf(_T("Network Parameters\t\n"));
+
+    FixedInfo = (FIXED_INFO*)GlobalAlloc(GPTR, sizeof(FIXED_INFO));
+    ulOutBufLen = sizeof(FIXED_INFO);
+    if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &ulOutBufLen)) {
+        GlobalFree(FixedInfo);
+        FixedInfo =(FIXED_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
+    }
+    if (dwRetVal = GetNetworkParams(FixedInfo, &ulOutBufLen)) {
+        _tprintf(_T("Call to GetNetworkParams failed. Return Value: %08x\n"), dwRetVal);
+    } else {
+        printf("  Host Name: %s", FixedInfo->HostName);
+        printf("\n  Domain Name: %s", FixedInfo->DomainName);
+        printf("\n  DNS Servers:\t%s\n", FixedInfo->DnsServerList.IpAddress.String);
+        pIPAddr = FixedInfo->DnsServerList.Next;
+        while (pIPAddr) {
+            printf("\t\t\t%s\n", pIPAddr->IpAddress.String);
+            pIPAddr = pIPAddr->Next;
+        }
+    }
+}
+
+static void ShowAdapterInfo()
+{
+    IP_ADAPTER_INFO* pAdaptorInfo;
+    ULONG ulOutBufLen;
+    DWORD dwRetVal;
+
+    _tprintf(_T("\nAdaptor Information\t\n"));
+    pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, sizeof(IP_ADAPTER_INFO));
+    ulOutBufLen = sizeof(IP_ADAPTER_INFO);
+
+    if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
+        GlobalFree(pAdaptorInfo);
+        pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
+    }
+    if (dwRetVal = GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
+        _tprintf(_T("Call to GetAdaptersInfo failed. Return Value: %08x\n"), dwRetVal);
+    } else {
+        while (pAdaptorInfo) {
+            printf("  AdapterName: %s\n", pAdaptorInfo->AdapterName);
+            printf("  Description: %s\n", pAdaptorInfo->Description);
+            pAdaptorInfo = pAdaptorInfo->Next;
+        }
+    }
+}
+
+/*
+typedef struct {
+    UINT idLength;
+    UINT* ids;
+} AsnObjectIdentifier;
+
+VOID SnmpUtilPrintAsnAny(AsnAny* pAny);  // pointer to value to print
+VOID SnmpUtilPrintOid(AsnObjectIdentifier* Oid);  // object identifier to print
+
+ */
+void test_snmp(void)
+{
+    int nBytes = 500;
+    BYTE* pCache;
+
+    pCache = (BYTE*)SnmpUtilMemAlloc(nBytes);
+    if (pCache != NULL) {
+        AsnObjectIdentifier* pOidSrc = NULL;
+        AsnObjectIdentifier AsnObId;
+        if (SnmpUtilOidCpy(&AsnObId, pOidSrc)) {
+            //
+            //
+            //
+            SnmpUtilOidFree(&AsnObId);
+        }
+        SnmpUtilMemFree(pCache);
+    } else {
+        _tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n"));
+    }
+}
+
+// Maximum string lengths for ASCII ip address and port names
+//
+#define HOSTNAMELEN            256
+#define PORTNAMELEN            256
+#define ADDRESSLEN             HOSTNAMELEN+PORTNAMELEN
+
+//
+// Our option flags
+//
+#define FLAG_SHOW_ALL_ENDPOINTS    1
+#define FLAG_SHOW_ETH_STATS        2
+#define FLAG_SHOW_NUMBERS          3
+#define FLAG_SHOW_PROT_CONNECTIONS 4
+#define FLAG_SHOW_ROUTE_TABLE      5
+#define FLAG_SHOW_PROT_STATS       6
+#define FLAG_SHOW_INTERVAL         7
+
+
+// Undocumented extended information structures available only on XP and higher
+
+typedef struct {
+  DWORD dwState;        // state of the connection
+  DWORD dwLocalAddr;    // address on local computer
+  DWORD dwLocalPort;    // port number on local computer
+  DWORD dwRemoteAddr;   // address on remote computer
+  DWORD dwRemotePort;   // port number on remote computer
+  DWORD        dwProcessId;
+} MIB_TCPEXROW, *PMIB_TCPEXROW;
+
+typedef struct {
+       DWORD dwNumEntries;
+       MIB_TCPEXROW table[ANY_SIZE];
+} MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
+
+typedef struct {
+  DWORD   dwLocalAddr;    // address on local computer
+  DWORD   dwLocalPort;    // port number on local computer
+  DWORD          dwProcessId;
+} MIB_UDPEXROW, *PMIB_UDPEXROW;
+
+typedef struct {
+       DWORD dwNumEntries;
+       MIB_UDPEXROW table[ANY_SIZE];
+} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
+
+
+//
+// GetPortName
+//
+// Translate port numbers into their text equivalent if there is one
+//
+PCHAR
+GetPortName(DWORD Flags, UINT port, PCHAR proto, PCHAR name, int namelen) 
+{
+       struct servent *psrvent;
+
+       if (Flags & FLAG_SHOW_NUMBERS) {
+               sprintf(name, "%d", htons((WORD)port));
+               return name;
+       } 
+       // Try to translate to a name
+       if (psrvent = getservbyport(port, proto)) {
+               strcpy(name, psrvent->s_name );
+       } else {
+               sprintf(name, "%d", htons((WORD)port));
+       }               
+       return name;
+}
+
+
+//
+// GetIpHostName
+//
+// Translate IP addresses into their name-resolved form if possible.
+//
+PCHAR
+GetIpHostName(DWORD Flags, BOOL local, UINT ipaddr, PCHAR name, int namelen) 
+{
+//     struct hostent *phostent;
+       UINT nipaddr;
+
+       // Does the user want raw numbers?
+       nipaddr = htonl(ipaddr);
+       if (Flags & FLAG_SHOW_NUMBERS ) {
+               sprintf(name, "%d.%d.%d.%d", 
+                       (nipaddr >> 24) & 0xFF,
+                       (nipaddr >> 16) & 0xFF,
+                       (nipaddr >> 8) & 0xFF,
+                       (nipaddr) & 0xFF);
+               return name;
+       }
+
+       name[0] = _T('\0');
+
+       // Try to translate to a name
+       if (!ipaddr) {
+               if (!local) {
+                       sprintf(name, "%d.%d.%d.%d", 
+                               (nipaddr >> 24) & 0xFF,
+                               (nipaddr >> 16) & 0xFF,
+                               (nipaddr >> 8) & 0xFF,
+                               (nipaddr) & 0xFF);
+               } else {
+                       //gethostname(name, namelen);
+               }
+       } else if (ipaddr == 0x0100007f) {
+               if (local) {
+                       //gethostname(name, namelen);
+               } else {
+                       strcpy(name, "localhost");
+               }
+//     } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
+//             strcpy(name, phostent->h_name);
+       } else {
+#if 0
+        int i1, i2, i3, i4;
+
+               i1 = (nipaddr >> 24) & 0x000000FF;
+               i2 = (nipaddr >> 16) & 0x000000FF;
+               i3 = (nipaddr >> 8) & 0x000000FF;
+               i4 = (nipaddr) & 0x000000FF;
+
+               i1 = 10;
+               i2 = 20;
+               i3 = 30;
+               i4 = 40;
+
+               sprintf(name, "%d.%d.%d.%d", i1,i2,i3,i4);
+#else
+               sprintf(name, "%d.%d.%d.%d", 
+                       ((nipaddr >> 24) & 0x000000FF),
+                       ((nipaddr >> 16) & 0x000000FF),
+                       ((nipaddr >> 8) & 0x000000FF),
+                       ((nipaddr) & 0x000000FF));
+#endif
+       }
+       return name;
+}
+
+BOOLEAN usage(void)
+{
+    TCHAR buffer[MAX_RESLEN];
+
+    int length = LoadString(GetModuleHandle(NULL), IDS_APP_USAGE, buffer, sizeof(buffer)/sizeof(buffer[0]));
+       _fputts(buffer, stderr);
+       return FALSE;
+}
+
+//
+// GetOptions
+// 
+// Parses the command line arguments.
+//
+BOOLEAN 
+GetOptions(int argc, char *argv[], PDWORD pFlags)
+{
+       int             i, j;
+       BOOLEAN skipArgument;
+
+       *pFlags = 0;
+       for (i = 1; i < argc; i++) {
+               skipArgument = FALSE;
+               switch (argv[i][0]) {
+               case '-':
+               case '/':
+                       j = 1;
+                       while (argv[i][j]) {
+                               switch (toupper(argv[i][j])) {
+                               case 'A':
+                                       *pFlags |= FLAG_SHOW_ALL_ENDPOINTS;
+                                       break;
+                               case 'E':
+                                       *pFlags |= FLAG_SHOW_ETH_STATS;
+                                       break;
+                               case 'N':
+                                       *pFlags |= FLAG_SHOW_NUMBERS;
+                                       break;
+                               case 'P':
+                                       *pFlags |= FLAG_SHOW_PROT_CONNECTIONS;
+                                       break;
+                               case 'R':
+                                       *pFlags |= FLAG_SHOW_ROUTE_TABLE;
+                                       break;
+                               case 'S':
+                                       *pFlags |= FLAG_SHOW_PROT_STATS;
+                                       break;
+                               default:
+                                       return usage();
+                               }
+                               if (skipArgument) break;
+                               j++;
+                       }
+                       break;
+               case 'i':
+                       *pFlags |= FLAG_SHOW_INTERVAL;
+                       break;
+               default:
+                       return usage();
+               }
+       }
+       return TRUE;
+}
+
+#if 1
+
+       CHAR localname[HOSTNAMELEN], remotename[HOSTNAMELEN];
+       CHAR remoteport[PORTNAMELEN], localport[PORTNAMELEN];
+       CHAR localaddr[ADDRESSLEN], remoteaddr[ADDRESSLEN];
+
+int main(int argc, char *argv[])
+{
+       PMIB_TCPTABLE tcpTable;
+       PMIB_UDPTABLE udpTable;
+       DWORD error, dwSize;
+       DWORD i, flags;
+
+       // Get options
+       if (!GetOptions(argc, argv, &flags)) {
+               return -1;
+    } else {
+               // Get the table of TCP endpoints
+               dwSize = 0;
+               error = GetTcpTable(NULL, &dwSize, TRUE);
+               if (error != ERROR_INSUFFICIENT_BUFFER) {
+                       printf("Failed to snapshot TCP endpoints.\n");
+                       PrintError(error);
+                       return -1;
+               }
+               tcpTable = (PMIB_TCPTABLE)malloc(dwSize);
+               error = GetTcpTable(tcpTable, &dwSize, TRUE );
+               if (error) {
+                       printf("Failed to snapshot TCP endpoints table.\n");
+                       PrintError(error);
+                       return -1;
+               }
+
+               // Get the table of UDP endpoints
+               dwSize = 0;
+               error = GetUdpTable(NULL, &dwSize, TRUE);
+               if (error != ERROR_INSUFFICIENT_BUFFER) {
+                       printf("Failed to snapshot UDP endpoints.\n");
+                       PrintError(error);
+                       return -1;
+               }
+               udpTable = (PMIB_UDPTABLE)malloc(dwSize);
+               error = GetUdpTable(udpTable, &dwSize, TRUE);
+               if (error) {
+                       printf("Failed to snapshot UDP endpoints table.\n");
+                       PrintError(error);
+                       return -1;
+               }
+
+               // Dump the TCP table
+               for (i = 0; i < tcpTable->dwNumEntries; i++) {
+                       if (flags & FLAG_SHOW_ALL_ENDPOINTS ||
+                               tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB) {
+                               sprintf(localaddr, "%s:%s", 
+                                       GetIpHostName(flags, TRUE, tcpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN), 
+                                   GetPortName(flags, tcpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
+                               sprintf(remoteaddr, "%s:%s",
+                                       GetIpHostName(flags, FALSE, tcpTable->table[i].dwRemoteAddr, remotename, HOSTNAMELEN), 
+                                   tcpTable->table[i].dwRemoteAddr ? 
+                                       GetPortName(flags, tcpTable->table[i].dwRemotePort, "tcp", remoteport, PORTNAMELEN):
+                                       "0");
+                               printf("%4s\tState:   %s\n", "[TCP]", TcpState[tcpTable->table[i].dwState]);
+                               printf("       Local:   %s\n       Remote:  %s\n", localaddr, remoteaddr);
+                       }
+               }
+               // Dump the UDP table
+               if (flags & FLAG_SHOW_ALL_ENDPOINTS) {
+                       for (i = 0; i < udpTable->dwNumEntries; i++) {
+                               sprintf(localaddr, "%s:%s", 
+                                       GetIpHostName(flags, TRUE, udpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN), 
+                                       GetPortName(flags, udpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
+                               printf("%4s", "[UDP]");
+                               printf("       Local:   %s\n       Remote:  %s\n", localaddr, "*.*.*.*:*");
+                       }
+               }
+       }       
+       printf("\n");
+       return 0;
+}
+
+#else
+
+int main(int argc, char *argv[])
+{
+    if (argc > 1) {
+        usage();
+        return 1;
+    }
+
+    _tprintf(_T("\nActive Connections\n\n")\
+             _T("  Proto  Local Address          Foreign Address        State\n\n"));
+    test_snmp();
+
+    ShowTcpStatistics();
+    ShowUdpStatistics();
+    ShowIpStatistics();
+    ShowNetworkParams();
+    ShowAdapterInfo();
+
+       return 0;
+}
+
+#endif
diff --git a/reactos/apps/utils/net/netstat/netstat.rc b/reactos/apps/utils/net/netstat/netstat.rc
new file mode 100644 (file)
index 0000000..ce5c878
--- /dev/null
@@ -0,0 +1,40 @@
+/* $Id: netstat.rc,v 1.1 2004/11/21 22:26:14 chorns Exp $ */
+
+#include <windows.h>
+#include "resource.h"
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS TCP/IPv4 Win32 netstat\0"
+#define REACTOS_STR_INTERNAL_NAME      "netstat\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "netstat.exe\0"
+#include <reactos/version.rc>
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+#ifdef __GNUC__
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_APP_TITLE           "ReactOS netstat"
+    IDS_APP_USAGE           "\n"\
+                            "Displays current TCP/IP protocol statistics and network connections.\n\n"\
+                            "NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]\n\n"\
+                            "  -a            Displays all connections and listening ports.\n"\
+                            "  -e            Displays Ethernet statistics. May be combined with -s\n"\
+                            "  -n            Displays address and port numbers in numeric form.\n"\
+                            "  -p proto      Shows connections for protocol 'proto' TCP or UDP.\n"\
+                            "                If used with the -s option to display\n"\
+                            "                per-protocol statistics, 'proto' may be TCP, UDP, or IP.\n"\
+                            "  -r            Displays the current routing table.\n"\
+                            "  -s            Displays per-protocol statistics. Statistics are shown for\n"\
+                            "                TCP, UDP and IP by default; use -p option to display\n"\
+                            "                information about a subset of the protocols only.\n"\
+                            "  interval      Redisplays selected statistics every 'interval' seconds.\n"\
+                            "                Press CTRL+C to stop redisplaying. By default netstat will\n"\
+                            "                print the current information only once.\n"
+END
+#endif
+
diff --git a/reactos/apps/utils/net/netstat/resource.h b/reactos/apps/utils/net/netstat/resource.h
new file mode 100644 (file)
index 0000000..16f0156
--- /dev/null
@@ -0,0 +1,7 @@
+
+#define RES_FIRST_INDEX 1
+#define RES_LAST_INDEX  25
+
+#define IDS_APP_TITLE  100
+#define IDS_APP_USAGE  101
+
diff --git a/reactos/apps/utils/net/netstat/trace.c b/reactos/apps/utils/net/netstat/trace.c
new file mode 100644 (file)
index 0000000..d225a22
--- /dev/null
@@ -0,0 +1,53 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#include <stdio.h> 
+#include <stdarg.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <tchar.h>
+#include "trace.h"
+
+
+#ifdef _DEBUG
+
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+
+void _DebugBreak(void)
+{
+    DebugBreak();
+}
+
+void Trace(TCHAR* lpszFormat, ...)
+{
+    va_list args;
+    int nBuf;
+    TCHAR szBuffer[512];
+
+    va_start(args, lpszFormat);
+    nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
+    OutputDebugString(szBuffer);
+    // was there an error? was the expanded string too long?
+    //ASSERT(nBuf >= 0);
+    va_end(args);
+}
+
+void Assert(void* assert, TCHAR* file, int line, void* msg)
+{
+    if (msg == NULL) {
+        printf("ASSERT -- %s occured on line %u of file %s.\n",
+               assert, line, file);
+    } else {
+        printf("ASSERT -- %s occured on line %u of file %s: Message = %s.\n",
+               assert, line, file, msg);
+    }
+}
+
+#else
+
+void Trace(TCHAR* lpszFormat, ...) { };
+void Assert(void* assert, TCHAR* file, int line, void* msg) { };
+
+#endif //_DEBUG
+/////////////////////////////////////////////////////////////////////////////
diff --git a/reactos/apps/utils/net/netstat/trace.h b/reactos/apps/utils/net/netstat/trace.h
new file mode 100644 (file)
index 0000000..7f3318e
--- /dev/null
@@ -0,0 +1,61 @@
+/////////////////////////////////////////////////////////////////////////////
+// Diagnostic Trace
+//
+#ifndef __TRACE_H__
+#define __TRACE_H__
+
+#ifdef _DEBUG
+
+#ifdef _X86_
+#define BreakPoint()        _asm { int 3h }
+#else
+#define BreakPoint()        _DebugBreak()
+#endif
+
+#ifndef ASSERT
+#define ASSERT(exp)                                 \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, NULL);     \
+        BreakPoint();                               \
+    }                                               \
+}                                                   \
+
+#define ASSERTMSG(exp, msg)                         \
+{                                                   \
+    if (!(exp)) {                                   \
+        Assert(#exp, __FILE__, __LINE__, msg);      \
+        BreakPoint();                               \
+    }                                               \
+}
+#endif
+
+//=============================================================================
+//  MACRO: TRACE()
+//=============================================================================
+
+#define TRACE  Trace
+
+
+#else   // _DEBUG
+
+//=============================================================================
+//  Define away MACRO's ASSERT() and TRACE() in non debug builds
+//=============================================================================
+
+#ifndef ASSERT
+#define ASSERT(exp)
+#define ASSERTMSG(exp, msg)
+#endif
+
+#define TRACE 0 ? (void)0 : Trace
+
+#endif // !_DEBUG
+
+
+void Assert(void* assert, TCHAR* file, int line, void* msg);
+void Trace(TCHAR* lpszFormat, ...);
+
+
+#endif // __TRACE_H__
+/////////////////////////////////////////////////////////////////////////////
index d63774a..954ada3 100644 (file)
@@ -1,6 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
 *.o
 *.d
-*.exe
 *.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
 *.sym
+*.plg
+*.bak
 *.map
diff --git a/reactos/apps/utils/net/ping/makefile b/reactos/apps/utils/net/ping/makefile
new file mode 100644 (file)
index 0000000..acbfc25
--- /dev/null
@@ -0,0 +1,17 @@
+PATH_TO_TOP = ../../../..
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = ping
+
+TARGET_CFLAGS = -D__USE_W32_SOCKETS
+
+TARGET_SDKLIBS = ws2_32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
diff --git a/reactos/apps/utils/net/ping/ping.c b/reactos/apps/utils/net/ping/ping.c
new file mode 100644 (file)
index 0000000..e349e9b
--- /dev/null
@@ -0,0 +1,633 @@
+/* $Id: ping.c,v 1.7 2004/11/21 22:26:14 chorns Exp $
+ *
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS ping utility
+ * FILE:        apps/net/ping/ping.c
+ * PURPOSE:     Network test utility
+ * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
+ * REVISIONS:
+ *   CSH  01/09/2000 Created
+ */
+//#include <windows.h>
+#include <winsock2.h>
+#include <tchar.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#ifndef _MSC_VER
+
+//#define DBG
+
+/* FIXME: Where should this be? */
+#ifdef CopyMemory
+#undef CopyMemory
+#endif
+#define CopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length);
+
+/* Should be in the header files somewhere (exported by ntdll.dll) */
+long atol(const char *str);
+
+#ifndef __int64
+typedef long long __int64;
+#endif
+
+char * _i64toa(__int64 value, char *string, int radix);
+
+#endif
+
+
+/* General ICMP constants */
+#define ICMP_MINSIZE           8               /* Minimum ICMP packet size */
+#define ICMP_MAXSIZE           65535   /* Maximum ICMP packet size */
+
+/* ICMP message types */
+#define ICMPMSG_ECHOREQUEST    8               /* ICMP ECHO request message */
+#define ICMPMSG_ECHOREPLY      0               /* ICMP ECHO reply message */
+
+#pragma pack(4)
+
+/* IPv4 header structure */
+typedef struct _IPv4_HEADER {
+       unsigned char   IHL:4;
+       unsigned char   Version:4;
+       unsigned char   TOS;
+       unsigned short  Length;
+       unsigned short  Id;
+       unsigned short  FragFlags;
+       unsigned char   TTL;
+       unsigned char   Protocol;
+       unsigned short  Checksum;
+       unsigned int    SrcAddress;
+       unsigned int    DstAddress;
+} IPv4_HEADER, *PIPv4_HEADER;
+
+/* ICMP echo request/reply header structure */
+typedef struct _ICMP_HEADER {
+       unsigned char   Type;
+       unsigned char   Code;
+       unsigned short  Checksum;
+       unsigned short  Id;
+       unsigned short  SeqNum;
+} ICMP_HEADER, *PICMP_HEADER;
+
+typedef struct _ICMP_ECHO_PACKET {
+       ICMP_HEADER   Icmp;
+       LARGE_INTEGER Timestamp;
+} ICMP_ECHO_PACKET, *PICMP_ECHO_PACKET;
+
+#pragma pack(1)
+
+BOOL                InvalidOption;
+BOOL                NeverStop;
+BOOL                ResolveAddresses;
+UINT                PingCount;
+UINT                DataSize;   /* ICMP echo request data size */
+BOOL                DontFragment;
+ULONG               TTLValue;
+ULONG               TOSValue;
+ULONG               Timeout;
+CHAR                TargetName[256];
+SOCKET              IcmpSock;
+SOCKADDR_IN         Target;
+LPSTR               TargetIP;
+FD_SET              Fds;
+TIMEVAL             Timeval;
+UINT                CurrentSeqNum;
+UINT                SentCount;
+UINT                LostCount;
+BOOL                MinRTTSet;
+LARGE_INTEGER       MinRTT;     /* Minimum round trip time in microseconds */
+LARGE_INTEGER       MaxRTT;
+LARGE_INTEGER       SumRTT;
+LARGE_INTEGER       AvgRTT;
+LARGE_INTEGER       TicksPerMs; /* Ticks per millisecond */
+LARGE_INTEGER       TicksPerUs; /* Ticks per microsecond */
+BOOL                UsePerformanceCounter;
+
+
+/* Display the contents of a buffer */
+VOID DisplayBuffer(
+    PVOID Buffer,
+    DWORD Size)
+{
+    UINT i;
+    PCHAR p;
+
+    printf("Buffer (0x%X)  Size (0x%X).\n", Buffer, Size);
+
+    p = (PCHAR)Buffer;
+    for (i = 0; i < Size; i++) {
+      if (i % 16 == 0) {
+        printf("\n");
+      }
+      printf("%02X ", (p[i]) & 0xFF);
+    }
+}
+
+/* Display usage information on screen */
+VOID Usage(VOID)
+{
+       printf("\nUsage: ping [-t] [-n count] [-l size] [-w timeout] destination-host\n\n");
+       printf("Options:\n");
+       printf("    -t             Ping the specified host until stopped.\n");
+       printf("                   To stop - type Control-C.\n");
+       printf("    -n count       Number of echo requests to send.\n");
+       printf("    -l size        Send buffer size.\n");
+       printf("    -w timeout     Timeout in milliseconds to wait for each reply.\n\n");
+}
+
+/* Reset configuration to default values */
+VOID Reset(VOID)
+{
+    LARGE_INTEGER PerformanceCounterFrequency;
+
+    NeverStop             = FALSE;
+    ResolveAddresses      = FALSE;
+    PingCount             = 4;
+    DataSize              = 32;
+    DontFragment          = FALSE;
+    TTLValue              = 128;
+    TOSValue              = 0;
+    Timeout               = 1000;
+    UsePerformanceCounter = QueryPerformanceFrequency(&PerformanceCounterFrequency);
+
+    if (UsePerformanceCounter) {
+        /* Performance counters may return incorrect results on some multiprocessor
+           platforms so we restrict execution on the first processor. This may fail
+           on Windows NT so we fall back to GetCurrentTick() for timing */
+        if (SetThreadAffinityMask (GetCurrentThread(), 1) == 0) {
+            UsePerformanceCounter = FALSE;
+        }
+
+        /* Convert frequency to ticks per millisecond */
+        TicksPerMs.QuadPart = PerformanceCounterFrequency.QuadPart / 1000;
+        /* And to ticks per microsecond */
+        TicksPerUs.QuadPart = PerformanceCounterFrequency.QuadPart / 1000000;
+    }
+    if (!UsePerformanceCounter) {
+        /* 1 tick per millisecond for GetCurrentTick() */
+        TicksPerMs.QuadPart = 1;
+        /* GetCurrentTick() cannot handle microseconds */
+        TicksPerUs.QuadPart = 1;
+    }
+}
+
+/* Return ULONG in a string */
+ULONG GetULONG(LPSTR String)
+{
+    UINT i, Length;
+    ULONG Value;
+
+    i = 0;
+    Length = strlen(String);
+    while ((i < Length) && ((String[i] < '0') || (String[i] > '9'))) i++;
+    if ((i >= Length) || ((String[i] < '0') || (String[i] > '9'))) {
+        InvalidOption = TRUE;
+        return 0;
+    }
+    Value = (ULONG)atol(&String[i]);
+
+    return Value;
+}
+
+/* Return ULONG in a string. Try next paramter if not successful */
+ULONG GetULONG2(LPSTR String1, LPSTR String2, PINT i)
+{
+    ULONG Value;
+
+    Value = GetULONG(String1);
+    if (InvalidOption) {
+        InvalidOption = FALSE;
+        if (String2[0] != '-') {
+            Value = GetULONG(String2);
+            if (!InvalidOption)
+                *i += 1;
+        }
+    }
+
+    return Value;
+}
+
+/* Parse command line parameters */
+BOOL ParseCmdline(int argc, char* argv[])
+{
+    INT i;
+    BOOL ShowUsage;
+    BOOL FoundTarget;
+//#if 1
+//    lstrcpy(TargetName, "127.0.0.1");
+//    PingCount = 1;
+//    return TRUE;
+//#endif
+    if (argc < 2) {
+        ShowUsage = TRUE;
+    } else {
+        ShowUsage = FALSE;
+    }
+    FoundTarget = FALSE;
+    InvalidOption = FALSE;
+
+    for (i = 1; i < argc; i++) {
+        if (argv[i][0] == '-') {
+            switch (argv[i][1]) {
+            case 't': NeverStop = TRUE; break;
+            case 'a': ResolveAddresses = TRUE; break;
+            case 'n': PingCount = GetULONG2(&argv[i][2], argv[i + 1], &i); break;
+            case 'l':
+                DataSize = GetULONG2(&argv[i][2], argv[i + 1], &i);
+                if ((DataSize < 0) || (DataSize > ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET))) {
+                    printf("Bad value for option -l, valid range is from 0 to %d.\n",
+                        ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET));
+                    return FALSE;
+                }
+                break;
+            case 'f': DontFragment = TRUE; break;
+            case 'i': TTLValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break;
+            case 'v': TOSValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break;
+            case 'w': Timeout  = GetULONG2(&argv[i][2], argv[i + 1], &i); break;
+            default:
+                printf("Bad option %s.\n", argv[i]);
+                Usage();
+                return FALSE;
+            }
+            if (InvalidOption) {
+                printf("Bad option format %s.\n", argv[i]);
+                return FALSE;
+            }
+        } else {
+            if (FoundTarget) {
+                printf("Bad parameter %s.\n", argv[i]);
+                return FALSE;
+            } else {
+                               lstrcpy(TargetName, argv[i]);
+                FoundTarget = TRUE;
+            }
+        }
+    }
+
+    if ((!ShowUsage) && (!FoundTarget)) {
+        printf("Name or IP address of destination host must be specified.\n");
+        return FALSE;
+    }
+
+    if (ShowUsage) {
+        Usage();
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/* Calculate checksum of data */
+WORD Checksum(PUSHORT data, UINT size)
+{
+    ULONG sum = 0;
+
+    while (size > 1) {
+        sum  += *data++;
+        size -= sizeof(USHORT);
+    }
+
+    if (size)
+        sum += *(UCHAR*)data;
+
+    sum = (sum >> 16) + (sum & 0xFFFF);
+    sum += (sum >> 16);
+
+    return (USHORT)(~sum);
+}
+
+/* Prepare to ping target */
+BOOL Setup(VOID)
+{
+    WORD     wVersionRequested;
+    WSADATA  WsaData;
+    INT             Status;
+    ULONG    Addr;
+    PHOSTENT phe;
+
+    wVersionRequested = MAKEWORD(2, 2);
+    Status = WSAStartup(wVersionRequested, &WsaData);
+    if (Status != 0) {
+        printf("Could not initialize winsock dll.\n"); 
+        return FALSE;
+    }
+
+    IcmpSock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0, 0);
+    if (IcmpSock == INVALID_SOCKET) {
+        printf("Could not create socket (#%d).\n", WSAGetLastError());
+        return FALSE;
+    }
+
+    ZeroMemory(&Target, sizeof(Target));
+    phe = NULL;
+    Addr = inet_addr(TargetName);
+    if (Addr == INADDR_NONE) {
+        phe = gethostbyname(TargetName);
+        if (phe == NULL) {
+            printf("Unknown host %s.\n", TargetName);
+            return FALSE;
+        } 
+    }
+       
+    if (phe != NULL) {
+        CopyMemory(&Target.sin_addr, phe->h_addr_list, phe->h_length);
+    } else {
+        Target.sin_addr.s_addr = Addr;
+    }
+
+    if (phe != NULL) {
+               Target.sin_family = phe->h_addrtype;
+    } else {
+        Target.sin_family = AF_INET;
+    }
+       
+    TargetIP           = inet_ntoa(Target.sin_addr);
+    CurrentSeqNum      = 0;
+    SentCount          = 0;
+       LostCount               = 0;
+    MinRTT.QuadPart = 0;
+    MaxRTT.QuadPart = 0;
+    SumRTT.QuadPart = 0;
+    MinRTTSet       = FALSE;
+    return TRUE;
+}
+
+/* Close socket */
+VOID Cleanup(VOID)
+{
+    if (IcmpSock != INVALID_SOCKET)
+        closesocket(IcmpSock);
+
+    WSACleanup();
+}
+
+VOID QueryTime(PLARGE_INTEGER Time)
+{
+    if (UsePerformanceCounter) {
+        if (QueryPerformanceCounter(Time) == 0) {
+            /* This should not happen, but we fall
+               back to GetCurrentTick() if it does */
+            Time->u.LowPart  = (ULONG)GetTickCount();
+            Time->u.HighPart = 0;
+
+            /* 1 tick per millisecond for GetCurrentTick() */
+            TicksPerMs.QuadPart = 1;
+            /* GetCurrentTick() cannot handle microseconds */
+            TicksPerUs.QuadPart = 1;
+
+            UsePerformanceCounter = FALSE;
+        }
+    } else {
+        Time->u.LowPart  = (ULONG)GetTickCount();
+        Time->u.HighPart = 0;
+    }
+}
+
+VOID TimeToMsString(LPSTR String, LARGE_INTEGER Time)
+{
+    UINT          i, Length;
+    CHAR          Convstr[40];
+    LARGE_INTEGER LargeTime;
+
+    LargeTime.QuadPart = Time.QuadPart / TicksPerMs.QuadPart;
+    _i64toa(LargeTime.QuadPart, Convstr, 10);
+       strcpy(String, Convstr);
+    strcat(String, ",");
+
+    LargeTime.QuadPart = (Time.QuadPart % TicksPerMs.QuadPart) / TicksPerUs.QuadPart;
+    _i64toa(LargeTime.QuadPart, Convstr, 10);
+    Length = strlen(Convstr);
+    if (Length < 4) {
+        for (i = 0; i < 4 - Length; i++)
+            strcat(String, "0");
+    }
+
+    strcat(String, Convstr);
+    strcat(String, "ms");
+}
+
+/* Locate the ICMP data and print it. Returns TRUE if the packet was good,
+   FALSE if not */
+BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from)
+{
+    PIPv4_HEADER      IpHeader;
+    PICMP_ECHO_PACKET Icmp;
+       UINT              IphLength;
+    CHAR              Time[100];
+    LARGE_INTEGER     RelativeTime;
+    LARGE_INTEGER     LargeTime;
+
+    IpHeader = (PIPv4_HEADER)buffer;
+
+    IphLength = IpHeader->IHL * 4;
+
+    if (size  < IphLength + ICMP_MINSIZE) {
+#ifdef DBG
+        printf("Bad size (0x%X < 0x%X)\n", size, IphLength + ICMP_MINSIZE);
+#endif /* DBG */
+        return FALSE;
+    }
+
+    Icmp = (PICMP_ECHO_PACKET)(buffer + IphLength);
+
+    if (Icmp->Icmp.Type != ICMPMSG_ECHOREPLY) {
+#ifdef DBG
+        printf("Bad ICMP type (0x%X should be 0x%X)\n", Icmp->Icmp.Type, ICMPMSG_ECHOREPLY);
+#endif /* DBG */
+        return FALSE;
+    }
+
+    if (Icmp->Icmp.Id != (USHORT)GetCurrentProcessId()) {
+#ifdef DBG
+        printf("Bad ICMP id (0x%X should be 0x%X)\n", Icmp->Icmp.Id, (USHORT)GetCurrentProcessId());
+#endif /* DBG */
+        return FALSE;
+    }
+
+    QueryTime(&LargeTime);
+
+    RelativeTime.QuadPart = (LargeTime.QuadPart - Icmp->Timestamp.QuadPart);
+
+    TimeToMsString(Time, RelativeTime);
+
+    printf("Reply from %s: bytes=%d time=%s TTL=%d\n", inet_ntoa(from->sin_addr), 
+      size - IphLength - sizeof(ICMP_ECHO_PACKET), Time, IpHeader->TTL);
+    if (RelativeTime.QuadPart < MinRTT.QuadPart) {
+                 MinRTT.QuadPart = RelativeTime.QuadPart;
+      MinRTTSet = TRUE;
+    }
+         if (RelativeTime.QuadPart > MaxRTT.QuadPart)
+             MaxRTT.QuadPart = RelativeTime.QuadPart;
+    SumRTT.QuadPart += RelativeTime.QuadPart;
+
+       return TRUE;
+}
+
+/* Send and receive one ping */
+BOOL Ping(VOID)
+{
+    INT                 Status;
+    SOCKADDR            From;
+    UINT                Length;
+    PVOID               Buffer;
+    UINT                Size;
+    PICMP_ECHO_PACKET   Packet;
+
+    /* Account for extra space for IP header when packet is received */
+    Size   = DataSize + 128;
+    Buffer = GlobalAlloc(0, Size);
+    if (!Buffer) {
+        printf("Not enough free resources available.\n");
+        return FALSE;
+    }
+
+    ZeroMemory(Buffer, Size);
+    Packet = (PICMP_ECHO_PACKET)Buffer;
+
+    /* Assemble ICMP echo request packet */
+    Packet->Icmp.Type     = ICMPMSG_ECHOREQUEST;
+    Packet->Icmp.Code     = 0;
+    Packet->Icmp.Id          = (USHORT)GetCurrentProcessId();
+    Packet->Icmp.SeqNum   = (USHORT)CurrentSeqNum;
+    Packet->Icmp.Checksum = 0;
+
+    /* Timestamp is part of data area */
+    QueryTime(&Packet->Timestamp);
+
+    CopyMemory(Buffer, &Packet->Icmp, sizeof(ICMP_ECHO_PACKET) + DataSize);
+    /* Calculate checksum for ICMP header and data area */
+    Packet->Icmp.Checksum = Checksum((PUSHORT)&Packet->Icmp, sizeof(ICMP_ECHO_PACKET) + DataSize);
+
+    CurrentSeqNum++;
+
+       /* Send ICMP echo request */
+
+    FD_ZERO(&Fds);
+    FD_SET(IcmpSock, &Fds);
+    Timeval.tv_sec  = Timeout / 1000;
+    Timeval.tv_usec = Timeout % 1000;
+    Status = select(0, NULL, &Fds, NULL, &Timeval);
+    if ((Status != SOCKET_ERROR) && (Status != 0)) {
+
+#ifdef DBG
+        printf("Sending packet\n");
+        DisplayBuffer(Buffer, sizeof(ICMP_ECHO_PACKET) + DataSize);
+        printf("\n");
+#endif /* DBG */
+
+        Status = sendto(IcmpSock, Buffer, sizeof(ICMP_ECHO_PACKET) + DataSize,
+            0, (SOCKADDR*)&Target, sizeof(Target));
+        SentCount++;
+    }
+    if (Status == SOCKET_ERROR) {
+        if (WSAGetLastError() == WSAEHOSTUNREACH) {
+            printf("Destination host unreachable.\n");
+        } else {
+            printf("Could not transmit data (%d).\n", WSAGetLastError());
+        }
+        GlobalFree(Buffer);
+        return FALSE;
+    }
+
+    /* Expect to receive ICMP echo reply */
+    FD_ZERO(&Fds);
+    FD_SET(IcmpSock, &Fds);
+    Timeval.tv_sec  = Timeout / 1000;
+    Timeval.tv_usec = Timeout % 1000;
+
+    Status = select(0, &Fds, NULL, NULL, &Timeval);
+    if ((Status != SOCKET_ERROR) && (Status != 0)) {
+        Length = sizeof(From);
+        Status = recvfrom(IcmpSock, Buffer, Size, 0, &From, &Length);
+
+#ifdef DBG
+        printf("Received packet\n");
+        DisplayBuffer(Buffer, Status);
+        printf("\n");
+#endif /* DBG */
+    }
+    if (Status == SOCKET_ERROR) {
+        if (WSAGetLastError() != WSAETIMEDOUT) {
+            printf("Could not receive data (%d).\n", WSAGetLastError());
+            GlobalFree(Buffer);
+            return FALSE;
+        }
+        Status = 0;
+    }
+
+    if (Status == 0) {
+        printf("Request timed out.\n");
+        LostCount++;
+        GlobalFree(Buffer);
+        return TRUE;
+    }
+
+    if (!DecodeResponse(Buffer, Status, (PSOCKADDR_IN)&From)) {
+        /* FIXME: Wait again as it could be another ICMP message type */
+        printf("Request timed out (incomplete datagram received).\n");
+        LostCount++;
+    }
+
+    GlobalFree(Buffer);
+    return TRUE;
+}
+
+
+/* Program entry point */
+int main(int argc, char* argv[])
+{
+    UINT Count;
+    CHAR MinTime[20];
+    CHAR MaxTime[20];
+    CHAR AvgTime[20];
+
+    Reset();
+
+    if ((ParseCmdline(argc, argv)) && (Setup())) {
+
+        printf("\nPinging %s [%s] with %d bytes of data:\n\n",
+            TargetName, TargetIP, DataSize);
+               
+               Count = 0;
+               while ((NeverStop) || (Count < PingCount)) {
+                       Ping();
+                       Sleep(Timeout);
+                       Count++;
+               };
+
+        Cleanup();
+
+               /* Calculate avarage round trip time */
+        if ((SentCount - LostCount) > 0) {
+            AvgRTT.QuadPart = SumRTT.QuadPart / (SentCount - LostCount);
+        } else {
+            AvgRTT.QuadPart = 0;
+        }
+
+        /* Calculate loss percent */
+        if (LostCount > 0) {
+            Count = (SentCount * 100) / LostCount;
+        } else {
+            Count = 0;
+        }
+
+        if (!MinRTTSet)
+            MinRTT = MaxRTT;
+
+        TimeToMsString(MinTime, MinRTT);
+        TimeToMsString(MaxTime, MaxRTT);
+        TimeToMsString(AvgTime, AvgRTT);
+
+        /* Print statistics */
+        printf("\nPing statistics for %s:\n", TargetIP);
+        printf("    Packets: Sent = %d, Received = %d, Lost = %d (%d%% loss),\n",
+            SentCount, SentCount - LostCount, LostCount, Count);
+        printf("Approximate round trip times in milli-seconds:\n");
+        printf("    Minimum = %s, Maximum = %s, Average = %s\n",
+            MinTime, MaxTime, AvgTime);
+    }
+       return 0;
+}
+
+/* EOF */
diff --git a/reactos/apps/utils/net/ping/ping.rc b/reactos/apps/utils/net/ping/ping.rc
new file mode 100644 (file)
index 0000000..fb0b989
--- /dev/null
@@ -0,0 +1,7 @@
+/* $Id: ping.rc,v 1.3 2004/11/21 22:26:14 chorns Exp $ */
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS TCP/IPv4 Win32 Ping\0"
+#define REACTOS_STR_INTERNAL_NAME      "ping\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "ping.exe\0"
+#define REACTOS_STR_ORIGINAL_COPYRIGHT "Casper S. Hornstrup (chorns@users.sourceforge.net)\0"
+#include <reactos/version.rc>
index d63774a..954ada3 100644 (file)
@@ -1,6 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
 *.o
 *.d
-*.exe
 *.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
 *.sym
+*.plg
+*.bak
 *.map
index 6963dd7..5baa003 100644 (file)
@@ -1,5 +1,3 @@
-# $Id: Makefile,v 1.5 2002/06/07 22:58:02 ekohl Exp $
-
 PATH_TO_TOP = ../../../..
 
 TARGET_TYPE = program
@@ -8,19 +6,34 @@ TARGET_APPTYPE = console
 
 TARGET_NAME = telnet
 
-TARGET_SDKLIBS = kernel32.a ws2_32.a
+TARGET_SDKLIBS = ws2_32.a
+
+TARGET_CPPFLAGS = -D__REACTOS__ -D__USE_W32API -Wall
+
+TARGET_GCCLIBS = stdc++
 
 TARGET_OBJECTS = \
-       ansi.o          \
-       console.o       \
-       helpsock.o      \
-       main.o          \
-       nvt.o           \
-       telnet.o        \
-       vm.o
+       src/ansiprsr.o \
+       src/keytrans.o \
+       src/tcharmap.o \
+       src/tconsole.o \
+       src/tkeydef.o \
+       src/tkeymap.o \
+       src/tmapldr.o \
+       src/tmouse.o \
+       src/tnclass.o \
+       src/tnclip.o \
+       src/tncon.o \
+       src/tnconfig.o \
+       src/tnerror.o \
+       src/tnetwork.o \
+       src/tnmain.o \
+       src/tnmisc.o \
+       src/tscript.o \
+       src/tscroll.o \
+       src/ttelhndl.o
+
 
 include $(PATH_TO_TOP)/rules.mak
 
 include $(TOOLS_PATH)/helper.mk
-
-# EOF
diff --git a/reactos/apps/utils/net/telnet/Makefile.mingw b/reactos/apps/utils/net/telnet/Makefile.mingw
new file mode 100644 (file)
index 0000000..9aab1f5
--- /dev/null
@@ -0,0 +1,142 @@
+#
+# Makefile for Console Telnet
+# Last modified 4/15/2000 by Paul Brannan
+#
+
+SRCDIR=./src
+OBJDIR=src
+RESDIR=resource
+
+SRC=$(wildcard $(SRCDIR)/*.cpp)
+RESOURCES=$(wildcard $(RESDIR)/*.rc)
+OBJ1=$(SRC:.c=.o)
+OBJ=$(OBJ1:.cpp=.o) $(RESOURCES:.rc=.o)
+
+INCLUDES=-I$(RESDIR)
+
+OUT=telnet.exe
+
+# Modify these for your system if necessary
+# Note: DJGPP+RDXNTDJ configuration is untested.
+
+# --CYGWIN--
+#CC=gcc
+#CCC=g++
+#LDFLAGS=-lwsock32 -lmsvcrt
+#CFLAGS=-O2 -Wall -mwindows -mno-cygwin -D__CYGWIN__
+#CCFLAGS=$(CFLAGS)
+#RES=
+#RC=windres
+#RCFLAGS=-O coff
+
+# --MINGW32(+EGCS)--
+CC=gcc
+CCC=g++
+LDFLAGS=-lkernel32 -luser32 -lgdi32 -lshell32 -lwsock32
+CFLAGS=-O2 -Wall
+CCFLAGS=$(CFLAGS)
+RES=
+RC=windres
+RCFLAGS=
+
+# --DJGPP+RSXNTDJ--
+#CC=gcc -Zwin32 -Zmt -Zcrtdll
+#CCC=$(CC)
+#LDFLAGS=
+#CFLAGS= -g
+#CCFLAGS=$(CFLAGS)
+#RES=rsrc
+#RC=grc
+#RCFLAGS=-r
+
+
+# You should not have to modify anything below this line
+
+all: dep $(OUT)
+
+.SUFFIXES: .c .cpp .rc
+
+.c.o:
+       $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
+
+.cpp.o:
+       $(CCC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
+
+.rc.o:
+       $(RC) -i $< $(RCFLAGS) -o $@
+
+$(OUT): $(OBJ)
+       $(CCC) $(OBJ) $(LDFLAGS) $(LIBS) -o $(OUT)
+       strip $(OUT)
+
+depend: dep
+
+dep:
+       start /min makedepend -- $(CFLAGS) -- $(INCLUDES) $(SRC)
+
+clean:
+       del $(OBJDIR)\*.o
+       del $(OUT)
+
+# DO NOT DELETE
+
+./src/ansiprsr.o: ./src/ansiprsr.h ./src/tnconfig.h ./src/tnerror.h
+./src/ansiprsr.o: ./src/tnmsg.h ./src/tparser.h ./src/tconsole.h
+./src/ansiprsr.o: ./src/keytrans.h ./src/tkeydef.h ./src/tkeymap.h
+./src/ansiprsr.o: ./src/stl_bids.h ./src/tscroll.h ./src/tmouse.h
+./src/ansiprsr.o: ./src/tnclip.h ./src/tnetwork.h ./src/tcharmap.h
+./src/keytrans.o: ./src/keytrans.h ./src/tkeydef.h ./src/tkeymap.h
+./src/keytrans.o: ./src/stl_bids.h ./src/tnerror.h ./src/tnmsg.h
+./src/tcharmap.o: ./src/tcharmap.h ./src/tnconfig.h ./src/tnerror.h
+./src/tcharmap.o: ./src/tnmsg.h
+./src/tconsole.o: ./src/tconsole.h ./src/tnconfig.h ./src/tnerror.h
+./src/tconsole.o: ./src/tnmsg.h
+./src/tkeydef.o: ./src/tkeydef.h
+./src/tkeymap.o: ./src/tkeymap.h ./src/stl_bids.h ./src/tkeydef.h
+./src/tmapldr.o: ./src/tmapldr.h ./src/keytrans.h ./src/tkeydef.h
+./src/tmapldr.o: ./src/tkeymap.h ./src/stl_bids.h ./src/tcharmap.h
+./src/tmapldr.o: ./src/tnerror.h ./src/tnmsg.h ./src/tnconfig.h
+./src/tmouse.o: ./src/tmouse.h ./src/tnclip.h ./src/tnetwork.h
+./src/tmouse.o: ./src/tconsole.h ./src/tnconfig.h ./src/tnerror.h
+./src/tmouse.o: ./src/tnmsg.h
+./src/tnclass.o: ./src/tnclass.h ./src/tnconfig.h ./src/tnerror.h
+./src/tnclass.o: ./src/tnmsg.h ./src/ttelhndl.h ./src/tparser.h
+./src/tnclass.o: ./src/tconsole.h ./src/keytrans.h ./src/tkeydef.h
+./src/tnclass.o: ./src/tkeymap.h ./src/stl_bids.h ./src/tscroll.h
+./src/tnclass.o: ./src/tmouse.h ./src/tnclip.h ./src/tnetwork.h
+./src/tnclass.o: ./src/tcharmap.h ./src/tncon.h ./src/tparams.h
+./src/tnclass.o: ./src/ansiprsr.h ./src/tmapldr.h ./src/tnmisc.h
+./src/tnclip.o: ./src/tnclip.h ./src/tnetwork.h
+./src/tncon.o: ./src/tncon.h ./src/tparams.h ./src/ttelhndl.h ./src/tparser.h
+./src/tncon.o: ./src/tconsole.h ./src/tnconfig.h ./src/tnerror.h
+./src/tncon.o: ./src/tnmsg.h ./src/keytrans.h ./src/tkeydef.h ./src/tkeymap.h
+./src/tncon.o: ./src/stl_bids.h ./src/tscroll.h ./src/tmouse.h ./src/tnclip.h
+./src/tncon.o: ./src/tnetwork.h ./src/tcharmap.h
+./src/tnconfig.o: ./src/tnconfig.h ./src/tnerror.h ./src/tnmsg.h
+./src/tnerror.o: ./src/tnerror.h ./src/tnmsg.h ./src/ttelhndl.h
+./src/tnerror.o: ./src/tparser.h ./src/tconsole.h ./src/tnconfig.h
+./src/tnerror.o: ./src/keytrans.h ./src/tkeydef.h ./src/tkeymap.h
+./src/tnerror.o: ./src/stl_bids.h ./src/tscroll.h ./src/tmouse.h
+./src/tnerror.o: ./src/tnclip.h ./src/tnetwork.h ./src/tcharmap.h
+./src/tnetwork.o: ./src/tnetwork.h
+./src/tnmain.o: ./src/tnmain.h ./src/tncon.h ./src/tparams.h ./src/ttelhndl.h
+./src/tnmain.o: ./src/tparser.h ./src/tconsole.h ./src/tnconfig.h
+./src/tnmain.o: ./src/tnerror.h ./src/tnmsg.h ./src/keytrans.h
+./src/tnmain.o: ./src/tkeydef.h ./src/tkeymap.h ./src/stl_bids.h
+./src/tnmain.o: ./src/tscroll.h ./src/tmouse.h ./src/tnclip.h
+./src/tnmain.o: ./src/tnetwork.h ./src/tcharmap.h ./src/tnclass.h
+./src/tnmain.o: ./src/ansiprsr.h ./src/tmapldr.h ./src/tnmisc.h
+./src/tnmisc.o: ./src/tnmisc.h
+./src/tscript.o: ./src/tscript.h ./src/tnetwork.h
+./src/tscroll.o: ./src/tscroll.h ./src/tconsole.h ./src/tnconfig.h
+./src/tscroll.o: ./src/tnerror.h ./src/tnmsg.h ./src/tmouse.h ./src/tnclip.h
+./src/tscroll.o: ./src/tnetwork.h ./src/tncon.h ./src/tparams.h
+./src/tscroll.o: ./src/ttelhndl.h ./src/tparser.h ./src/keytrans.h
+./src/tscroll.o: ./src/tkeydef.h ./src/tkeymap.h ./src/stl_bids.h
+./src/tscroll.o: ./src/tcharmap.h
+./src/ttelhndl.o: ./src/ttelhndl.h ./src/tparser.h ./src/tconsole.h
+./src/ttelhndl.o: ./src/tnconfig.h ./src/tnerror.h ./src/tnmsg.h
+./src/ttelhndl.o: ./src/keytrans.h ./src/tkeydef.h ./src/tkeymap.h
+./src/ttelhndl.o: ./src/stl_bids.h ./src/tscroll.h ./src/tmouse.h
+./src/ttelhndl.o: ./src/tnclip.h ./src/tnetwork.h ./src/tcharmap.h
+./src/ttelhndl.o: ./src/telnet.h ./src/tparams.h
diff --git a/reactos/apps/utils/net/telnet/ansi.cpp b/reactos/apps/utils/net/telnet/ansi.cpp
deleted file mode 100644 (file)
index 4130efc..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-/* $Id: ansi.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
- *
- * FILE       : ansi.cpp
- * AUTHOR     : unknown (sources found on www.telnet.org)
- * PROJECT    : ReactOS Operating System
- * DESCRIPTION: telnet client for the W32 subsystem
- * DATE       : 2001-01-21
- * REVISIONS
- *     2001-02-21 ea   Modified to compile under 0.0.16 src tree
- */
-#include <winsock.h>
-#include <windows.h>
-
-#include "telnet.h"
-
-// Need to implement a Keymapper.
-// here are some example key maps
-
-// vt100 f1 - \eOP
-// vt100 f2 - \eOQ
-
-// ansi  f5 - \e[17~
-//       f6 - \e[18~
-//       f7 - \e[20~
-//       f10- \e[[V
-
-enum _ansi_state
-{
-  as_normal,
-  as_esc,
-  as_esc1
-};
-
-//SetConsoleMode
-
-///////////////////////////////////////////////////////////////////////////////
-// SET SCREEN ATTRIBUTE
-/*
-ESC [ Ps..Ps m  Ps refers to selective parameter. Multiple parameters are
-                separated by the semicolon character (073 octal). The param-
-                eters are executed in order and have the following meaning:
-
-                0 or none               All attributes off
-                1                       Bold on
-                4                       Underscore on
-                5                       Blink on
-                7                       Reverse video on
-
-                3x                      set foreground color to x
-                nx                      set background color to x
-
-                Any other parameters are ignored.
-*/
-static int sa = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
-
-void ansi_set_screen_attribute(char* buffer)
-{
-  while(*buffer)
-  {
-    switch(*buffer++)
-    {
-    case '0': //Normal
-      sa = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
-      break;
-    case '1': //Hign Intensity
-      sa |= FOREGROUND_INTENSITY;
-      break;
-    case '4': //Underscore
-      break;
-    case '5': //Blink.
-      sa |= BACKGROUND_INTENSITY;
-      break;
-    case '7':
-      sa = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
-      break;
-    case '8':
-      sa = 0;
-      break;
-    case '3':
-      sa = sa & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY) |
-        (*buffer & 1)?FOREGROUND_RED:0 |
-        (*buffer & 2)?FOREGROUND_GREEN:0 |
-        (*buffer & 4)?FOREGROUND_BLUE:0;
-      if(*buffer)
-        buffer++;
-      break;
-    case '6':
-      sa = sa & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY) |
-        (*buffer & 1)?BACKGROUND_RED:0 |
-        (*buffer & 2)?BACKGROUND_GREEN:0 |
-        (*buffer & 4)?BACKGROUND_BLUE:0;
-      if(*buffer)
-        buffer++;
-      break;
-    }
-    if(*buffer && *buffer == ';')
-      buffer++;
-  }
-  SetConsoleTextAttribute(StandardOutput,sa);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ERASE LINE
-/*
-ESC [ 0K        Same *default*
-ESC [ 1K        Erase from beginning of line to cursor
-ESC [ 2K        Erase line containing cursor
-*/
-
-void ansi_erase_line(char* buffer)
-{
-  int act = 0;
-  while(*buffer)
-  {
-    act = (*buffer++) - '0';
-  }
-
-  CONSOLE_SCREEN_BUFFER_INFO csbi;
-  GetConsoleScreenBufferInfo(StandardOutput,&csbi);
-
-  COORD pos;
-  DWORD n;
-
-  switch(act)
-  {
-  case 0: //erase to end of line
-    pos.X = csbi.dwCursorPosition.X;
-    pos.Y = csbi.dwCursorPosition.Y;
-    n = csbi.dwSize.X - csbi.dwCursorPosition.X;
-    break;
-  case 1: //erase from beginning
-    pos.X = 0;
-    pos.Y = csbi.dwCursorPosition.Y;
-    n = csbi.dwCursorPosition.X;
-    break;
-  case 2: // erase whole line
-    pos.X = 0;
-    pos.Y = csbi.dwCursorPosition.Y;
-    n = csbi.dwSize.X;
-    break;
-  }
-
-  DWORD w;
-  FillConsoleOutputCharacter(StandardOutput,' ',n,pos,&w);
-}
-
-
-///////////////////////////////////////////////////////////////////////////////
-// SET POSITION
-// ESC [ Pl;PcH    Direct cursor addressing, where Pl is line#, Pc is column#
-// default = (1,1)
-
-void ansi_set_position(char* buffer)
-{
-  COORD pos = {0,0};
-
-  // Grab line
-  while(*buffer && *buffer != ';')
-    pos.Y = pos.Y*10 + *buffer++ - '0';
-
-  if(*buffer)
-    buffer++;
-
-  // Grab y
-  while(*buffer && *buffer != ';')
-    pos.X = pos.X*10 + *buffer++ - '0';
-
-  (pos.X)?pos.X--:0;
-  (pos.Y)?pos.Y--:0;
-
-  SetConsoleCursorPosition(StandardOutput,pos);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ERASE SCREEN
-/*
-ESC [ 0J        Same *default*
-ESC [ 2J        Erase entire screen
-*/
-
-void ansi_erase_screen(char* buffer)
-{
-  int act = 0;
-  while(*buffer)
-  {
-    act = (*buffer++) - '0';
-  }
-
-  CONSOLE_SCREEN_BUFFER_INFO csbi;
-  GetConsoleScreenBufferInfo(StandardOutput,&csbi);
-
-  COORD pos;
-  DWORD n;
-
-  switch(act)
-  {
-  case 0:
-    pos.X = csbi.dwCursorPosition.X;
-    pos.Y = csbi.dwCursorPosition.Y;
-    n = csbi.dwSize.X*csbi.dwSize.Y;
-    break;
-  case 2:
-    pos.X = 0;
-    pos.Y = 0;
-    n = csbi.dwSize.X*csbi.dwSize.Y;
-    break;
-  }
-
-  DWORD w;
-  FillConsoleOutputCharacter(StandardOutput,' ',n,pos,&w);
-  SetConsoleCursorPosition(StandardOutput,pos);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// MOVE UP
-// ESC [ Pn A      Cursor up Pn lines (Pn default=1)
-
-void ansi_move_up(char* buffer)
-{
-  int cnt = *buffer?0:1;
-  while(*buffer)
-  {
-    cnt = cnt*10 + (*buffer++) - '0';
-  }
-
-  COORD pos;
-
-  CONSOLE_SCREEN_BUFFER_INFO csbi;
-  GetConsoleScreenBufferInfo(StandardOutput,&csbi);
-
-  pos.X = csbi.dwCursorPosition.X;
-  pos.Y = ((csbi.dwCursorPosition.Y-cnt)>=0)?(csbi.dwCursorPosition.Y-cnt):0;
-
-  SetConsoleCursorPosition(StandardOutput,pos);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-char codebuf[256];
-unsigned char codeptr;
-
-#define NUM_CODEC 6
-
-typedef void (*LPCODEPROC)(char*);
-
-struct 
-{
-  unsigned char cmd;
-  LPCODEPROC proc;
-} codec[NUM_CODEC] = {
-  {'m',ansi_set_screen_attribute},
-  {'H',ansi_set_position},
-  {'K',ansi_erase_line},
-  {'J',ansi_erase_screen},
-  {'A',ansi_move_up},
-  {0,0}
-};
-
-void ansi(SOCKET server,unsigned char data)
-{
-  static _ansi_state state = as_normal;
-  DWORD z;
-  switch( state)
-  {
-  case as_normal:
-    switch(data)
-    {
-    case 0:  //eat null codes.
-      break;
-    case 27: //ANSI esc.
-      state = as_esc;
-      break;
-    default: //Send all else to the console.
-      WriteConsole(StandardOutput,&data,1,&z,NULL);
-      break;
-    }
-    break;
-  case as_esc:
-    state = as_esc1;
-    codeptr=0;
-    codebuf[codeptr] = 0;
-    break;
-  case as_esc1:
-    if(data > 64)
-    {
-      int i = 0;
-      codebuf[codeptr] = 0;
-      for(i=0; codec[i].cmd && codec[i].cmd != data; i++);
-      if(codec[i].proc)
-        codec[i].proc(codebuf);
-#ifdef _DEBUG
-      else
-      {
-        char buf[256];
-        wsprintf(buf,"Unknown Ansi code:'%c' (%s)\n",data,codebuf);
-        OutputDebugString(buf);
-      }
-#endif
-      state = as_normal;
-    }
-    else
-      codebuf[codeptr++] = data;
-    break;
-  }
-}
-
-/* EOF */
diff --git a/reactos/apps/utils/net/telnet/console.cpp b/reactos/apps/utils/net/telnet/console.cpp
deleted file mode 100644 (file)
index 09dcaec..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/* $Id: console.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
- *
- * FILE       : console.cpp
- * AUTHOR     : E.Aliberti
- * PROJECT    : ReactOS Operating System
- * DESCRIPTION: telnet client for the W32 subsystem
- * DATE       : 2001-01-21
- * REVISIONS
- *     2001-02-21 ea   added to group console-related methods
- */
-#include <windows.h>
-
-const char * title = "telnet - ";
-
-// Set console's title
-void console_title_connecting (
-       char const* pszHostName,
-       const int nPort
-       )
-{
-  char t[256];
-  wsprintf(t,"%sconnecting to %s:%i", title, pszHostName, nPort);
-  SetConsoleTitle(t);
-}
-
-void console_title_connected (
-       char const* pszHostName,
-       const int nPort
-       )
-{
-  char t[256];
-  wsprintf(t,"%sconnected to %s:%i", title, pszHostName, nPort);
-  SetConsoleTitle(t);
-}
-
-void console_title_not_connected (void)
-{
-  char t[256];
-  wsprintf(t,"%snot connected", title);
-  SetConsoleTitle(t);
-}
-
-/* EOF */
diff --git a/reactos/apps/utils/net/telnet/console.h b/reactos/apps/utils/net/telnet/console.h
deleted file mode 100644 (file)
index 0846f38..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _APPS_NET_TELNET_CONSOLE_H
-#define _APPS_NET_TELNET_CONSOLE_H 
-void console_title_connecting (
-       char const* pszHostName,
-       const int nPort
-       );
-void console_title_connected (
-       char const* pszHostName,
-       const int nPort
-       );
-void console_title_not_connected (void);
-#endif /* _APPS_NET_TELNET_CONSOLE_H */
diff --git a/reactos/apps/utils/net/telnet/doc/00readme.avs b/reactos/apps/utils/net/telnet/doc/00readme.avs
new file mode 100644 (file)
index 0000000..fe0e2d2
--- /dev/null
@@ -0,0 +1,261 @@
+Hi!
+
+Now I come back to telnet source, and make some changes, wich you suggest
+to me:
+
+1.  telnet.rc renamed to telnet.cfg
+2.  I change syntax of 'keys' command (but I did'nt found a tool for edit
+    msg*.bin files - so it's remain unchanged). Syntax are
+
+        keys load keymapname [file]
+        keys display
+        keys switch number
+
+
+I fix some 'political' ;) problem with charmap, now we (citizens of xUSSR)
+have koi8, koi8r and koi8u(RFC on draft) on UNIX, wich are diff's on 6 or
+8 letters; cp866 and many (3 or 4) very near to cp866 on DOS.
+
+So, I rewrite code to able a charmap addition like a keymap done.
+
+And I make more smart command line processing, look at telCommandLine().
+
+And last: my english is not so good :( to rewrite documentation, but there are
+things, wich would be described - look on next page. I think that you will
+translate my english to more understable, ok?
+
+and now is a list of files, wich I touch
+
+
+                            old                         new
+
+ANSIPRSR.CPP        32763  05.10.97  11:09    33237  24.12.97  17:42
+ANSIPRSR.H           3311  04.09.97   0:25     3410  23.12.97  13:18
+KEYTRANS.CPP         9504  28.05.97  22:43    26547  03.02.98  21:33
+KEYTRANS.H           8020  25.01.97  16:06     8090  03.02.98  19:53
+TNCLASS.CPP         13663  17.08.97  23:55    13891  03.02.98  20:09
+TNCLASS.H            1112  01.06.97  14:19     1233  03.02.98  20:09
+TNMAIN.CPP          12668  02.10.97  20:38    16610  03.02.98  21:22
+TNNET.CPP            3445  01.06.97  14:21     3474  23.12.97  13:16
+TNPARSER.CPP        17653  05.10.97  11:09    17715  23.12.97  18:03
+TNPARSER.H           2129  01.06.97  14:22     2188  23.12.97  13:25
+
+KEYS.CFG            erased
+TELNET.CFG          new
+
+TELNET.IDE          65810  26.10.97  16:53    66118  03.02.98  21:34
+
+
+I was start my work with file telc2b4s.zip with size 132619 bytes, and now send
+to you just files, wich I touch.
+
+with best regards
+Andrei V. Smilianets
+
+smile@head.aval.kiev.ua
+22:25 03 Feb 1998
+
+
+\f
+There are all of my changes (from 2.04b), wich have to be described:
+
+1. command line (telnet>) processing
+
+   a 'keys' command
+
+        was
+                keys keymapname [file]
+        new
+                keys load keymapname [file] // mean unchanged
+                keys display                // display a list of loaded keymaps
+                keys switch number          // switch to keymap
+
+   more smart command processing
+
+        command might be writed shortly
+
+          cl[ose]
+          op[en]
+          ke[ys]
+          qu[it]
+
+        subcommands of 'keys'
+
+          l[oad]
+          d[isplay]
+          s[witch]
+
+        synonym of '?' -> h[elp]
+
+2. file 'keys.cfg' renamed to 'telnet.cfg'
+
+3. Added codepage conversion, look [charmap]
+
+4. completely changed conception of telnet.cfg
+
+   Now you can define multiple keymaps, character maps, combine it in your
+   ways.
+
+   file is splitted into following sections:
+
+    [COMMENT]
+     ...
+    [END COMMENT]
+
+        it is for comment a big part of text. can be nested.
+        in text also work:
+
+           ; - first printable character in line, which is completelly
+               ignored.
+           // - like C++ comment
+
+    [GLOBAL]
+    ...
+    [END GLOBAL]
+
+        mean of [global] unchanged
+
+    [KEYMAP name]
+    ...
+    [END KEYMAP]
+        'name' - is a keymap name for reference. in 'name' you can use
+        any char exept spaces, '+', ':' and ']'. '+' and ':' reserved for
+        CONFIG section.
+        body is a sequence of key definition:
+
+           <vk_name> [keymodifier[+keymodifier[+...]]] <keytranslation>
+
+        example:
+           VK_F1 RIGHT_ALT+RIGHT_CTRL this_would_print
+
+        vk_name is an ASCII string equivalent to an entry in [GLOBAL].
+
+        valid keymodifiers are:
+          RIGHT_ALT
+          LEFT_ALT
+          RIGHT_CTRL
+          LEFT_CTRL
+          SHIFT
+          ENHANCED
+
+        Undefined enhanced keys will use the non-enhanced definition.
+
+        keytranslation is the string you want printed for the key.
+        The notation ^[ can be used to denote an escape character.
+        Any ASCII value can be represented by
+
+            \nnn where nnn is a 3 digit decimal ASCII value or
+            \xhh where hh is a 2 digit hexadecimal ASCII value.
+
+        Leading zeros may not be omitted.
+        A value of \000(\x00) will not be transmitted.
+
+        note: In order to have both left and right alt have the same
+        action, you must create a separate def for left and right.
+
+
+    [CHARMAP name]
+    ...
+    [END CHARMAP]
+        'name' - is a charmap name for reference. requirements is the same
+        as for keymap name.
+        body is a sequence of char conversion definition:
+
+           <host_char> <console_char>
+
+        where host_char is a char received from host, and console_char
+        is a char, which would be displayed on console.
+
+        The main purpose of it is a conversion between differents code
+        pages, for example, on former USSR part of world most unix's hosts
+        uses 'koi8' code page, and on W95 machines - 866 code page and
+        (as say I.Ioannou)  Greece has the same problem with 737 and 928
+        code-pages.
+
+
+        Any ASCII value can be represented by
+
+            \nnn where nnn is a 3 digit decimal ASCII value or
+            \xhh where hh is a 2 digit hexadecimal ASCII value.
+
+        Leading zeros may be omitted.
+        A value of \000(\x00) will not be accepted.
+
+        look for example at [charmap koi8-cp866].
+
+    [CONFIG name]
+    ...
+    [END CONFIG]
+        'name' - is a configuration name for reference. requirements is
+        the same as for keymap name.
+
+        you must define one with name 'default', which will be used as
+        default.
+
+        in body of this part you can combine keymaps and set charmap,
+        format is:
+
+           KEYMAP name_list [: <vk_name> [keymodifier[+keymodifier[+...]]] ]
+
+             where
+                  name_list:
+                     keymap_name
+                     keymap_name '+' name_list
+
+                  keymap_name is a name of [KEYMAP]
+
+             You can specify multiple keymaps, for first (mean default)
+             you can not define ': <vk_name> ...' part, but for rests
+             (secondary) you must!
+             The ': <vk_name> ...' part define a key for switch to this
+             keymap.
+
+             Assigning a switching key to first (default) keymap will be
+             ignored, but you can switch to by pressing second time switch
+             key of current keymap.
+
+             If a key not found in switched keymap, a program will be look
+             for it in default keymap. So, you can redefine only needed keys
+             in secondary keymaps.
+
+           CHARMAP name_list
+
+                where
+                      name_list:
+                                charmap_name
+                                charmap_name '+' name_list
+
+                      charmap_name is a name of [CHARMAP]
+
+
+             define wich charmap(s) is to use.
+
+           examples:
+              [config default]
+                 keymap default
+              [end config]
+
+              [config linux]
+                 keymap default + linux
+              [end config]
+
+              [config default_koi8]
+                 keymap default
+                 keymap koi8u + koi8r : VK_/ RIGHT_ALT // russian keyboard
+                 keymap koi8u         : VK_. RIGHT_ALT // ukranian
+
+                 charmap koi8-cp866
+              [end config]
+
+              [config linux_koi8]
+                 keymap default + linux
+                 keymap koi8u + koi8r : VK_/ RIGHT_ALT // russian keyboard
+                 keymap koi8u         : VK_. RIGHT_ALT // ukranian
+
+                 charmap koi8-cp866 + koi8u-cp866
+              [end config]
+
+            so, for switch to russian keyboard just press RIGHT_ALT and '/'.
+            and, for switch back to default press it again.
+
+
diff --git a/reactos/apps/utils/net/telnet/doc/bugs.txt b/reactos/apps/utils/net/telnet/doc/bugs.txt
new file mode 100644 (file)
index 0000000..52e1794
--- /dev/null
@@ -0,0 +1,24 @@
+                **********************************************
+                *** Console Telnet 2.1 beta 2.  Known Bugs ***
+                **********************************************
+
+
+Wrap_Line = 0   Doesn't work very well. It works with elvis or talk on linux,
+                but messes up bash at last line.
+
+Enable_Mouse=1  Causes the display to slow in fullscreen mode, since the
+                mouse has to be erased and then drawn again for every
+                screen write.
+
+Term_Width or Term_Height != -1 or Wide_Enable=1
+                Specifying any of these can cause display problems if
+                the font size is not set to auto.
+
+Resizing the current window while running telnet can cause problems, especially
+if doing so makes the buffer smaller.  This should be more of a problem on
+NT/W2K than on 95/98.  Part of the problem is that the telnet NAWS option
+negotiation isn't done properly.  On a related note, turning on scrollbars can
+decrease performance.
+
+There are many other bugs, most of which are documented in the code.  Just
+grep the source for "FIX ME".
diff --git a/reactos/apps/utils/net/telnet/doc/changes.txt b/reactos/apps/utils/net/telnet/doc/changes.txt
new file mode 100644 (file)
index 0000000..4e03d47
--- /dev/null
@@ -0,0 +1,239 @@
+                **********************************************
+                *** Console Telnet version 2.1 Change log  ***
+                **********************************************
+
+Version 2.1b2 -- October 16, 2000
+  Redirection fix (Mark Miesfield)
+  Allow "o" to open a connecton on the command line
+  Fixed problem with special keys (ALt-[, Alt-], Alt-\, etc.)
+  Added MTE Support (Ziglio Frediano)
+  Speed improvements in ttelhndl.cpp -- may be buggy?
+  Wrap_line option is now modifiable via telnet command line
+  Lock_linewrap option added
+  Cleaned up console code
+  Fixed some color issues with nonstandard consoles
+  Tab setting/resetting
+  Fixed "telnet.exe" installer problem
+  Fixed miscellaneous parsing bugs
+  Fixed vt100-compliance
+  Added NAWS support, but it doesn't work (RFC 1073)
+  Added X Display Location support (RFC 1096)
+
+Version 2.1b1 -- April 5, 2000
+-Bugfixes
+  Console code writes to bottom of buffer (W2K scrollback buffer now works)
+  Updated Winsock error messages (Craig Nellist)
+  Sleeping while thread paused, to give up CPU time (Craig Nellist)
+  Ctrl_Break_as_C now works properly
+  Restore original screen colors; use initial screen colors as default
+
+-New features
+  Cursor size sequences (Jose Cesar Otero Ridriguez)
+  Network piping
+  Line mode support added
+  Support for telnet:// URLs
+  Command-line history (Craig Nellist)
+  Connection Aliases
+
+-Translator updates
+  New code structure
+  Unified character map class
+  More configurable "special" keys:
+    tn_escape, tn_scrollback, tn_dial, tn_paste, tn_null, tn_cr, tn_crlf
+  Transmission of NUL character possible
+  Czech keyboard definition (Jakub Sterba)
+
+-New INI options
+  Window_Width, Window_Height
+  Scriptname (not functional), Script_Enable (not functional)
+  Netpipe (functional), Iopipe (not functional)
+
+Version 2.0 -- July 5, 1999
+-Bugfixes
+  Save/restore console title, character mapping fix (Pedro Gutierrez)
+  Telnet prompt fix, suspend telnet, string-based port (Craig Davidson)
+  Mutt/Lynx colors/underline fix, repeat character fix
+  Color display problem fixed (I.Ioannou)
+  Newline properly handled, added APP4_KEY, better key translation
+  Problem with icons not displaying properly fixed
+  Small bug with telnet crashing at exit (Sam Robertson, Daniel Straub)
+  Bug getting name of executable (Thomas Briggs)
+
+-Updates
+  Better key translation
+  Spanish keyboard definition (Cesar Otero)
+
+-New ini options
+  Set_Title (Adi Seiker)
+  Scroll_Enable/Scroll_Size
+  CtrlBreak_as_CtrlC (Bryan Montgomery)
+  Clear_on_Tabset removed
+  
+Version 2.0b7.1 -- Dec. 5, 1998
+-Minor changes
+  Fixed problems with Scrollback and Clipboard
+  Minor updates to terminal emulation
+  Keyboard init improvements (Vassili Bourdo)
+  Repeat sequence support, German key config (Titus von Boxberg)
+
+Version 2.0b7 -- Oct. 21, 1988
+-To do still:
+  ZModem support
+  Update key translator/character maps
+  Finish scrollback
+
+-Changes
+  Options added: Term_Width, Term_Height, Wide_Enable, Buffer_Size, Dial_key,
+        Keyboard_Paste, Status_bg, Status_fg, Input_Redir, Output_Redir
+
+  Application keypad mode support
+  Numlock/scroll lock support in KEYS.CFG
+  Del/. key now works properly
+  Ctrl-break bugfixes (Thomas Briggs)
+
+  Added suspend and fast quit to the command line (Thomas Briggs)
+  Error message for unable to load ini file (Thomas Briggs)
+  Fixed TELNET_INI environment variable (BK Oxley)
+
+  Support for changing screen size
+  Support for switching to 132-column mode via ANSI sequences
+
+  Fixed minor memory leaks
+  Mouse speedups/bugfixes, scrolling speedups/bugfixes
+  Miscellaneous ANSI parser fixes
+
+  Added support for changing the icon in the corner of the window
+  Fixed bug with mIRC
+  Fixed "try again" error message
+  Input and output redirection now separate (TELNET_REDIR still supported)
+  Modified "set" command to operate on groups
+  Character mapping now works again
+
+Version 2.0b6 28 Jul 1998
+-To Do still:
+  ZModem support
+  Finish mouse support
+  Fix character maps
+
+-Changes:
+  ANSI Parser should be almost complete
+  Reorganized source
+  Display speedups
+  Preliminary mouse support
+  Enhanced scrollback support
+  Miscellaneous bug fixes
+
+Version 2.0b5 05 Jun 1998
+-Version 2b5 released from I.Ioannou <roryt@hol.gr>
+-To Do Still:
+  Too many to mention :-)
+-To Do, Maybe:
+  Mouse cut/paste support.
+  Support secure telnet options.
+  Real blinking attributes.
+  Zmodem & Kermit DL Protocols.
+  Any ideas acceptable :-)
+
+
+May 1998
+-Changes
+   Paul Brannan <pbranna@clemson.edu> add telnet.ini code
+   improve telnet's speed, add some VT emulation, port telnet to
+   MSVC, rewrote the command line options processing with GNU getopt,
+   fix many bugs, and more.  Good work Paul :-)
+   I.Ioannou <roryt@hol.gr> . A few bugs fixes, and a icon.
+   Also I convert tnmsg files to use a resource compiler.
+
+December 1997
+-Changes
+    Andrey V. Smilianets (smile@head.aval.kiev.ua)
+    rewrote the keys translator to support many different
+    keymaps, charmaps and configurations.
+    Also add editing support to telnet> prompt.
+
+
+Version 2.0b4 10/6/97
+-Updated by Brad Johnson who can be contacted at
+  <jbj@nounname.com>  http://nounname.com
+-Changes
+  Added command line history at the telnet> prompt.
+  Added ability to "unmap" a key by setting it equal to \000 in the key.cfg.
+  Added log-file option '-dFILENAME'.
+  Added print screen/line commands by I.Ioannou <roryt@hol.gr>.
+  Added Support for running in an emacs buffer <mauch@unidui.uni-duisburg.de>.
+  Added better support for international character sets
+     <mauch@unidui.uni-duisburg.de>.
+-To Do Still:
+  Support for local echo.
+  Scrollback buffer.
+  Fix Scrolling bug.
+-To Do, Maybe:
+  Change the telnet options to initiate the negotiation.
+  Mouse cut/paste support.
+  Support secure telnet options.
+  Real blinking attributes.
+  Zmodem & Kermit DL Protocols.
+
+Version 2.0b3  12/25/96:
+-Updated by Brad Johnson who can be contacted at
+  <jbj@nounname.com>  http://nounname.com
+-Changes
+  Screen colors and buffer settings are now preserved on exit.
+  Fixed WindowSize height/width 255 exception :-).
+  Found out that the paste problem is a bug in Win 95 (not my problem)!
+  Fixed screen buffer problems under NT when the window
+    was smaller than the buffer.
+  Added custom key maps by I.Ioannou <roryt@hol.gr>.
+-To Do Still:
+  Fix advance to next line error when writing past column
+  Extend NAWS window negotiation to include buffer size changes.
+  Change the telnet options to initiate the negotiation.
+  Add print screen/line commands.
+-To Do, Maybe:
+  Support for running in an emacs buffer.
+  Mouse cut/paste support.
+  Support secure telnet options.
+  Real blinking attributes.
+  Zmodem & Kermit DL Protocols.
+
+Version 2.0b2  09/29/96:
+-Updated by Brad Johnson who can be contacted at
+  <jbj@nounname.com>  http://nounname.com
+-Changes
+  Added code to move cursor to end of screen and reset attributes on close
+  Fixed potential IAC parsing problem
+  Fixed ClearScreen Last line problem
+  Fixed parse problem that prevented line clears on unix history
+  Changed scroll code to scroll the entire buffer
+  Removed destructive backspace. May cause problems with terminals that want
+    destructive backspaces.
+  Added binary telnet option to use 8bit.
+-To Do Next
+  Paste still doesn't work!
+
+Version 2.0b1  09/22/96:
+-Updated by Brad Johnson who can be contacted at
+  <jbj@nounname.com>  http://nounname.com
+-Changes
+  Added Color ANSI support. It works!
+  Added option for user specified port addresses on the command line.
+  Added ANSI keyboard mapping support for cursor keys.
+  Added destructive Backspace.
+  Added escape key 'ALT-]'.
+  Added TermType and WindowSize telnet options.
+  Added/Fixed various other ANSI codes.
+  Now (I hope) all ANSI codes handled correctly!
+  Fixed cursor left/right/save/restore commands.
+  Fixed clear line and clear screen command.
+  Expanded and altered network buffer to prevent some lockups :-).
+  Added Unix style telnet prompt "telnet>" with options.
+-To Do Next
+  Should parse for IAC separate from ANSI.
+
+Version 1.0a:
+- This release fixes a bug which caused it to hang when connecting to
+  UNIX boxes. The program simply ignored Telnet DO instead of replying
+  with WON'T as required by RFC 854.
+
+Version 1.0:
+- First release
diff --git a/reactos/apps/utils/net/telnet/doc/license.txt b/reactos/apps/utils/net/telnet/doc/license.txt
new file mode 100644 (file)
index 0000000..3358a7b
--- /dev/null
@@ -0,0 +1,340 @@
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                          675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+\f
+                   GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+\f
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+\f
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+\f
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                           NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+       Appendix: How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
diff --git a/reactos/apps/utils/net/telnet/doc/options.txt b/reactos/apps/utils/net/telnet/doc/options.txt
new file mode 100644 (file)
index 0000000..fefd154
--- /dev/null
@@ -0,0 +1,187 @@
+This file describes all the environment variables and options that are
+available in TELNET.INI.  If you are having problems with a terminal setting,
+this is the file you want to read first.  If this file does not help you,
+please send a bug report to Paul Brannan <pbranna@clemson.edu>.
+
+Environment variables
+---------------------
+
+Before there was a telnet.ini file, all the options were controlled
+through environment variables.  These have been left in for compatibility
+with previous versions, and for specifying locations of files.  They
+override any values in telnet.ini.
+
+TELNET_CFG      Specifies the location of the keys.cfg file
+TELNET_REDIR    Specifies whether file redirection needs to be supported
+INPUT_REDIR     Specicies only to redirect input
+OUTPUT_REDIR    Specifies only to redirect output
+TELNET_INI      Specifies the location of the telnet.ini file
+
+Configuration options
+---------------------
+
+These are the options that you can specify in telnet.ini.  This file is in
+the same format as any normal Windows ini file.  You can also change some
+of these options using the SET command at the telnet> prompt.
+
+[Terminal] section
+
+Dumpfile
+Specifies the filename of a file to dump output to.  (Default = "")
+
+Term
+The name of the terminal type to send to the server.  You
+can use this if Telnet is sending "ANSI" but you have a
+vt100 terminal.  If you use this options, please read about
+some of the other options below.  (Default = ansi)
+
+EightBit_Ansi
+Some machines use the ASCII characters 128 to 155 for ANSI
+sequences.  These are usually the newer VAX systems.  Turning
+this option on may cause problems with certain foreign
+(non-American) character sets.  (Default = FALSE)
+
+VT100_Mode
+This option turns on VT100 mode.  There are a few minor
+differences between ANSI terminals and DEC VT100 terminals.
+I recommend trying TERM=vt220 or TERM=vt102 before trying
+this option, but if you must have true VT100 emulation,
+this is the only way to get it.  (Default = FALSE)
+
+Destructive_Backspace
+This will probably cause problems with most programs, but if you need the
+backspace to erase the previous character (as with some BBSes), use this
+option.  (Default = FALSE)
+
+Speaker_Beep
+If you set this to true you will hear beeps through the PC speaker; setting
+it to false will play the default system beep sound through your sound
+card.  (Default = TRUE)
+
+Beep
+Setting this to false turns off all beeps; setting this to true turns on
+all beeps.  (Default = TRUE)
+
+Preserve_Colors
+This turns on color preservation for systems that require it (like SCO).
+(Default = FALSE)
+
+Wrap_line
+This turns on/off line wrap.  (Default = TRUE)
+
+Lock_linewrap
+Turning on this option disables the ability of the remote end to control
+line wrap, and "locks" it into whatever it is set to in the ini file.
+(Default = FALSE)
+
+Fast_write
+This turns on/off fast screen write.  Turning it off allows you to see
+control characters if your application requires it.  (Default = TRUE)
+
+Term_width
+Term_height
+These options specify the size of the terminal.  You can specify non-standard
+sizes if you are running telnet in a window.  You may want to specify
+a font size if you use these (using "Auto" can cause display problems).
+Specifying -1 means use the settings for the parent console.
+(Default = -1, -1)
+
+Wide_enable
+This is to allow the ANSI parser to change the screen size when sent certain
+escape sequences.  This is for vt100 compatibility.  (Default = FALSE)
+
+Buffer_size
+This is the size of the ANSI buffer used for parsing sequences.  Increasing
+this value speeds up the parser, and decreasing it allows the mouse to
+respond faster.  (Default = 2048)
+
+Input_redir
+Output_redir
+These are for redirecting input and output.  (Default = 0, 0)
+Any value greater than 0 turns redir on.  Turn Output_redir on to bypass
+the Console Telnet screen writing and positioning functions and simply
+pass the data stream as received from the host straight through.
+
+Strip_redir
+If enabled, this option will attempt to strip the stream before passing it on
+through redirected output.  This will have no effect on non-redirected output.
+(Default=FALSE)
+
+[Colors] section
+
+Setting the following to -1 disables them:
+Blink_bg                Background color to use for blink (default = -1)
+Blink_fg                Foreground color to use for blink (default = -1)
+Underline_bg            Background color to use for underline (default = -1)
+Underline_fg            Foreground color to use for underline (default = -1)
+UlBlink_bg              Background color to use for blink+uline (default = -1)
+UlBlink_fg              Foreground color to use for blink+uline (default = -1)
+
+Setting the following to -1 uses colors detected at startup:
+Normal_bg               Normal text background color (default = -1)
+Normal_fg               Normal text foreground color (default = -1)
+
+Please do not set these values to -1:
+Scroll_bg               Background color for scrollback mode (default = 0)
+Scroll_fg               Foreground color for scrollback mode (default = 7)
+Status_bg               Bg color of status line in scrollback (default = 1)
+Status_fg               Fg color of status line in scrollback (default = 15)
+
+Here's a list of colors:
+0 - black, 1 - blue, 2 - green, 3 - cyan, 4 - red, 5 - magenta, 6 - brown
+7 - lt. grey (dk. white), 8 - dk. grey, 9 - bright blue, 10 - bright green,
+11 - bright cyan, 12 - bright red, 13 - bright magenta, 14 - yellow
+15 - bright white
+
+[Mouse] section
+
+Enable_Mouse
+Turns on mouse support.  (Default = TRUE)
+
+[Printer] section
+
+Printer_Name
+The DOS name for the printer.  (Default = LPT1)
+
+[Keyboard] section
+Many of these options are also available from telnet.cfg.
+
+Escape_key
+The key to break out of a telnet session.  (Default = ])
+
+Scrollback_key
+The key for switching to scrollback mode.  (Default = [)
+
+Dial_key
+You can start a new telnet session with this key.  (Default = \)
+
+Alt_erase
+If you set this to true, it will swap backspace and delete.
+(Default = FALSE)
+
+Keyboard_paste
+This option allows pasting to the screen via shift-insert.  (Default = FALSE)
+
+Keyfile
+Selects an alternate telnet.cfg file.  (Default = TELNET.CFG)
+
+Default_Config
+Selects a different keyboard definition.  All of these are defined in
+telnet.cfg.
+
+[Scrollback] section
+
+Scroll_Mode
+Selects the default mode for scrollback.  Valid selections are:
+        HEX             Hex dump
+        DUMP            Dump, control characters are shown as "."
+        DUMPB           Binary dump
+        TEXT            Text mode
+Note: you can press TAB in scrollback mode to cycle through these.
+(Default = DUMP)
+
+Command-line Options
+--------------------
+
+-d<filename>    Specifies the name of the dumpfile.
+-h             Gives a help screen.
diff --git a/reactos/apps/utils/net/telnet/doc/readme.txt b/reactos/apps/utils/net/telnet/doc/readme.txt
new file mode 100644 (file)
index 0000000..abebe34
--- /dev/null
@@ -0,0 +1,280 @@
+              **************************************************
+              ** Console Telnet v2.1b2 README.TXT 16 Oct 2000 **
+              **************************************************
+
+                               RELEASE NOTES:
+                               --------------
+
+This release of TELNET is a beta one. This means that it is working as far
+as it is tested, and has a few bugs. Hopefully this will be a stable
+version.  Please send comments and bug reports to me at
+pbranna@clemson.edu, or to the mailing list (see below).  See file
+CHANGES.TXT for a detailed log of changes.  See file BUGS.TXT for known
+bugs.
+
+                                DESCRIPTION:
+                                ------------
+
+This is a telnet client with full color ANSI support for Windows NT/95
+console. You can use this program from the Win95 command line (MsDos) and
+run it in full screen text mode. You may also redirect the telnet session
+to STDIN and STDOUT for use with other programs.  Telnet will communicate
+the number of lines and rows to the host, and can operate in any console
+mode.  Most of it's options are customizable.
+
+
+                         COPYRIGHT/LICENSE/WARRANTY
+                         --------------------------
+
+Telnet Win32, Copyright (C) 1996-1997, Brad Johnson <jbj@nounname.com>
+Copyright (C) 1998 I.Ioannou, Copyright (C) 1999-2000 Paul Brannan.  Telnet
+is a free project released under the GNU public license.  This program comes
+with ABSOLUTELY NO WARRANTY.  This is free software, and you are welcome
+to redistribute it under the licence contitions.  See LICENSE.TXT for
+details.
+
+                                REQUIREMENTS:
+                                -------------
+
+This program requires a Microsoft Win32 enviroment (Windows 95/98/NT) with
+Winsock TCP/IP.  16 bit Win3.x or Win32s are not supported.
+
+                                  FEATURES:
+                                  ---------
+
+Full ANSI colors and (almost) complete ANSI emulation.
+User configurable options via telnet.ini.
+User configurable key bindings with alternative keyboards.
+Icoming character translations.
+Redirection of telnet session.
+Telnet output can be dumped to a file.
+Local printer support.
+Basic scrollback support.
+Basic VT emulation.
+Mouse support.
+Clipboard (cut-and-paste) support.
+Support for multiple screen sizes.
+
+                              WHERE TO GET IT:
+                              ----------------
+
+Since version 2.0, Console Telnet's new home page is
+http://www.musc.edu/~brannanp/telnet/.  You can get the latest version from
+ftp://argeas.cs-net.gr/Telnet-Win32 or from the web page.  Telnet is
+available as full project (sources included) or as binaries only.  If you
+would like to help to the development check the /devel directory on the ftp
+site for a recent alpha version.
+
+                                MAILING LIST:
+                                -------------
+
+Telnet has it's own mailing list for announcements, bug reports, support,
+suggestions etc. To subscribe send e-mail to majordomo@argeas.cs-net.gr
+with empty Subject, and the word subscribe in the body. List's address is
+telnet-win32@argeas.cs-net.gr You can find the old archives at
+http://www.cs-net.gr/lists
+
+If you are only interested in announcements, follow the above procedures to
+subscribe to telnet-win32-announce.  The development list is
+telnet-win32-devel.
+
+                                HOW TO HELP:
+                                ------------
+
+Telnet is a free project made from volunteers. If you know C/C++ and would
+like to help in the development you are welcome :-)  Just contact
+pbranna@clemson.edu, and/or subscribe to the mailing list.  Check
+ftp://argeas.cs-net.gr/Telnet-Win32/devel for a recent alpha version.
+
+
+                                INSTALLATION
+                                ------------
+
+Just copy telnet.exe, telnet.ico, telnet.ini and keys.cfg to a directory.
+I prefer a directory included in the PATH (such as C:\WINDOWS, but this will
+overwrite the telnet that comes with Windows -- which is not necessarily a
+bad thing). If you are upgrading from a previous version please look below
+(Key file definitions) : the keys.cfg file has changed a bit. Also look at
+the Configuration section below, TELNET now has a ini file.
+
+                                   USAGE:
+                                   -------
+
+  TELNET
+    Begins telnet and enters telnet> command line.
+
+  TELNET [params][host [port]]
+    Connects to port on host. Port defaults to 23 for TELNET.
+
+    params    -d FILENAME.EXT    Dumps all incoming data to FILENAME.EXT
+                                 Note lowercase 'd'.
+              --variable=value   Overrides ini variable to be set to value.
+
+    host                         Host name or IP to connect to
+    port                         Service port to open connection on
+                                 (default is telnet port 23).
+
+  TELNET -?
+    Gives usage information.
+
+Pressing the escape key (default ALT-]) will break out of a telnet session and
+return you to the telnet> prompt. Pressing return will resume your session.
+All the options are available from the telnet> prompt. Type ? to get help.
+
+Pressing the scrollback key (default ALT-[) will give you a basic scrollback
+view. Pressing ESC will resume your session.
+
+                                   BUGS:
+                                   -----
+
+There are :-). Hopefully this version is more stable than the previous. See
+BUGS.TXT, and grep for FIX ME's in the sources. Any help ?
+
+                                   NOTES:
+                                   ------
+
+If the environment variable LANG has a valid value (e.g. LANG=de for German
+characters) and the file LOCALE.DLL is installed somewhere along the PATH
+TELNET will not ignore local characters.
+
+If you have problems with paste under Win 95 try unchecking the fast paste
+option in the MsDos properties. The paste function works correctly under NT.
+This is a Microsoft bug :-)
+
+                                CONFIGURATION
+                                -------------
+
+The configuration is made through telnet.ini and keys.cfg. These files (at
+least telnet.ini) must be in the same directory which telnet.exe is.  The
+basic options are loaded from the file telnet.ini. If you are having problems
+with a terminal setting, check the file OPTIONS.TXT for configuration
+information.
+
+
+Key file definitions (telnet.cfg)
+-------------------------------
+
+Use the key file (telnet.cfg) to define the characters that telnet is sending
+to the host.  From version 2b5 you can configure the output keys (KEYMAP
+sections), the input character translations (CHARMAP sections) and you can
+combine all to as many configurations as you like (CONFIG sections). You
+can also have alternative keymaps in a configuration, and keys to switch
+between them.  See the comments in keys.cfg for details.
+
+NOTE: if you are upgrading from a previous version you must put your old keys
+in the KEYMAP sections.
+Please send any national specific keymaps / charmaps / configurations to be
+included to the next version.
+
+
+                              HOW TO COMPILE IT
+                             -------------------
+
+Telnet compiles with a variety of compilers.  You will need at least
+Borland 4.x or newer compiler, or MSVC 2.0 or newer, or download a version
+of gcc for Win32 (see http://www.musc.edu/~brannanp/telnet/gccwin32.html).
+Copy the files from the directories BORLAND or MSVC to the main directory,
+change them to fit to your system, and recompile.  The project comes with
+IDE files and makefiles.
+
+Follow the instructions for your compiler to compile telnet.  A Makefile
+for use with mingw32 or other gcc variants has been included, so if you have
+gcc, you can just type "make" at the command line.
+
+                               SPECIAL THANKS:
+                               ---------------
+
+Many people have worked for this project. Please forgive me (and let me
+know!) if I have forgotten anyone. We all thank them :-)
+
+Igor Milavec <igor.milavec@uni-lj.si>
+        Original Author of version 1.1
+        Igor wrote the basic telnet program and released it to public.
+
+Brad Johnson <jbj@nounname.com>  http://nounname.com
+        Author of versions 2.0b to 2b4. Brad has wrote plenty of code for
+        telnet like ansi colors, emulation, scrollback option, and many
+        others.
+
+Titus_Boxberg@public.uni-hamburg.de
+        Ansi emulation improvements
+        German keyboard configuration
+
+I.Ioannou roryt@hol.gr
+        KeyTranslator class (version 2b3)
+        Maintainer (since version 2b5)
+
+Andrei V. Smilianets <smile@head.aval.kiev.ua> (version 2b5)
+        KeyTranslator class (version 2b5)
+        Prompt improvments
+
+Paul Brannan <pbranna@clemson.edu>
+        Telnet.ini author, MSVC port, speed improvements, VT support,
+        and many others.
+        Maintainer (since version 2b6)
+
+Leo Leibovici <leo.leibovici@nouveau.co.uk>
+        Fixed some crashes in the ANSI parser
+        Wrote UK keymap
+
+Dmitry Lapenkov <dl@bis.msk.su>
+        Wrote AT386 keymaps
+        Improved telnet icon
+
+Thomas Briggs <tbriggs@qmetric.com>
+        Fixed problem with Ctrl-Break
+        Added suspend and fast quit options to the command line
+        Error messages for unable to load ini file
+        Fixed bug w/ getting name of executable
+
+BK Oxley
+        Fixed TELNET_INI environment variable
+
+Sam Robertson
+        Fixed compilation problems with MSVC6
+        Bugfix with telnet crashing at exit
+
+Vassili Bourdo <vassili_bourdo@softhome.net>
+        Keyboard initialization improvements
+
+Craig Davidson <crn@ozemail.com.au>
+        Bugfixes for telnet prompt
+        Added suspend telnet option
+        Set port number using name rather than number
+
+Pedro Gutierrez <paag@coppi.tid.es>
+        Save/restore console title
+        Bugfix w/ character mapping
+
+Daniel Straub <Daniel.Straub@nbgm.siemens.de>
+        Bugfix with telnet crashing at exit
+
+Jose Cesar Otero Rodriguez <jcotero@las.es>
+        Spanish Keyboard definition
+        Cursor size sequences
+
+Bryan Montgomery <monty@english.net>
+        Added CtrlBreak_as_CtrlC option
+        Added Scroll_Enable option
+
+Adi Seiker
+        Added Set_Title ini file option
+
+Craig Nellist
+        Updated Winsock error messages
+        Sleeping while thread paused, to give up CPU time
+        Command-line history
+
+Jakub Sterba
+        Czech keyboard definition
+
+Ziglio Frediano
+        MTE (Meridian Terminal) Support
+
+Mark Miesfield
+       Fixed redirection
+       Wrote documentation for redirection
+
+---
+
+Paul Brannan <pbranna@clemson.edu>
diff --git a/reactos/apps/utils/net/telnet/doc/ssh.txt b/reactos/apps/utils/net/telnet/doc/ssh.txt
new file mode 100644 (file)
index 0000000..077d79b
--- /dev/null
@@ -0,0 +1,22 @@
+It should be possible to add ssh support to console telnet, as console telnet has a very modular design when it comes to the networking code.  There is already support for pipes, and if there exists an ssh client for Win32 that will output to stdout, then you're in business.  I'm yet to find such a client, but if one existed, an SSH session could be started like so:
+
+C:\> telnet
+Copyright message, license.txt, stuff, etc.
+telnet> set io_netpipe "C:\BIN\SSH.EXE -l username host"
+telnet> open blah
+login:
+password:
+
+Unfortunately, all the ssh clients I've found don't work this way.  You can output CMD.EXE to telnet this way, though, and get a very pretty ansi interpreter.  If you want to try to get OpenSSH working, here's step-by-step instructions to get you started (please read them all the way though):
+
+1) Get Perl from http://www.activestate.com/ActivePerl/download.htm
+2) Get Openssl from http://www.openssl.org/source/
+   - Follow directions in INSTALL.W32
+   - Copy the .LIB files from OUT32DLL to your LIB directory (C:\DevStudio\VC\LIB)
+   - Copy the .DLL files from OUT32DLLto your system directory (C:\Winnt\System32 or C:\Windows\System)
+   - Copy the .H files from INC32\OPENSSL to your include\ssl (C:\DevStudio\VC\include\ssl)
+   - Copy these same files to include\openssl (C:\DevStudio\VC\include\openssl)
+3) Get Openssh from http://www.openssh.com
+4) Modify Openssh so it will compile, and get rid of all the termios stuff
+
+Obviously this is a lot of work.  If you need a good ssh client, try PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/.  It may be possible to integrate PuTTY and Telnet, and that would certainly be easier than the above option.  PuTTY is licensed under the MIT license, which seems to be compatible with the GPL.  The primary advantage of integrating the two projects is that PuTTY would gain the key mappings that telnet has, and telnet would gain encryption.
\ No newline at end of file
diff --git a/reactos/apps/utils/net/telnet/helpsock.cpp b/reactos/apps/utils/net/telnet/helpsock.cpp
deleted file mode 100644 (file)
index a7a6b65..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* $Id: helpsock.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
- *
- * FILE       : helpsock.cpp
- * AUTHOR     : unknown (sources found on www.telnet.org)
- * PROJECT    : ReactOS Operating System
- * DESCRIPTION: telnet client for the W32 subsystem
- * DATE       : 2001-01-21
- * REVISIONS
- *     2001-02-21 ea   Modified to compile under 0.0.16 src tree
- */
-#include <winsock.h>
-#include <windows.h>
-#include <process.h>
-
-#include "telnet.h"
-
-char const* sockmsg(int ecode)
-{
-  switch(ecode)
-  {
-// programming errors
-// (should never occour in release code?)
-  case WSASYSNOTREADY: return "tcp/ip network not ready";
-  case WSAEINVAL: return "invalid winsock version";
-  case WSAVERNOTSUPPORTED: return "wrong winsock version";
-  case WSANOTINITIALISED: return "winsock not initialized";
-  case WSAEINTR: "The call was canceled";
-  case WSAEINPROGRESS: "A blocking winsock operation is in progress";
-  default: return "unknown winsock error";
-// general TCP problems
-  case WSAENETDOWN: return "winsock has detected that the network subsystem has failed";
-// GetXbyY related errors:
-  case WSAHOST_NOT_FOUND: return "Authoritative Answer Host not found";
-  case WSATRY_AGAIN: return "Non-Authoritative Host not found, or SERVERFAIL";
-  case WSANO_RECOVERY: "Nonrecoverable errors: FORMERR, REFUSED, NOTIMP";
-  case WSANO_DATA: "Valid name, no data record of requested type";
-  }
-}
-
-/* EOF */
diff --git a/reactos/apps/utils/net/telnet/main.cpp b/reactos/apps/utils/net/telnet/main.cpp
deleted file mode 100644 (file)
index 3b382b3..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* $Id: main.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
- *
- * FILE       : main.cpp
- * AUTHOR     : unknown (sources found on www.telnet.org)
- * PROJECT    : ReactOS Operating System
- * DESCRIPTION: telnet client for the W32 subsystem
- * DATE       : 2001-01-21
- * REVISIONS
- *     2001-02-21 ea   Modified to compile under 0.0.16 src tree
- *     2001-02-27 ea   If run with no argument, it asks for a hostname.
- */
-///////////////////////////////////////////////////////////////////////////////
-//
-// File:
-//        main.cpp
-// 
-// Purpose:
-//        This file provdes the main entry point for the project, and all the
-//        global scope support routines.
-//
-// Notes:
-//        This file expects to be linked without the C-Runtime. If compiling,
-//        please force the entry point symbol to be "main", and do not link in
-//        the default librarys.
-//        This means that no c-runtime functions can be used anywhere in the
-//        project. I expect this will also exclude any MFC based additions.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <winsock.h>
-#include <windows.h>
-#include <process.h>
-#include <stdlib.h>
-
-#include "telnet.h"
-
-///////////////////////////////////////////////////////////////////////////////
-
-//
-// Our simple replacement for the c-runtime includes getting the StandardInput,
-// StandardOutput & StandardError handles, and providing new and delete operators, that work
-// with the win32 heap functions.
-//
-
-//
-// standard handles needed for CRT emulation
-//
-HANDLE hHeap;
-HANDLE StandardInput;
-HANDLE StandardOutput;
-HANDLE StandardError;
-
-//
-// new will use the win32 heap functions.
-//
-void* operator new(unsigned int nSize)
-{
-  return HeapAlloc(hHeap,0,nSize);
-}
-
-//
-// delete operator provides all memory de-allocation.
-// HeapFree doesn't accept NULL.
-//
-void operator delete(void* pMem)
-{
-  if(pMem) HeapFree(hHeap,0,pMem);
-}
-
-
-
-void err(char const* s, ...)
-{
-       char    buf [1024];
-       DWORD   nout;
-       
-       wvsprintf (buf, s, (char*)(s + sizeof(int)));
-       WriteFile (StandardError,"Error: ", 7, & nout, NULL);
-       WriteFile (StandardError, buf, lstrlen(buf), & nout, NULL);
-       WriteFile (StandardError, "\r\n\r\n", 4, & nout, NULL);
-#ifdef _DEBUG
-       OutputDebugString(buf);
-       OutputDebugString("\n");
-#endif
-       ExitProcess (ERROR_SUCCESS);
-}
-
-
-int main(int argc, char * argv[])
-{
-       WSADATA wd;
-       int     errn;
-       char    name [256] = {'\0'};
-       short   port = IPPORT_TELNET; /* default tcp port */
-
-       ///////////////////////////////////////
-       // CRT emulation init
-       // Get the IO handles
-       StandardInput = GetStdHandle(STD_INPUT_HANDLE);
-       StandardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
-       StandardError = GetStdHandle(STD_ERROR_HANDLE);
-
-       // Get the heap 
-       hHeap = GetProcessHeap();
-
-       // Explicitly force the console into a good mode (actually all we are doing is turning
-       // mouse input off.
-       SetConsoleMode (
-               StandardInput,
-               (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
-               );
-
-       ///////////////////////////////////////
-       // Init winsock
-
-       if (errn = WSAStartup (0x0101, & wd))
-       {
-               err(sockmsg(errn));
-       }
-
-       /* hostname */
-       if (1 < argc)
-       {
-               lstrcpy (name, argv [1]);
-       }
-       /*
-        * Default port is IPPORT_TELNET.
-        * User may hand one.
-        */
-       if (3 == argc)
-       {
-               port = atoi (argv[2]);
-               if (port <= 0)
-               {
-                       struct servent * service = NULL;
-                       
-                       service = getservbyname (argv[2], "tcp");
-                       if (NULL == service)
-                       {
-                               err("Invalid service name specified");
-                       }
-                       port = service->s_port;
-               }
-               else
-               {
-                       err("Invalid port specified");
-               }
-       }
-       /* Too many arguments */
-       if (3 < argc)
-       {
-               err("Usage: telnet <hostname> [<port>]");
-       }
-       /* No argument */
-       if (1 == argc)
-       {
-               DWORD Count;
-               char *c;
-               
-               WriteFile (StandardError,"host: ", 6, & Count, NULL);
-               ReadFile (StandardInput, name, sizeof name, & Count, NULL);
-               c = name;
-               while (*c > ' ') ++ c;
-               *c = '\0';
-       }
-
-       // guess what this does.
-       telnet (name, port);
-
-       //Bye bye...
-       WSACleanup ();
-
-       // Exit process terminates any waiting threads.
-       // (Its the CRT that makes a process close when the main thread exits.
-       // The WinAPI will leave the process as is for as long as it has a 
-       // thread any thread.
-       ExitProcess (EXIT_SUCCESS);
-}
-
-/* EOF */
diff --git a/reactos/apps/utils/net/telnet/nvt.cpp b/reactos/apps/utils/net/telnet/nvt.cpp
deleted file mode 100644 (file)
index a455a29..0000000
+++ /dev/null
@@ -1,296 +0,0 @@
-/* $Id: nvt.cpp,v 1.1 2001/01/27 22:38:43 ea Exp $
- *
- * FILE       : nvt.cpp
- * AUTHOR     : unknown (sources found on www.telnet.org)
- * PROJECT    : ReactOS Operating System
- * DESCRIPTION: telnet client for the W32 subsystem
- * DATE       : 2001-01-21
- * REVISIONS
- *     2001-02-21 ea   Modified to compile under 0.0.16 src tree
- */
-///////////////////////////////////////////////////////////////////////////////
-//
-// file: nvt.cpp
-// 
-// purpose: Provides the "bare bones" telnet "Network Virtual Terminal"
-//          that is our default. We only se a more capable terminal, if
-//          properly requested via the telnet option.
-//
-// refrence: The following excerpt from rfc 854
-//
-///////////////////////////////////////////////////////////////////////////////
-/*
-THE NETWORK VIRTUAL TERMINAL
-   The Network Virtual Terminal (NVT) is a bi-directional character
-   device.  The NVT has a printer and a keyboard.  The printer responds
-   to incoming data and the keyboard produces outgoing data which is
-   sent over the TELNET connection and, if "echoes" are desired, to the
-   NVT's printer as well.  "Echoes" will not be expected to traverse the
-   network (although options exist to enable a "remote" echoing mode of
-   operation, no host is required to implement this option).  The code
-   set is seven-bit USASCII in an eight-bit field, except as modified
-   herein.  Any code conversion and timing considerations are local
-   problems and do not affect the NVT.
-   TRANSMISSION OF DATA
-      Although a TELNET connection through the network is intrinsically
-      full duplex, the NVT is to be viewed as a half-duplex device
-      operating in a line-buffered mode.  That is, unless and until
-      options are negotiated to the contrary, the following default
-      conditions pertain to the transmission of data over the TELNET
-      connection:
-         1)  Insofar as the availability of local buffer space permits,
-         data should be accumulated in the host where it is generated
-         until a complete line of data is ready for transmission, or
-         until some locally-defined explicit signal to transmit occurs.
-         This signal could be generated either by a process or by a
-         human user.
-         The motivation for this rule is the high cost, to some hosts,
-         of processing network input interrupts, coupled with the
-         default NVT specification that "echoes" do not traverse the
-         network.  Thus, it is reasonable to buffer some amount of data
-         at its source.  Many systems take some processing action at the
-         end of each input line (even line printers or card punches
-         frequently tend to work this way), so the transmission should
-         be triggered at the end of a line.  On the other hand, a user
-         or process may sometimes find it necessary or desirable to
-         provide data which does not terminate at the end of a line;
-         therefore implementers are cautioned to provide methods of
-         locally signaling that all buffered data should be transmitted
-         immediately.
-         2)  When a process has completed sending data to an NVT printer
-         and has no queued input from the NVT keyboard for further
-         processing (i.e., when a process at one end of a TELNET
-         connection cannot proceed without input from the other end),
-         the process must transmit the TELNET Go Ahead (GA) command.
-         This rule is not intended to require that the TELNET GA command
-         be sent from a terminal at the end of each line, since server
-         hosts do not normally require a special signal (in addition to
-         end-of-line or other locally-defined characters) in order to
-         commence processing.  Rather, the TELNET GA is designed to help
-         a user's local host operate a physically half duplex terminal
-         which has a "lockable" keyboard such as the IBM 2741.  A
-         description of this type of terminal may help to explain the
-         proper use of the GA command.
-         The terminal-computer connection is always under control of
-         either the user or the computer.  Neither can unilaterally
-         seize control from the other; rather the controlling end must
-         relinguish its control explicitly.  At the terminal end, the
-         hardware is constructed so as to relinquish control each time
-         that a "line" is terminated (i.e., when the "New Line" key is
-         typed by the user).  When this occurs, the attached (local)
-         computer processes the input data, decides if output should be
-         generated, and if not returns control to the terminal.  If
-         output should be generated, control is retained by the computer
-         until all output has been transmitted.
-         The difficulties of using this type of terminal through the
-         network should be obvious.  The "local" computer is no longer
-         able to decide whether to retain control after seeing an
-         end-of-line signal or not; this decision can only be made by
-         the "remote" computer which is processing the data.  Therefore,
-         the TELNET GA command provides a mechanism whereby the "remote"
-         (server) computer can signal the "local" (user) computer that
-         it is time to pass control to the user of the terminal.  It
-         should be transmitted at those times, and only at those times,
-         when the user should be given control of the terminal.  Note
-         that premature transmission of the GA command may result in the
-         blocking of output, since the user is likely to assume that the
-         transmitting system has paused, and therefore he will fail to
-         turn the line around manually.
-      The foregoing, of course, does not apply to the user-to-server
-      direction of communication.  In this direction, GAs may be sent at
-      any time, but need not ever be sent.  Also, if the TELNET
-      connection is being used for process-to-process communication, GAs
-      need not be sent in either direction.  Finally, for
-      terminal-to-terminal communication, GAs may be required in
-      neither, one, or both directions.  If a host plans to support
-      terminal-to-terminal communication it is suggested that the host
-      provide the user with a means of manually signaling that it is
-      time for a GA to be sent over the TELNET connection; this,
-      however, is not a requirement on the implementer of a TELNET
-      process.
-      Note that the symmetry of the TELNET model requires that there is
-      an NVT at each end of the TELNET connection, at least
-      conceptually.
-*//*
-
-   THE NVT PRINTER AND KEYBOARD
-      The NVT printer has an unspecified carriage width and page length
-      and can produce representations of all 95 USASCII graphics (codes
-      32 through 126).  Of the 33 USASCII control codes (0 through 31
-      and 127), and the 128 uncovered codes (128 through 255), the
-      following have specified meaning to the NVT printer:
-         NAME                  CODE         MEANING
-         NULL (NUL)              0      No Operation
-         Line Feed (LF)         10      Moves the printer to the
-                                        next print line, keeping the
-                                        same horizontal position.
-         Carriage Return (CR)   13      Moves the printer to the left
-                                        margin of the current line.
-         In addition, the following codes shall have defined, but not
-         required, effects on the NVT printer.  Neither end of a TELNET
-         connection may assume that the other party will take, or will
-         have taken, any particular action upon receipt or transmission
-         of these:
-         BELL (BEL)              7      Produces an audible or
-                                        visible signal (which does
-                                        NOT move the print head).
-         Back Space (BS)         8      Moves the print head one
-                                        character position towards
-                                        the left margin.
-         Horizontal Tab (HT)     9      Moves the printer to the
-                                        next horizontal tab stop.
-                                        It remains unspecified how
-                                        either party determines or
-                                        establishes where such tab
-                                        stops are located.
-         Vertical Tab (VT)       11     Moves the printer to the
-                                        next vertical tab stop.  It
-                                        remains unspecified how
-                                        either party determines or
-                                        establishes where such tab
-                                        stops are located.
-         Form Feed (FF)          12     Moves the printer to the top
-                                        of the next page, keeping
-                                        the same horizontal position.
-      All remaining codes do not cause the NVT printer to take any
-      action.
-      The sequence "CR LF", as defined, will cause the NVT to be
-      positioned at the left margin of the next print line (as would,
-      for example, the sequence "LF CR").  However, many systems and
-      terminals do not treat CR and LF independently, and will have to
-      go to some effort to simulate their effect.  (For example, some
-      terminals do not have a CR independent of the LF, but on such
-      terminals it may be possible to simulate a CR by backspacing.)
-      Therefore, the sequence "CR LF" must be treated as a single "new
-      line" character and used whenever their combined action is
-      intended; the sequence "CR NUL" must be used where a carriage
-      return alone is actually desired; and the CR character must be
-      avoided in other contexts.  This rule gives assurance to systems
-      which must decide whether to perform a "new line" function or a
-      multiple-backspace that the TELNET stream contains a character
-      following a CR that will allow a rational decision.
-         Note that "CR LF" or "CR NUL" is required in both directions
-         (in the default ASCII mode), to preserve the symmetry of the
-         NVT model.  Even though it may be known in some situations
-         (e.g., with remote echo and suppress go ahead options in
-         effect) that characters are not being sent to an actual
-         printer, nonetheless, for the sake of consistency, the protocol
-         requires that a NUL be inserted following a CR not followed by
-         a LF in the data stream.  The converse of this is that a NUL
-         received in the data stream after a CR (in the absence of
-         options negotiations which explicitly specify otherwise) should
-         be stripped out prior to applying the NVT to local character
-         set mapping.
-      The NVT keyboard has keys, or key combinations, or key sequences,
-      for generating all 128 USASCII codes.  Note that although many
-      have no effect on the NVT printer, the NVT keyboard is capable of
-      generating them.
-      In addition to these codes, the NVT keyboard shall be capable of
-      generating the following additional codes which, except as noted,
-      have defined, but not reguired, meanings.  The actual code
-      assignments for these "characters" are in the TELNET Command
-      section, because they are viewed as being, in some sense, generic
-      and should be available even when the data stream is interpreted
-      as being some other character set.
-      Synch
-         This key allows the user to clear his data path to the other
-         party.  The activation of this key causes a DM (see command
-         section) to be sent in the data stream and a TCP Urgent
-         notification is associated with it.  The pair DM-Urgent is to
-         have required meaning as defined previously.
-      Break (BRK)
-         This code is provided because it is a signal outside the
-         USASCII set which is currently given local meaning within many
-         systems.  It is intended to indicate that the Break Key or the
-         Attention Key was hit.  Note, however, that this is intended to
-         provide a 129th code for systems which require it, not as a
-         synonym for the IP standard representation.
-      Interrupt Process (IP)
-         Suspend, interrupt, abort or terminate the process to which the
-         NVT is connected.  Also, part of the out-of-band signal for
-         other protocols which use TELNET.
-
-      Abort Output (AO)
-         Allow the current process to (appear to) run to completion, but
-         do not send its output to the user.  Also, send a Synch to the
-         user.
-      Are You There (AYT)
-         Send back to the NVT some visible (i.e., printable) evidence
-         that the AYT was received.
-      Erase Character (EC)
-         The recipient should delete the last preceding undeleted
-         character or "print position" from the data stream.
-      Erase Line (EL)
-         The recipient should delete characters from the data stream
-         back to, but not including, the last "CR LF" sequence sent over
-         the TELNET connection.
-      The spirit of these "extra" keys, and also the printer format
-      effectors, is that they should represent a natural extension of
-      the mapping that already must be done from "NVT" into "local".
-      Just as the NVT data byte 68 (104 octal) should be mapped into
-      whatever the local code for "uppercase D" is, so the EC character
-      should be mapped into whatever the local "Erase Character"
-      function is.  Further, just as the mapping for 124 (174 octal) is
-      somewhat arbitrary in an environment that has no "vertical bar"
-      character, the EL character may have a somewhat arbitrary mapping
-      (or none at all) if there is no local "Erase Line" facility.
-      Similarly for format effectors:  if the terminal actually does
-      have a "Vertical Tab", then the mapping for VT is obvious, and
-      only when the terminal does not have a vertical tab should the
-
-*/
-
-#include <winsock.h>
-#include <windows.h>
-
-#include "telnet.h"
-
-void nvt(SOCKET server,unsigned char data)
-{
-  DWORD z;
-  switch(data)
-  {
-  case 0:  //eat null codes.
-    break;
-  default: //Send all else to the console.
-    WriteConsole(StandardOutput, & data, 1, & z, NULL);
-    break;
-  }
-}
-
-/* EOF */
diff --git a/reactos/apps/utils/net/telnet/resource/tnmsg.h b/reactos/apps/utils/net/telnet/resource/tnmsg.h
new file mode 100644 (file)
index 0000000..b46f8cb
--- /dev/null
@@ -0,0 +1,108 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by Tnmsg.rc
+//
+#define MSG_COPYRIGHT                   0x01
+#define MSG_COPYRIGHT_1                 0x02
+#define MSG_USAGE                       0x03
+#define MSG_USAGE_1                     0x04
+#define MSG_HELP                        0x05
+#define MSG_HELP_1                      0x06
+#define MSG_INVCMD                      0x07
+#define MSG_ERROR                       0x08
+#define MSG_INFO                        0x09
+#define MSG_WARNING                     0x0a
+#define MSG_TRYING                      0x0b
+#define MSG_CONNECTED                   0x0c
+#define MSG_TERMBYREM                   0x0d
+#define MSG_KEYMAP                      0x0e
+#define MSG_ERRKEYMAP                   0x0f
+#define MSG_DUMPFILE                    0x10
+#define MSG_CONFIG                      0x11
+#define MSG_NOINI                       0x12
+#define MSG_BADVAL                      0x13
+#define MSG_NOSPAWN                     0x14
+#define MSG_RESOLVING                                  0x15
+#define MSG_NOSERVICE                                  0x16
+#define MSG_SIZEALIAS                                  0x17
+#define MSG_ERRPIPE                                            0x18
+#define MSG_BADUSAGE                                   0x19
+#define MSG_ALREADYCONNECTED                   0x1a
+
+#define MSG_KEYNOVAL                    1001
+#define MSG_KEYBADVAL                   1002
+#define MSG_KEYBADSTRUCT                1003
+#define MSG_KEYBADCHARS                 1004
+#define MSG_KEYUNEXPLINE                1005
+#define MSG_KEYUNEXPEOF                 1006
+#define MSG_KEYUNEXPTOK                 1007
+#define MSG_KEYUNEXPTOKIN               1008
+#define MSG_KEYUNEXP                    1009
+#define MSG_KEYNOGLOBAL                 1010
+#define MSG_KEYNOCONFIG                 1011
+#define MSG_KEYUSECONFIG                1012
+#define MSG_KEYNOSWKEY                  1013
+#define MSG_KEYCANNOTDEF                1014
+#define MSG_KEYDUPSWKEY                 1015
+#define MSG_KEYUNKNOWNMAP               1016
+#define MSG_KEYNOCHARMAPS               1017
+#define MSG_KEYNOKEYMAPS                1018
+#define MSG_KEYNUMMAPS                  1019
+#define MSG_KEYBADMAP                                  1020
+#define MSG_KEYMAPSWITCHED                             1021
+
+#define MSG_WSAEINTR                    0x2714
+#define MSG_WSAEBADF                    0x2719
+#define MSG_WSAEACCESS                  0x271D
+#define MSG_WSAEDEFAULT                 0x271E
+#define MSG_WSAEINVAL                   0x2726
+#define MSG_WSAEMFILE                   0x2728
+#define MSG_WSAEWOULDBLOCK              0x2733
+#define MSG_WSAEINPROGRESS              0x2734
+#define MSG_WSAEALREADY                 0x2735
+#define MSG_WSAENOTSOCK                 0x2736
+#define MSG_WSAEDESTADDRREQ             0x2737
+#define MSG_WSAEMSGSIZE                 0x2738
+#define MSG_WSAEPROTOTYPE               0x2739
+#define MSG_WSAENOPROTOOPT              0x273A
+#define MSG_WSAEPROTONOTSUPPORT         0x273B
+#define MSG_WSAESOCKNOTSUPPORT          0x273C
+#define MSG_WSAEOPNOTSUPP               0x273D
+#define MSG_WSAEPFNOTSUPPORT            0x273E
+#define MSG_WSAEAFNOTSUPPORT            0x273F
+#define MSG_WSAEADDRINUSE               0x2740
+#define MSG_WSAEADDRNOTAVAIL            0x2741
+#define MSG_WSAENETDOWN                 0x2742
+#define MSG_WSAENETUNREACH              0x2743
+#define MSG_WSAENETRESET                0x2744
+#define MSG_WSAECONNABORTED             0x2745
+#define MSG_WSAECONNRESET               0x2746
+#define MSG_WSAENOBUFS                  0x2747
+#define MSG_WSAEISCONN                  0x2748
+#define MSG_WSAENOTCONN                 0x2749
+#define MSG_WSAESHUTDOWN                0x274A
+#define MSG_WSAETOOMANYREFS             0x274B
+#define MSG_WSAETIMEDOUT                0x274C
+#define MSG_WSAECONNREFUSED             0x274D
+#define MSG_WSAELOOP                    0x274E
+#define MSG_WSAENAMETOOLONG             0x274F
+#define MSG_WSAEHOSTDOWN                0x2750
+#define MSG_WSAEHOSTUNREACH             0x2751
+#define MSG_WSAESYSNOTREADY             0x276B
+#define MSG_WSAVERNOTSUPPORTED          0x276C
+#define MSG_WSANOTINITIALISED           0x276D
+#define MSG_WSAHOST_NOT_FOUND           0x2AF9
+#define MSG_WSATRY_AGAIN                0x2AFA
+#define MSG_WSANO_RECOVERY              0x2AFB
+#define MSG_WSANO_DATA                  0x2AFC
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        101
+#define _APS_NEXT_COMMAND_VALUE         40001
+#define _APS_NEXT_CONTROL_VALUE         1000
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif
diff --git a/reactos/apps/utils/net/telnet/resource/tnmsg.rc b/reactos/apps/utils/net/telnet/resource/tnmsg.rc
new file mode 100644 (file)
index 0000000..bb8b2fd
--- /dev/null
@@ -0,0 +1,107 @@
+#include "tnmsg.h"
+
+LANGUAGE 0,0
+
+// String Table
+STRINGTABLE DISCARDABLE 
+BEGIN
+    MSG_COPYRIGHT           "Telnet Win32 v2.1b2, Copyright (C) 2000 Paul Brannan <pbranna@clemson.edu>\nand the team.  This program comes with ABSOLUTELY NO WARRANTY; for details\nread LICENSE.TXT.  "
+    MSG_COPYRIGHT_1         "This is free software, and you are welcome to redistribute\nit under certain conditions.\n\n"
+    MSG_USAGE               "Usage: TELNET [params][host [port]]\n\n  params\n    -d:FILENAME.EXT  Dumps all incoming data to FILENAME.EXT.\n  host              Host name or IP address of the remote host to connect to.\n"
+    MSG_USAGE_1             "  port              Service port to open (default is telnet port 23).\n\n"
+    MSG_HELP                "Commands may be abbreviated.  Commands are:\n  \ncl[ose]         close current connection\nop[en]          connect to a site\nq[uit]          exit telnet\n"
+    MSG_HELP_1              "ke[ys]          changes/displays keymaps (write keys to see the options)\nse[t]           displays/alters configuration options\nz               suspend\n? h[elp]        print help information\n"
+    MSG_INVCMD              "Invalid command.  Type ? for help.\n"
+    MSG_ERROR               "%1 failed.\n"
+    MSG_INFO                "%1\n"
+    MSG_WARNING             "%1\n"
+    MSG_TRYING              "Trying %1.%2.%3.%4:%5...\n"
+    MSG_CONNECTED           "Connected to %1.  Escape key is ALT-%2.\n"
+    MSG_TERMBYREM           "Connection terminated.\n"
+    MSG_KEYMAP              "Loading %1 from %2.\n"
+    MSG_ERRKEYMAP           "Error loading keymap.\n"
+    MSG_DUMPFILE            "Writing output to file %1.\n"
+    MSG_CONFIG              "Loading configuration options from %1.\n"
+    MSG_NOINI               "Error loading configuration file %1.\nLoading default options.\n"
+    MSG_BADVAL              "Warning: invalid variable %1.\n"
+    MSG_NOSPAWN             "Unable to spawn process.\n"
+    MSG_RESOLVING           "Looking up host: %1..."
+    MSG_NOSERVICE           "Could not find TCP service %1.\n"
+    MSG_SIZEALIAS           "Warning: size of alias %1 is too big, ignoring.\n"
+    MSG_ERRPIPE             "Error: unable to spawn process for pipe.\n"
+    MSG_BADUSAGE            "Error: invalid usage of command.\n"
+    MSG_ALREADYCONNECTED    "Already connected to %1.\n"
+
+    MSG_WSAEINTR            "Interrupted function call.\n"
+    MSG_WSAEBADF            "WSAEBADF\n"
+    MSG_WSAEACCESS          "Permission denied.\n"
+    MSG_WSAEDEFAULT         "WSAEDEFAULT\n"
+    MSG_WSAEINVAL           "Invalid argument.\n"
+    MSG_WSAEMFILE           "Too many open files.\n"
+    MSG_WSAEWOULDBLOCK      "Resource temporalily unavailable.\n"
+    MSG_WSAEINPROGRESS      "Operation now in progress.\n"
+    MSG_WSAEALREADY         "Operation already in progress.\n"
+    MSG_WSAENOTSOCK         "Socket operation on non-socket.\n"
+    MSG_WSAEDESTADDRREQ     "Destination address required.\n"
+    MSG_WSAEMSGSIZE         "Message too long.\n"
+    MSG_WSAEPROTOTYPE       "Protocol wrong type for socket.\n"
+    MSG_WSAENOPROTOOPT      "Bad protocol option.\n"
+    MSG_WSAEPROTONOTSUPPORT "Protocol not supported.\n"
+    MSG_WSAESOCKNOTSUPPORT  "Socket type not supported.\n"
+    MSG_WSAEOPNOTSUPP       "Operation not supported.\n"
+    MSG_WSAEPFNOTSUPPORT    "Protocol family not supported.\n"
+    MSG_WSAEAFNOTSUPPORT    "Address family not supported by protocol family.\n"
+    MSG_WSAEADDRINUSE       "Address already in use.\n"
+    MSG_WSAEADDRNOTAVAIL    "Cannot assign requested address.\n"
+    MSG_WSAENETDOWN         "Network is down.\n"
+    MSG_WSAENETUNREACH      "Network is unreachable.\n"
+    MSG_WSAENETRESET        "Network dropped connection on reset.\n"
+    MSG_WSAECONNABORTED     "Software caused connection abort.\n"
+    MSG_WSAECONNRESET       "Connection reset by peer.\n"
+    MSG_WSAENOBUFS          "No buffer space available.\n"
+    MSG_WSAEISCONN          "Socket is already connected.\n"
+    MSG_WSAENOTCONN         "Socket is not connected.\n"
+    MSG_WSAESHUTDOWN        "Cannot send after socket shutdown.\n"
+    MSG_WSAETOOMANYREFS     "WSAETOOMANYREFS\n"
+    MSG_WSAETIMEDOUT        "Connection timed out.\n"
+    MSG_WSAECONNREFUSED     "Connection refused.\n"
+    MSG_WSAELOOP            "WSAELOOP\n"
+    MSG_WSAENAMETOOLONG     "Name too long.\n"
+    MSG_WSAEHOSTDOWN        "Host is down.\n"
+    MSG_WSAEHOSTUNREACH     "No route to host.\n"
+    MSG_WSAESYSNOTREADY     "Network subsystem is unavailable.\n"
+    MSG_WSAVERNOTSUPPORTED  "WINSOCK.DLL version out of range.\n"
+    MSG_WSANOTINITIALISED   "Successful WSAStartup not yet performed.\n"
+    MSG_WSAHOST_NOT_FOUND   "Host not found.\n"
+    MSG_WSATRY_AGAIN        "Non-authoritative host not found.\n"
+    MSG_WSANO_RECOVERY      "This is a non-recoverable error.\n"
+    MSG_WSANO_DATA          "Valid name, no data record of requested type.\n"
+
+    MSG_KEYNOVAL            "[GLOBAL]: No value for %1.\n"
+    MSG_KEYBADVAL           "[GLOBAL]: Bad value for %1.\n"
+    MSG_KEYBADSTRUCT        "%1: Bad structure.\n"
+    MSG_KEYBADCHARS         "%1: Bad chars? %1 -> %3.\n"
+    MSG_KEYUNEXPLINE        "Unexpected line ""%1"".\n"
+    MSG_KEYUNEXPEOF         "Unexpended end of file.\n"
+    MSG_KEYUNEXPTOK         "Unexpected token %1.\n"
+    MSG_KEYUNEXPTOKIN       "Unexpected token in %1.\n"
+    MSG_KEYUNEXP            "Unexpected end of file or token.\n"
+    MSG_KEYNOGLOBAL         "No [GLOBAL] definition!\n"
+    MSG_KEYNOCONFIG         "No [CONFIG %1].\n"
+    MSG_KEYUSECONFIG        "Use configuration: %1.\n"
+    MSG_KEYNOSWKEY          "No switch key for ""%1"".\n"
+    MSG_KEYCANNOTDEF        "You cannot define switch key for default keymap - ignored.\n"
+    MSG_KEYDUPSWKEY         "Duplicate switching key.\n"
+    MSG_KEYUNKNOWNMAP       "Unknown keymap %1.\n"
+    MSG_KEYNOCHARMAPS       "No charmaps loaded.\n"
+    MSG_KEYNOKEYMAPS        "No keymaps loaded.\n"
+    MSG_KEYNUMMAPS          "There are %1 maps.\n"
+    MSG_KEYBADMAP           "Bad keymap number - try 'keys display'\n"
+    MSG_KEYMAPSWITCHED      "keymap switched.\n"
+END
+
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+TelnetIcon ICON "telnet.ico"
+#else
+TelnetIcon ICON "../telnet.ico"
+#endif
diff --git a/reactos/apps/utils/net/telnet/src/.cvsignore b/reactos/apps/utils/net/telnet/src/.cvsignore
new file mode 100644 (file)
index 0000000..954ada3
--- /dev/null
@@ -0,0 +1,17 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.map
diff --git a/reactos/apps/utils/net/telnet/src/ansiprsr.cpp b/reactos/apps/utils/net/telnet/src/ansiprsr.cpp
new file mode 100644 (file)
index 0000000..6280147
--- /dev/null
@@ -0,0 +1,1474 @@
+///////////////////////////////////////////////////////////////////////////////
+//Telnet Win32 : an ANSI telnet client.
+//Copyright (C) 1998-2000 Paul Brannan
+//Copyright (C) 1998 I.Ioannou
+//Copyright (C) 1997 Brad Johnson
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+//I.Ioannou
+//roryt@hol.gr
+//
+///////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Module:             ansiprsr.cpp
+//
+// Contents:   ANSI parser base class
+//
+// Product:            telnet
+//
+// Revisions: August 30, 1998 Paul Brannan <pbranna@clemson.edu>
+//            July 29, 1998 pbranna@clemson.edu
+//            June 15, 1998 pbranna@clemson.edu
+//            May 19, 1998  pbranna@clemson.edu
+//            24 Dec, 1997  Andrey.V.Smilianets
+//            05. Sep.1997  roryt@hol.gr (I.Ioannou)
+//            11.May.1997   roryt@hol.gr (I.Ioannou)
+//            6.April.1997  roryt@hol.gr (I.Ioannou)
+//            5.April.1997  jbj@nounname.com
+//            30.M\84rz.1997     Titus_Boxberg@public.uni-hamburg.de
+//                   14.Sept.1996  jbj@nounname.com
+//            Version 2.0
+//
+//            13.Jul.1995      igor.milavec@uni-lj.si
+//                                       Original code
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <windows.h>
+#include <string.h>
+#include "ansiprsr.h"
+
+// The constructor now takes different arguments and initializes different
+// variables (Paul Brannan 6/15/98)
+TANSIParser::TANSIParser(TConsole &RefConsole, KeyTranslator &RefKeyTrans,
+                                                TScroller &RefScroller, TNetwork &RefNetwork,
+                                                TCharmap &RefCharmap):
+TParser(RefConsole, RefKeyTrans, RefScroller, RefNetwork, RefCharmap) {
+       Init();
+       iSavedAttributes = (unsigned char) 7;
+       // must also check to make sure the string is non-NULL
+       // (Paul Brannan 5/8/98)
+       if ((ini.get_dumpfile() != NULL) && (*ini.get_dumpfile() != '\0')){
+               dumpfile = fopen(ini.get_dumpfile(), "wb");
+       }else {
+               dumpfile = NULL;
+       }
+       InPrintMode = 0;
+       printfile = NULL;
+
+       fast_write = ini.get_fast_write(); // Paul Brannan 6/28/98
+       Scroller.init(&StripBuffer);
+}
+
+TANSIParser::~TANSIParser(){
+       if (dumpfile) fclose (dumpfile);
+       // Added I.Ioannou 06 April, 1997
+       if (printfile != NULL) fclose (printfile);
+}
+
+// Created Init() function to initialize the parser but not clear the screen
+// (Paul Brannan 9/23/98)
+void TANSIParser::Init() {
+       // Paul Brannan 6/25/98
+       map_G0 = 'B'; map_G1 = 'B';
+       Charmap.setmap(map_G0);
+       current_map = 'B';
+
+       ignore_margins = 0;
+       vt52_mode = 0;
+       print_ctrl = 0;
+       newline_mode = false;
+
+       KeyTrans.clear_ext_mode();
+
+       iSavedCurY = 0;                                                 // Reset Variables
+       iSavedCurX = 0;
+       inGraphMode = 0;
+       Console.SetScroll(-1, -1);
+       Console.Normal();                                               // Reset Attributes
+
+       // Set tabs stops
+       resetTabStops();
+}
+
+void TANSIParser::ResetTerminal() {
+       Init();
+       Console.ClearScreen();                                  // Clear Screen
+       Console.SetRawCursorPosition(0,0);              // Home Cursor
+}
+void TANSIParser::SaveCurY(int iY){
+       iSavedCurY=iY;
+}
+
+void TANSIParser::SaveCurX(int iX){
+       iSavedCurX=iX;
+}
+
+void TANSIParser::resetTabStops() {
+       for(int j = 0; j < MAX_TAB_POSITIONS; j++) {
+               tab_stops[j] = 8 + j - (j%8);
+       }
+}
+
+void TANSIParser::ConSetAttribute(unsigned char TextAttrib){
+       // Paul Brannan 5/8/98
+       // Made this go a little bit faster by changing from switch{} to an array
+       // for the colors
+       if(TextAttrib >= 30) {
+               if(TextAttrib <= 37) {
+                       Console.SetForeground(ANSIColors[TextAttrib-30]);
+                       return;
+               } else if((TextAttrib >= 40) && (TextAttrib <= 47)) {
+                       Console.SetBackground(ANSIColors[TextAttrib-40]);
+                       return;
+               }
+       }
+       
+       switch (TextAttrib){
+               // Text Attributes
+       case 0: Console.Normal();           break;      // Normal video
+       case 1: Console.HighVideo();        break;      // High video
+       case 2: Console.LowVideo();         break;      // Low video
+       case 4: Console.UnderlineOn();          break;  // Underline on (I.Ioannou)
+       case 5: Console.BlinkOn();                      break;  // Blink video
+               // Corrected by I.Ioannou 11 May, 1997
+       case 7: Console.ReverseOn();            break;  // Reverse video
+       case 8:                                                         break;  // hidden
+               // All from 10 thru 27 are hacked from linux kernel
+               // I.Ioannou 06 April, 1997
+       case 10:
+               //  I.Ioannou 04 Sep 1997 turn on/off high bit
+               inGraphMode = 0;
+               print_ctrl = 0;
+               Charmap.setmap(current_map ? map_G1:map_G0); // Paul Brannan 6/25/98
+               break; // ANSI X3.64-1979 (SCO-ish?)
+               // Select primary font,
+               // don't display control chars
+               // if defined, don't set
+               // bit 8 on output (normal)
+       case 11:
+               inGraphMode = 0;
+               print_ctrl = 1;
+               Charmap.setmap(0); // Paul Brannan 6/25/98
+               break; // ANSI X3.64-1979 (SCO-ish?)
+               // Select first alternate font,
+               // let chars < 32 be displayed
+               // as ROM chars
+       case 12:
+               inGraphMode = 1;
+               print_ctrl = 1;
+               Charmap.setmap(0); // Paul Brannan 6/25/98
+               break; // ANSI X3.64-1979 (SCO-ish?)
+               // Select second alternate font,
+               // toggle high bit before
+               // displaying as ROM char.
+               
+       case 21:                                                                        // not really Low video
+       case 22: Console.LowVideo();            break;  // but this works good also
+       case 24: Console.UnderlineOff();        break;  // Underline off
+       case 25: Console.BlinkOff();            break;  // blink off
+               // Corrected by I.Ioannou 11 May, 1997
+       case 27: Console.ReverseOff();          break;  //Reverse video off
+
+       // Mutt needs this (Paul Brannan, Peter Jordan 12/31/98)
+       // This is from the Linux kernel source
+    case 38: /* ANSI X3.64-1979 (SCO-ish?)
+                         * Enables underscore, white foreground
+                         * with white underscore (Linux - use
+                         * default foreground).
+                         */
+                       Console.UnderlineOn();
+                       Console.SetForeground(ini.get_normal_fg());
+                       break;
+       case 39: /* ANSI X3.64-1979 (SCO-ish?)
+                         * Disable underline option.
+                         * Reset colour to default? It did this
+                         * before...
+                         */
+                       Console.UnderlineOff();
+                       Console.SetForeground(ini.get_normal_fg());
+                       break;
+       case 49:
+                       Console.SetBackground(ini.get_normal_bg());
+                       break;
+
+       }
+}
+
+void TANSIParser::ConSetCursorPos(int x, int y) {
+       if(ignore_margins)
+               Console.SetRawCursorPosition(x, y);
+       else
+               Console.SetCursorPosition(x, y);
+}
+
+char* TANSIParser::GetTerminalID()
+{
+       return "\033[?1;2c";
+}
+
+// All of the Telnet protocol stuff has been moved to TTelHndl.cpp
+// This is more consistent with what OO should be
+// (Paul Brannan 6/15/98)
+
+#ifdef __BORLANDC__
+// argsused doesn't work on MSVC++
+#pragma argsused
+#endif
+
+// Use this for the VT100 flags (Paul Brannan 12/2/98)
+#define FLAG_DOLLAR            0x0001
+#define FLAG_QMARK             0x0002
+#define FLAG_GREATER   0x0004
+#define FLAG_LESS              0x0008
+#define FLAG_EXCLAM            0x0010
+#define FLAG_AMPERSAND 0x0020
+#define FLAG_SLASH             0x0040
+#define FLAG_EQUAL             0x0080
+#define FLAG_QUOTE             0x0100
+#define FLAG_OTHER             0x8000
+
+char* TANSIParser::ParseEscapeANSI(char* pszBuffer, char* pszBufferEnd)
+{
+       
+       //      The buffer contains something like <ESC>[pA
+       //      where p is an optional decimal number specifying the count by which the
+       //      appropriate action should take place.
+       //      The pointer pszBuffer points us to the p, <ESC> and [ are
+       //      already 'consumed'
+       
+       //      TITUS: Simplification of the code: Assume default count of 1 in case
+       //      there are no parameters.
+       char tmpc;
+       const int nParam = 10;  // Maximum number of parameters
+       int     iParam[nParam] = {1, 0, 0, 0, 0};       // Assume 1 Parameter, Default 1
+       int iCurrentParam = 0;
+       DWORD flag = 0;
+       int missing_param = 0;
+
+       // Get parameters from escape sequence.
+       while ((tmpc = *pszBuffer) <= '?') {
+
+               if(tmpc < '0' || tmpc > '9') {
+                       // Check for parameter delimiter.
+                       if(tmpc == ';') {
+                               // This is a hack (Paul Brannan 6/27/98)
+                               if(*(pszBuffer - 1) == '[') missing_param = iCurrentParam+1;
+                               pszBuffer++;
+                               continue;
+                       }
+
+                       // It is legal to have control characters inside ANSI sequences
+                       // (Paul Brannan 6/26/98)
+                       if(tmpc < ' ') {
+                               Console.WriteCtrlChar(tmpc);
+                               pszBuffer++;
+                               continue;
+                       }
+
+                       // A new way of handling flags (Paul Brannan 12/2/98)
+                       switch(tmpc) {
+                       case '$': flag |= FLAG_DOLLAR; break;
+                       case '?': flag |= FLAG_QMARK; break;
+                       case '>': flag |= FLAG_GREATER; break;
+                       case '<': flag |= FLAG_LESS; break;
+                       case '!': flag |= FLAG_EXCLAM; break;
+                       case '&': flag |= FLAG_AMPERSAND; break;
+                       case '/': flag |= FLAG_SLASH; break;
+                       case '=': flag |= FLAG_EQUAL; break;
+                       case '\"': flag |= FLAG_QUOTE; break;
+                       default: flag |= FLAG_OTHER; break;
+                       }
+
+                       pszBuffer++;
+               }
+
+               //  Got Numerical Parameter.
+               iParam[iCurrentParam] = strtoul(pszBuffer, &pszBuffer, 10);
+               if (iCurrentParam < nParam)
+                       iCurrentParam++;
+       }
+       
+       //~~~ TITUS: Apparently the digit is optional (look at termcap or terminfo)
+       // So: If there is no digit, assume a count of 1
+       
+       switch ((unsigned char)*pszBuffer++) {
+               // Insert Character
+               case '@':
+                       if(iParam[0] == 0) iParam[0] = 1; // Paul Brannan 9/1/98
+                       Console.InsertCharacter(iParam[0]); break;
+               // Move cursor up.
+               case 'A':
+                       if(iParam[0] == 0) iParam[0] = 1;
+                       Console.MoveCursorPosition(0, -iParam[0]); break;
+               // Move cursor down.
+               // Added by I.Ioannou 06 April, 1997
+               case 'B':
+               case 'e':
+                       if(iParam[0] == 0) iParam[0] = 1;
+                       Console.MoveCursorPosition(0, iParam[0]);
+                       break;
+               // Move cursor right.
+               // Added by I.Ioannou 06 April, 1997
+               case 'C':
+               case 'a':
+                       // Handle cursor size sequences (Jose Cesar Otero Rodriquez and
+                       // Paul Brannan, 3/27/1999)
+                       if(flag & FLAG_EQUAL) {
+                               switch(iParam[0]) {
+                               case 7: Console.SetCursorSize(50); break;
+                               case 11: Console.SetCursorSize(6); break;
+                               case 32: Console.SetCursorSize(0); break;
+                               default: Console.SetCursorSize(13);
+                               }
+                       } else {
+                               if(iParam[0] == 0) iParam[0] = 1;
+                               Console.MoveCursorPosition(iParam[0], 0);
+                               break;
+                       }
+               // Move cursor left.
+               case 'D':
+                       if(iParam[0] == 0) iParam[0] = 1;
+                       Console.MoveCursorPosition(-iParam[0], 0);
+                       break;
+               // Move cursor to beginning of line, p lines down.
+               // Added by I.Ioannou 06 April, 1997
+               case 'E': 
+                       Console.MoveCursorPosition(-Console.GetCursorX(), iParam[0]);
+                       break;
+               // Moves active position to beginning of line, p lines up
+               // Added by I.Ioannou 06 April, 1997
+               // With '=' this changes the default fg color (Paul Brannan 6/27/98)
+               case 'F':
+                       if(flag & FLAG_EQUAL)
+                               Console.setDefaultFg(iParam[0]);
+                       else
+                               Console.MoveCursorPosition(-Console.GetCursorX(), -iParam[0]);
+                       break;
+               // Go to column p
+               // Added by I.Ioannou 06 April, 1997
+               // With '=' this changes the default bg color (Paul Brannan 6/27/98)
+               case '`': 
+               case 'G': // 'G' is from Linux kernel sources
+                       if(flag & FLAG_EQUAL) {
+                               Console.setDefaultBg(iParam[0]);
+                       } else {
+                               if (iCurrentParam < 1)                  // Alter Default
+                                       iParam[0] = 0;
+                               // this was backward, and we should subtract 1 from x
+                               // (Paul Brannan 5/27/98)
+                               ConSetCursorPos(iParam[0] - 1, Console.GetCursorY());
+                       }
+                       break;
+               // Set cursor position.
+               case 'f': 
+               case 'H':
+                       if (iCurrentParam < 2 || iParam[1] < 1)
+                               iParam[1] = 1;
+                       ConSetCursorPos(iParam[1] - 1, iParam[0] - 1);
+                       break;
+               // Clear screen
+               case 'J': 
+                       if ( iCurrentParam < 1 ) iParam[0] = 0; // Alter Default
+                       switch (iParam[0]) {
+                               case 0: Console.ClearEOScreen(); break;
+                               case 1: Console.ClearBOScreen(); break;
+                               case 2:
+                                       Console.ClearScreen();
+                                       Console.SetRawCursorPosition(0, 0);
+                                       break;
+                       }
+                       break;
+               // Clear line
+               case 'K': 
+                       if (iCurrentParam < 1)                  // Alter Default
+                               iParam[0] = 0;
+                       switch (iParam[0]) {
+                               case 0: Console.ClearEOLine(); break;
+                               case 1: Console.ClearBOLine(); break;
+                               case 2: Console.ClearLine(); break;
+                       }
+                       break;
+               //  Insert p new, blank lines.
+               // Added by I.Ioannou 06 April, 1997
+               case 'L': 
+                       {
+                               // for (int i = 1; i <= iParam[0]; i++)
+                               // This should speed things up a bit (Paul Brannan 9/2/98)
+                               Console.ScrollDown(Console.GetRawCursorY(), -1, iParam[0]);
+                               break;
+                       }
+               //  Delete p lines.
+               // Added by I.Ioannou 06 April, 1997
+               case 'M': 
+                       {
+                               for (int i = 1; i <= iParam[0]; i++)
+                               // This should speed things up a bit (Paul Brannan 9/2/98)
+                               Console.ScrollDown(Console.GetRawCursorY(), -1, -1);
+                               break;
+                       }
+               // DELETE CHAR
+               case 'P': 
+                       Console.DeleteCharacter(iParam[0]);
+                       break;
+               // Scrolls screen up (down? -- PB) p lines,
+               // Added by I.Ioannou 06 April, 1997
+               // ANSI X3.64-1979 references this but I didn't
+               // found it in any telnet implementation
+               // note 05 Oct 97  : but SCO terminfo uses them, so uncomment them !!
+               case 'S': 
+                       {
+                               //for (int i = 1; i <= iParam[0]; i++)
+                               // This should speed things up a bit (Paul Brannan 9/2/98)
+                               Console.ScrollDown(-1, -1, -iParam[0]);
+                               break;
+                       }
+               // Scrolls screen up p lines,
+               // Added by I.Ioannou 06 April, 1997
+               // ANSI X3.64-1979 references this but I didn't
+               // found it in any telnet implementation
+               // note 05 Oct 97  : but SCO terminfo uses them, so uncomment them !!
+               case 'T': 
+                       {
+                               // for (int i = 1; i <= iParam[0]; i++)
+                               // This should speed things up a bit (Paul Brannan 9/2/98)
+                               Console.ScrollDown(-1, -1, iParam[0]);
+                               break;
+                       }
+               //  Erases p characters up to the end of line
+               // Added by I.Ioannou 06 April, 1997
+               case 'X': 
+                       {
+                               int iKeepX = Console.GetRawCursorX();
+                               int iKeepY = Console.GetRawCursorY();
+                               if (iParam[0] > Console.GetWidth())
+                                       iParam[0] = Console.GetWidth(); // up to the end of line
+                               for ( int i = 1; i <= iParam[0]; i++ )
+                                       Console.WriteString(" ", 1);
+                               Console.SetRawCursorPosition(iKeepX , iKeepY);
+                               break;
+                       }
+               // Go back p tab stops
+               // Added by I.Ioannou 06 April, 1997
+               // Implemented by Paul Brannan, 4/13/2000
+               case 'Z':
+                       {
+                               int x = Console.GetCursorX();
+                               for(int j = 0; x > 0 && j < iParam[0]; j++)
+                                       while(x > 0 && tab_stops[j] == tab_stops[x]) x--;
+                               Console.SetCursorPosition(x, Console.GetCursorY());
+                       }
+                       break;
+               // Get Terminal ID
+               case 'c': 
+                       {
+                               char* szTerminalId = GetTerminalID();
+                               Network.WriteString(szTerminalId, strlen(szTerminalId));
+                               break;
+                       }
+               // TITUS++ 2. November 1998: Repeat Character.
+               case 'b':
+                       // isprint may be causing problems (Paul Brannan 3/27/99)
+                       // if ( isprint(last_char) ) {
+                               char    buf[150];       // at most 1 line (max 132 chars)
+
+                               if ( iParam[0] > 149 ) iParam[0] = 149;
+                               memset(buf, last_char, iParam[0]);
+                               buf[iParam[0]] = 0;
+                               if ( fast_write )
+                                       Console.WriteStringFast(buf, iParam[0]);
+                               else
+                                       Console.WriteString(buf, iParam[0]);
+                       // } /* IF */
+               break;
+               // Go to line p
+               // Added by I.Ioannou 06 April, 1997
+               case 'd': 
+                       if (iCurrentParam < 1)                  // Alter Default
+                               iParam[0] = 0;
+                       // this was backward, and we should subtract 1 from y
+                       // (Paul Brannan 5/27/98)
+                       ConSetCursorPos(Console.GetCursorX(), iParam[0] - 1);
+                       break;
+               // iBCS2 tab erase
+               // Added by I.Ioannou 06 April, 1997
+               case 'g': 
+                       if (iCurrentParam < 1)                  // Alter Default
+                               iParam[0] = 0;
+                       switch (iParam[0]) {
+                               case 0:
+                                       {
+                                               // Clear the horizontal tab stop at the current active position
+                                               for(int j = 0; j < MAX_TAB_POSITIONS; j++) {
+                                                       int x = Console.GetCursorX();
+                                                       if(tab_stops[j] == x) tab_stops[j] = tab_stops[x + 1];
+                                               }
+                                       }
+                                       break;
+                               case 2:
+                                       // I think this might be "set as default?"
+                                       break;
+                               case 3:
+                                       {
+                                               // Clear all tab stops
+                                               for(int j = 0; j < MAX_TAB_POSITIONS; j++)
+                                                       tab_stops[j] = -1;
+                                       }
+                                       break;
+                       }
+                       break;
+               // Set extended mode
+               case 'h': 
+                       {
+                               for (int i = 0; i < iCurrentParam; i++) {
+                                       // Changed to a switch statement (Paul Brannan 5/27/98)
+                                       if(flag & FLAG_QMARK) {
+                                               switch(iParam[i]) {
+                                                       case 1: // App cursor keys
+                                                               KeyTrans.set_ext_mode(APP_KEY);
+                                                               break;
+                                                       case 2: // VT102 mode
+                                                               vt52_mode = 0;
+                                                               KeyTrans.unset_ext_mode(APP2_KEY);
+                                                               break;
+                                                       case 3: // 132 columns
+                                                               if(ini.get_wide_enable()) {
+                                                                       Console.SetWindowSize(132, -1);
+                                                               }
+                                                               break;
+                                                       case 4: // smooth scrolling
+                                                               break;
+                                                       case 5: // Light background
+                                                               Console.Lightbg();
+                                                               break;
+                                                       case 6: // Stay in margins
+                                                               ignore_margins = 0;
+                                                               break;
+                                                       case 7:
+                                                               Console.setLineWrap(true);
+                                                               break;
+                                                       case 8: // Auto-repeat keys
+                                                               break;
+                                                       case 18: // Send FF to printer
+                                                               break;
+                                                       case 19: // Entire screen legal for printer
+                                                               break;
+                                                       case 25: // Visible cursor
+                                                               break;
+                                                       case 66: // Application numeric keypad
+                                                               break;
+                                                       default:
+#ifdef DEBUG
+                                                               Console.Beep();
+#endif
+                                                               break;
+                                               }
+                                       } else {
+                                               switch(iParam[i]) {
+                                                       case 2: // Lock keyboard
+                                                               break;
+                                                       case 3: // Act upon control codes (PB 12/5/98)
+                                                               print_ctrl = 0;
+                                                               break;
+                                                       case 4: // Set insert mode
+                                                               Console.InsertMode(1);
+                                                               break;
+                                                       case 12: // Local echo off
+                                                               break;
+                                                       case 20: // Newline sends cr/lf
+                                                               KeyTrans.set_ext_mode(APP4_KEY);
+                                                               newline_mode = true;
+                                                               break;
+                                                       default:
+#ifdef DEBUG
+                                                               Console.Beep();
+#endif
+                                                               break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               // Print Screen
+               case 'i': 
+                       if (iCurrentParam < 1)
+                               iParam[0]=0;
+                       switch (iParam[0]){
+                               case 0: break; // Print Screen
+                               case 1: break; // Print Line
+                               // Added I.Ioannou 06 April, 1997
+                               case 4:
+                                       // Stop Print Log
+                                       InPrintMode = 0;
+                                       if ( printfile != NULL )
+                                               fclose(printfile);
+                                       break;
+                               case 5:
+                                       // Start Print Log
+                                       printfile = fopen(ini.get_printer_name(), "ab");
+                                       if (printfile != NULL) InPrintMode = 1;
+                                       break;
+                       }
+                       break;
+               // Unset extended mode
+               case 'l': 
+                       {
+                               for (int i = 0; i < iCurrentParam; i++) {
+                                       // Changed to a switch statement (Paul Brannan 5/27/98)
+                                       if(flag & FLAG_QMARK) {
+                                               switch(iParam[i]) {
+                                                       case 1: // Numeric cursor keys
+                                                               KeyTrans.unset_ext_mode(APP_KEY);
+                                                               break;
+                                                       case 2: // VT52 mode
+                                                               vt52_mode = 1;
+                                                               KeyTrans.set_ext_mode(APP2_KEY);
+                                                               break;
+                                                       case 3: // 80 columns
+                                                               if(ini.get_wide_enable()) {
+                                                                       Console.SetWindowSize(80, -1);
+                                                               }
+                                                               break;
+                                                       case 4: // jump scrolling
+                                                               break;
+                                                       case 5: // Dark background
+                                                               Console.Darkbg();
+                                                               break;
+                                                       case 6: // Ignore margins
+                                                               ignore_margins = 1;
+                                                               break;
+                                                       case 7:
+                                                               Console.setLineWrap(false);
+                                                               break;
+                                                       case 8: // Auto-repeat keys
+                                                               break;
+                                                       case 19: // Only send scrolling region to printer
+                                                               break;
+                                                       case 25: // Invisible cursor
+                                                               break;
+                                                       case 66: // Numeric keypad
+                                                               break;
+                                                       default:
+#ifdef DEBUG
+                                                               Console.Beep();
+#endif
+                                                               break;
+                                               }
+                                       } else {
+                                               switch(iParam[i]) {
+                                                       case 2: // Unlock keyboard
+                                                               break;
+                                                       case 3: // Display control codes (PB 12/5/98)
+                                                               print_ctrl = 1;
+                                                               break;
+                                                       case 4: // Set overtype mode
+                                                               Console.InsertMode(0);
+                                                               break;
+                                                       case 12: // Local echo on
+                                                               break;
+                                                       case 20: // sends lf only
+                                                               KeyTrans.unset_ext_mode(APP4_KEY);
+                                                               newline_mode = false;
+                                                               break;
+                                                       default:
+#ifdef DEBUG
+                                                               Console.Beep();
+#endif
+                                                               break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               // Set color
+               case 'm':
+                       if(missing_param) Console.Normal();
+                       if(iCurrentParam == 0) {
+                               Console.Normal();
+                       } else {
+                               for(int i = 0; i < iCurrentParam; i++)
+                                       ConSetAttribute(iParam[i]);
+                       }
+                       break;
+               // report cursor position Row X Col
+               case 'n': 
+                       if (iCurrentParam == 1 && iParam[0]==5) {
+                               // report the cursor position
+                               Network.WriteString("\x1B[0n", 6);
+                               break;
+                       }
+                       if (iCurrentParam == 1 && iParam[0]==6){
+                               // report the cursor position
+                               // The cursor position needs to be sent as a single string
+                               // (Paul Brannan 6/27/98)
+                               char szCursorReport[40] = "\x1B[";
+
+                               itoa(Console.GetCursorY() + 1,
+                                       &szCursorReport[strlen(szCursorReport)], 10);
+                               strcat(szCursorReport, ";");
+                               itoa(Console.GetCursorX() + 1,
+                                       &szCursorReport[strlen(szCursorReport)], 10);
+                               strcat(szCursorReport, "R");
+
+                               Network.WriteString(szCursorReport, strlen(szCursorReport));
+               
+                       }
+                       break;
+               // Miscellaneous weird sequences (Paul Brannan 6/27/98)
+               case 'p':
+                       // Set conformance level
+                       if(flag & FLAG_QUOTE) {
+                               break;
+                       }
+                       // Soft terminal reset
+                       if(flag & FLAG_EXCLAM) {
+                               break;
+                       }
+                       // Report mode settings
+                       if(flag & FLAG_DOLLAR) {
+                               break;
+                       }
+                       break;
+               // Scroll Screen
+               case 'r': 
+                       if (iCurrentParam < 1) {
+                               // Enable scrolling for entire display
+                               Console.SetScroll(-1, -1);
+                               break;
+                       }
+                       if (iCurrentParam >1) {
+                               // Enable scrolling from row1 to row2
+                               Console.SetScroll(iParam[0] - 1, iParam[1] - 1);
+                               // If the cursor is outside the scrolling range, fix it
+                               // (Paul Brannan 6/26/98)
+                               // if(Console.GetRawCursorY() < iParam[0] - 1) {
+                               //      Console.SetRawCursorPosition(Console.GetCursorX(),
+                               //              iParam[0] - 1);
+                               // }
+                               // if(Console.GetRawCursorY() > iParam[1] - 1) {
+                               //      Console.SetRawCursorPosition(Console.GetCursorX(),
+                               //              iParam[1] - 1);
+                               // }
+                       }
+                       // Move the cursor to the home position (Paul Brannan 12/2/98)
+                       Console.SetCursorPosition(0, 0);
+                       break;
+               // Save cursor position
+               case 's': 
+                       SaveCurY(Console.GetRawCursorY());
+                       SaveCurX(Console.GetRawCursorX());
+                       break;
+               // Restore cursor position
+               case 'u': 
+                       Console.SetRawCursorPosition(iSavedCurX, iSavedCurY);
+                       break;
+               // DEC terminal report (Paul Brannan 6/28/98)
+               case 'x':
+                       if(iParam[0])
+                               Network.WriteString("\033[3;1;1;128;128;1;0x", 20);
+                       else
+                               Network.WriteString("\033[2;1;1;128;128;1;0x", 20);
+                       break;
+               default:
+#ifdef DEBUG
+                       Console.Beep();
+#endif
+                       break;
+       }
+
+       return pszBuffer;
+}
+
+#ifdef MTE_SUPPORT
+// Added by Frediano Ziglio, 5/31/2000
+// MTE extension
+// initially copied from ParseEscapeANSI
+char* TANSIParser::ParseEscapeMTE(char* pszBuffer, char* pszBufferEnd)
+{
+       //      The buffer contains something like <ESC>~pA
+       //      where p is an optional decimal number specifying the count by which the
+       //      appropriate action should take place.
+       //      The pointer pszBuffer points us to the p, <ESC> and ~ are
+       //      already 'consumed'
+       //      TITUS: Simplification of the code: Assume default count of 1 in case
+       //      there are no parameters.
+       char tmpc;
+       const int nParam = 10;  // Maximum number of parameters
+       int     iParam[nParam] = {1, 0, 0, 0, 0};       // Assume 1 parameter, Default 1
+       int iCurrentParam = 0;
+       char sRepeat[2];
+       
+       // Get parameters from escape sequence.
+       while ((tmpc = *pszBuffer) <= '?') {
+               if(tmpc < '0' || tmpc > '9') {
+                       // Check for parameter delimiter.
+                       if(tmpc == ';') {
+                               pszBuffer++;
+                               continue;
+                       }
+                       pszBuffer++;
+               }
+               
+               //  Got Numerical Parameter.
+               iParam[iCurrentParam] = strtoul(pszBuffer, &pszBuffer, 10);
+               if (iCurrentParam < nParam)
+                       iCurrentParam++;
+       }
+       
+       //~~~ TITUS: Apparently the digit is optional (look at termcap or terminfo)
+       // So: If there is no digit, assume a count of 1
+       
+       switch ((unsigned char)*pszBuffer++) {
+               case 'A':
+                       // set colors
+                       if (iCurrentParam < 2 )
+                               break;
+                       if (iParam[0] <= 15 && iParam[1] <= 15)
+                               Console.SetAttrib( (iParam[1] << 4) | iParam[0] );
+                       break;
+                       
+               case 'R':
+                       // define region
+                       mteRegionXF = -1;
+                       if (iCurrentParam < 2 )
+                               break;
+                       mteRegionXF = iParam[1]-1;
+                       mteRegionYF = iParam[0]-1;
+                       break;
+                       
+               case 'F':
+                       // fill with char
+                       {
+                               if (mteRegionXF == -1 || iCurrentParam < 1)
+                                       break;
+                               sRepeat[0] = (char)iParam[0];
+                               sRepeat[1] = '\0';
+                               int xi = Console.GetCursorX(),yi = Console.GetCursorY();
+                               int xf = mteRegionXF;
+                               int yf = mteRegionYF;
+                               mteRegionXF = -1;
+                               for(int y=yi;y<=yf;++y)
+                               {
+                                       Console.SetCursorPosition(xi,y);
+                                       for(int x=xi;x<=xf;++x)
+                                               
+                                               Console.WriteStringFast(sRepeat,1);
+                               }
+                       }
+                       break;
+                       
+               case 'S':
+                       // Scroll region
+                       {
+                               if (mteRegionXF == -1 || iCurrentParam < 2)
+                                       break;
+                               int /*x = Console.GetCursorX(),*/y = Console.GetCursorY();
+                               // int xf = mteRegionXF;
+                               int yf = mteRegionYF;
+                               mteRegionXF = -1;
+                               // !!! don't use x during scroll
+                               int diff = (iParam[0]-1)-y;
+                               if (diff<0)
+                                       Console.ScrollDown(y-1,yf,diff);
+                               else
+                                       Console.ScrollDown(y,yf+1,diff);
+                       }
+                       break;
+                       // Meridian main version ??
+               case 'x':
+                       // disable echo and line mode
+                       Network.set_local_echo(0);
+                       Network.set_line_mode(0);
+                       // Meridian Server handle cursor itself
+                       Console.SetCursorSize(0);
+                       break;
+                       // query ??
+               case 'Q':
+                       if (iParam[0] == 1)
+                               Network.WriteString("\033vga.",5);
+                       break;
+               default:
+#ifdef DEBUG
+                       Console.Beep();
+#endif
+                       break;
+       }
+       
+       return pszBuffer;
+ }
+#endif
+
+char* TANSIParser::ParseEscape(char* pszBuffer, char* pszBufferEnd) {
+       char *pszChar;
+
+       // Check if we have enough characters in buffer.
+       if ((pszBufferEnd - pszBuffer) < 2)
+               return pszBuffer;
+       
+       //  I.Ioannou 04 Sep 1997
+       // there is no need for pszBuffer++; after each command
+       
+       // Decode the command.
+       pszBuffer++;
+       
+       switch (*pszBuffer++) {
+               case 'A': // Cursor up
+                       Console.MoveCursorPosition(0, -1);
+                       break;
+               // Cursor down
+               case 'B': 
+                       Console.MoveCursorPosition(0, 1);
+                       break;
+               // Cursor right
+               case 'C':
+                       Console.MoveCursorPosition(1, 0);
+                       break;
+               // LF *or* cursor left (Paul Brannan 6/27/98)
+               case 'D':
+                       if(vt52_mode)
+                               Console.MoveCursorPosition(-1, 0);
+                       else
+                               Console.index();
+                       break;
+               // CR/LF (Paul Brannan 6/26/98)
+               case 'E':
+                       Console.WriteCtrlString("\r\n", 2);
+                       break;
+               // Special graphics char set (Paul Brannan 6/27/98)
+               case 'F':
+                       Charmap.setmap('0');
+                       break;
+               // ASCII char set (Paul Brannan 6/27/98)
+               case 'G':
+                       Charmap.setmap('B');
+                       break;
+               // Home cursor/tab set
+               case 'H': 
+                       if(ini.get_vt100_mode()) {
+                               int x = Console.GetCursorX();
+                               if(x != 0) {
+                                       int t = tab_stops[x - 1];
+                                       for(int j = x - 1; j >= 0 && tab_stops[j] == t; j--)
+                                               tab_stops[j] = x;
+                               }
+                       } else {
+                               //  I.Ioannou 04 Sep 1997 (0,0) not (1,1)
+                               ConSetCursorPos(0, 0);
+                       }
+                       break;
+               // Reverse line feed (Paul Brannan 6/27/98)
+               // FIX ME!!!  reverse_index is wrong to be calling here
+               // (Paul Brannan 12/2/98)
+               case 'I':
+                       Console.reverse_index();
+                       break;
+               // Erase end of screen
+               case 'J': 
+                       Console.ClearEOScreen();
+                       break;
+               // Erase EOL
+               case 'K':
+                       Console.ClearEOLine();
+                       break;
+               // Scroll Up one line //Reverse index
+               case 'M':
+                       Console.reverse_index();
+                       break;
+               // Direct cursor addressing
+               case 'Y':
+                       if ((pszBufferEnd - pszBuffer) >= 2){
+                               // if we subtract '\x1F', then we may end up with a negative
+                               // cursor position! (Paul Brannan 6/26/98)
+                               ConSetCursorPos(pszBuffer[1] - ' ',     pszBuffer[0] - ' ');
+                               pszBuffer+=2;
+                       } else {
+                               pszBuffer--; // Paul Brannan 6/26/98
+                       }
+                       break;
+               // Terminal ID Request
+               case 'Z':
+                       {
+                               char* szTerminalId = GetTerminalID();
+                               Network.WriteString(szTerminalId, strlen(szTerminalId));
+                               break;
+                       }
+               // reset terminal to defaults
+               case 'c':
+                       ResetTerminal();
+                       break;
+               // Enter alternate keypad mode
+               case '=':
+                       KeyTrans.set_ext_mode(APP3_KEY);
+                       break;
+               // Exit alternate keypad mode
+               case '>':
+                       KeyTrans.unset_ext_mode(APP3_KEY);
+                       break;
+               // Enter ANSI mode
+               case '<':
+                       KeyTrans.unset_ext_mode(APP2_KEY); // exit vt52 mode
+                       break;
+               // Graphics processor on (See note 3)
+               case '1':
+                       break;
+               // Line size commands
+               case '#':        //Line size commands
+                       // (Paul Brannan 6/26/98)
+                       if(pszBuffer < pszBufferEnd) {
+                               switch(*pszBuffer++) {
+                               case '3': break; // top half of a double-height line
+                               case '4': break; // bottom half of a double-height line
+                               case '6': break; // current line becomes double-width
+                               case '8': Console.ClearScreen('E'); break;
+                               }
+                       } else {
+                               pszBuffer--;
+                       }                       
+                       break;
+               // Graphics processor off (See note 3)
+               case '2':
+                       break;
+               // Save cursor and attribs
+               case '7':
+                       SaveCurY(Console.GetRawCursorY());
+                       SaveCurX(Console.GetRawCursorX());
+                       iSavedAttributes = Console.GetAttrib();
+                       break;
+                       // Restore cursor position and attribs
+               case '8':
+                       Console.SetRawCursorPosition(iSavedCurX, iSavedCurY);
+                       Console.SetAttrib(iSavedAttributes);
+                       break;
+               // Set G0 map (Paul Brannan 6/25/98)
+               case '(':
+                       if (pszBuffer < pszBufferEnd) {
+                               map_G0 = *pszBuffer;
+                               if(current_map == 0) Charmap.setmap(map_G0);
+                               pszBuffer++;
+                       } else {
+                               pszBuffer--;
+                       }
+                       break;
+               // Set G1 map (Paul Brannan 6/25/98)
+               case ')':
+                       if (pszBuffer < pszBufferEnd) {
+                               map_G1 = *pszBuffer;
+                               if(current_map == 1) Charmap.setmap(map_G1);
+                               pszBuffer++;
+                       } else {
+                               pszBuffer--;
+                       }
+                       break;
+               // This doesn't do anything, as far as I can tell, but it does take
+               // a parameter (Paul Brannan 6/27/98)
+               case '%':
+                       if (pszBuffer < pszBufferEnd) {
+                               pszBuffer++;
+                       } else {
+                               pszBuffer--;
+                       }
+                       break;
+               // ANSI escape sequence
+               case '[':
+                       // Check if we have whole escape sequence in buffer.
+                       // This should not be isalpha anymore (Paul Brannan 9/1/98)
+                       pszChar = pszBuffer;
+                       while ((pszChar < pszBufferEnd) && (*pszChar <= '?'))
+                               pszChar++;
+                       if (pszChar == pszBufferEnd)
+                               pszBuffer -= 2;
+                       else
+                               pszBuffer = ParseEscapeANSI(pszBuffer, pszBufferEnd);
+                       break;
+#ifdef MTE_SUPPORT
+               case '~':
+                       // Frediano Ziglio, 5/31/2000
+                       // Meridian Terminal Emulator extension
+                       // !!! same as ANSI
+                       // !!! should put in MTE procedure
+                       pszChar = pszBuffer;
+                       while ((pszChar < pszBufferEnd) && (*pszChar <= '?'))
+                               pszChar++;
+                       if (pszChar == pszBufferEnd)
+                               pszBuffer -= 2;
+                       else
+                               pszBuffer = ParseEscapeMTE(pszBuffer, pszBufferEnd);
+                       break;
+#endif
+               default:
+#ifdef DEBUG
+                       Console.Beep();
+#endif
+                       break;
+       }
+
+       return pszBuffer;
+}
+
+// This function now only parses the ANSI buffer and does not do anything
+// with IAC sequences.  That code has been moved to TTelHndl.cpp.
+// The scroller update routines have been moved to TScroll.cpp.
+// (Paul Brannan 6/15/98)
+char* TANSIParser::ParseBuffer(char* pszHead, char* pszTail){
+       // copy into ANSI buffer
+       char * pszResult;
+       
+       // Parse the buffer for ANSI or display
+       while (pszHead < pszTail) {
+               if(!ini.get_output_redir()) {
+                       pszResult = ParseANSIBuffer(pszHead, pszTail);
+               } else {
+                       // Output is being redirected
+                       if(ini.get_strip_redir()) {
+                               // Skip the WriteFile() altogether and pass the buffer to a filter
+                               // Mark Miesfield 09/24/2000
+                               pszResult = PrintGoodChars(pszHead, pszTail);
+                       } else {
+                               DWORD Result;
+                               // Paul Brannan 7/29/98
+                               // Note that this has the unforunate effect of printing out
+                               // NULL (ascii 0) characters onto the screen
+                               if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pszHead,
+                                       pszTail - pszHead, &Result,     NULL)) pszResult = pszHead;
+                               pszResult = pszHead + Result;
+                       }
+               }
+               if (dumpfile)
+                       fwrite( pszHead, sizeof (char), pszResult-pszHead, dumpfile);
+               if(ini.get_scroll_enable()) Scroller.update(pszHead, pszResult);
+               if (pszResult == pszHead) break;
+               pszHead = pszResult;
+       }
+       // return the new head to the buffer
+       return pszHead;
+}
+
+// A simple routine to strip ANSI sequences
+// This isn't perfect, but it does an okay job (Paul Brannan 7/5/98)
+// Fixed a line counting bug (Paul Brannan 12/4/98)
+int TANSIParser::StripBuffer(char* pszHead, char* pszTail, int width) {
+       int lines = 0, c = 0;
+       char *pszBuf = pszHead;
+
+       while(pszHead < pszTail) {
+               if(iscntrl(*pszHead)) {
+                       switch(*(pszHead++)) {
+                       case 8:
+                       case 127:
+                               if(c>0) {
+                                       if(!(c%width)) lines--;
+                                       c--;
+                                       pszBuf--;
+                               }
+                               break;
+                       case 10: lines++;
+                       case 13:
+                               *(pszBuf++) = *(pszHead - 1);
+                               c = 0;
+                               break;
+                       case 27:
+                               switch(*(pszHead++)) {
+                               case 'Y': pszHead += 2; break;
+                               case '#':
+                               case '(':
+                               case ')':
+                               case '%': pszHead++; break;
+                               case '[':
+                                       while((pszHead < pszTail) && (*pszHead < '?'))
+                                               pszHead++;
+                                       pszHead++;
+                                       break;
+                               }
+                       }
+               } else {
+                       *(pszBuf++) = *(pszHead++);
+                       c++;
+               }
+               if(c != 0 && !(c%width))
+                       lines++;
+       }
+       
+       // Fill in the end of the buffer with blanks
+       while(pszBuf <= pszTail) *pszBuf++ = ' ';
+
+       return lines;
+}
+
+char* TANSIParser::ParseANSIBuffer(char* pszBuffer, char* pszBufferEnd)
+{
+       if(InPrintMode) {
+               return PrintBuffer(pszBuffer, pszBufferEnd);
+       }
+       
+       unsigned char tmpc = *(unsigned char *)pszBuffer;
+
+       if(tmpc == 27) {
+               return ParseEscape(pszBuffer, pszBufferEnd);
+       }
+       
+//     if((fast_write && tmpc < 32) ||
+//             !print_ctrl && (tmpc < 32 || (EightBit_Ansi &&
+//             (tmpc > 128 && tmpc < 128 + ' ')))) {
+
+       // We shouldn't print ctrl characters when fast write is enabled
+       // and ctrl chars are disabled (Paul Brannan 9/1/98)
+       if(tmpc < 32) {
+               // From the Linux kernel (Paul Brannan 12/5/98):
+               /* A bitmap for codes <32. A bit of 1 indicates that the code
+                * corresponding to that bit number invokes some special action
+                * (such as cursor movement) and should not be displayed as a
+                * glyph unless the disp_ctrl mode is explicitly enabled.
+                */
+               const long CTRL_ACTION = 0x0d00ff81;
+               const long CTRL_ALWAYS = 0x0800f501;
+               if(!(((print_ctrl?CTRL_ALWAYS:CTRL_ACTION)>>tmpc)&1)) {
+                       
+                       Console.WriteString((char *)&tmpc, 1);
+                       pszBuffer++;
+                       return pszBuffer;
+               }
+
+               switch (tmpc) {
+               case 0:
+                       pszBuffer++;
+                       break;
+               
+               // I.Ioannou 5/30/98
+               case 7:
+                       Console.Beep();
+                       pszBuffer++;
+                       break;
+               
+               // destructive backspace
+               case 8:
+                       // Added option for destructive backspace (Paul Brannan 5/13/98)
+                       // Changed to ConWriteCtrlString so that the cursor position can be
+                       // updated (Paul Brannan 5/25/98)
+                       if(ini.get_dstrbksp()) {
+                               Console.WriteCtrlChar('\b');
+                               Console.WriteString(" ", 1);
+                               Console.WriteCtrlChar('\b');
+                       }
+                       else Console.WriteCtrlChar('\b');
+                       pszBuffer++;
+                       break;
+               
+               // horizontal tab
+               case 9:
+                       {
+                               pszBuffer++;
+                               int x = Console.GetCursorX();
+                               if(x != -1)
+                                       Console.SetCursorPosition(tab_stops[x], Console.GetCursorY());
+                       }
+                       break;
+               
+               // Line Feed Char
+               case 10:
+                       // Test for local echo (Paul Brannan 8/25/98)
+                       if(Network.get_local_echo() || newline_mode) // &&
+                               Console.WriteCtrlChar('\x0d');
+                       Console.WriteCtrlChar('\x0a');
+                       pszBuffer++;
+                       break;
+               
+               // form feed
+               case 12:
+                       pszBuffer++;
+                       Console.ClearScreen();
+                       Console.SetRawCursorPosition(Console.GetCursorX(), 1); // changed fm 1
+                       break;
+               
+               case 13:
+                       Console.WriteCtrlChar('\x0d');
+                       pszBuffer++;
+
+                       break;
+
+               case 14:  // shift out of alternate chararcter set
+                       pszBuffer++;
+                       Charmap.setmap(map_G1); // Paul Brannan 6/25/98
+                       current_map = 1;
+                       break;
+       
+               case 15:  // shift in
+                       pszBuffer++;
+                       Charmap.setmap(map_G0); // Paul Brannan 6/25/98
+                       current_map = 0;
+                       break;
+               
+               // Paul Brannan 9/1/98 - Is this okay?
+               default:
+                       pszBuffer++;
+               }
+
+               return pszBuffer;
+       }
+
+       //  added by I.Ioannou 06 April, 1997
+       //  In 8 bit systems the server may send 0x9b instead of ESC[
+       //  Well, this will produce troubles in Greek 737 Code page
+       //  which uses 0x9b as the small "delta" - and I thing that there
+       //  is another European country with the same problem.
+       //  If we have to stay 8-bit clean we may have to
+       //  give the ability of ROM characters (ESC[11m),
+       //  for striped 8'th bit (ESC[12m) as SCO does,
+       //  or a parameter at compile (or run ?) time.
+       // We now check for a flag in the ini file (Paul Brannan 5/13/98)
+       // We also handle any 8-bit ESC sequence (Paul Brannan 6/28/98)
+       if(ini.get_eightbit_ansi() && (tmpc > 128 && tmpc < 128 + ' ')) {
+               // There's a chance the sequence might not parse.  If this happens
+               // then pszBuffer will be one character too far back, since
+               // ParseEscape is expecting two characters, not one.
+               // In that case we must handle it.
+               char *pszCurrent = pszBuffer;
+               pszBuffer = ParseEscape(pszBuffer, pszBufferEnd);
+               if(pszBuffer < pszCurrent) pszBuffer = pszCurrent;
+       }
+
+       char* pszCurrent = pszBuffer + 1;
+       // I.Ioannou 04 Sep 1997 FIXME with ESC[11m must show chars < 32
+       // Fixed (Paul Brannan 6/28/98)
+       while ((pszCurrent < pszBufferEnd) && (!iscntrl(*pszCurrent))) {
+               // I.Ioannou 04 Sep 1997 strip on high bit
+               if ( (inGraphMode) && (*pszCurrent > (char)32) )
+                       *pszCurrent |= 0x80 ;
+               pszCurrent++;
+       }
+       
+       // Note that this may break dumpfiles slightly.
+       // If 'B' is set to anything other than ASCII, this will cause problems
+       // (Paul Brannan 6/28/98)
+       if(current_map != 'B' && Charmap.enabled)
+               Charmap.translate_buffer(pszBuffer, pszCurrent);    
+       
+       last_char = *(pszCurrent-1);    // TITUS++: Remember last char
+
+       if(fast_write) {
+               pszBuffer += Console.WriteStringFast(pszBuffer,
+                       pszCurrent - pszBuffer);
+       } else {
+               pszBuffer += Console.WriteString(pszBuffer,
+                       pszCurrent - pszBuffer);
+       }
+
+       return pszBuffer;
+}
+
+// Added by I.Ioannou 06 April, 1997
+// Print the buffer until you reach ESC[4i
+char* TANSIParser::PrintBuffer(char* pszBuffer, char* pszBufferEnd) {
+       // Check if we have enough characters in buffer.
+       if ((pszBufferEnd - pszBuffer) < 4)
+               return pszBuffer;
+       char *tmpChar;
+       
+       tmpChar = pszBuffer;
+       if ( *tmpChar == 27 ) {
+               tmpChar++;
+               if ( *tmpChar == '[' ) {
+                       tmpChar++;
+                       if ( *tmpChar == '4' ) {
+                               tmpChar++;
+                               if ( *tmpChar == 'i' ) {
+                                       InPrintMode = 0; // Stop Print Log
+                                       if ( printfile != NULL )
+                                               fclose(printfile);
+                                       pszBuffer += 4;
+                                       return pszBuffer;
+                               }
+                       }
+               }
+       }
+       
+       if (printfile != NULL) {
+               fputc( *pszBuffer, printfile);
+               pszBuffer++;
+       } else
+               InPrintMode = 0;
+       
+       return pszBuffer;
+}
+
+/* - PrintGoodChars( pszHead, pszTail ) - - - - - - - - - - - - - - - - - - -
+-*
+
+  Mark Miesfield 09/24/2000
+
+  Prints the characters in a buffer, from the specified head to the specified
+  tail, to standard out, skipping any control characters or ANSI escape
+  sequences.
+
+  Parameters on entry:
+    pszHead  ->  Starting point in buffer.
+
+    pszTail  ->  Ending point in buffer.
+
+  Returns:
+    Pointer to the first character in the buffer that was not output to
+    standard out.  (Since no error checking is done, this is in effect
+    pszTail.)
+
+  Side Effects:
+    None.
+* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+*/
+char * TANSIParser::PrintGoodChars( char * pszHead, char * pszTail )  {
+
+  while ( pszHead < pszTail )  {
+    if ( iscntrl( *pszHead ) )  {
+      switch ( *(pszHead++) )  {
+        case 10 :
+          putc( 10, stdout );
+          break;
+
+        case 13 :
+          putc( 13, stdout );
+          break;
+
+        case 27:
+          switch ( *(pszHead++) )  {
+            case 'Y':
+              pszHead += 2;
+              break;
+
+            case '#':
+            case '(':
+            case ')':
+            case '%': pszHead++; break;
+            case '[':
+              while ( (pszHead < pszTail) && (*pszHead < '?') )
+                pszHead++;
+              pszHead++;
+              break;
+
+            default :
+              break;
+          }
+          break;
+
+        default :
+          break;
+      }
+    }
+    else
+      putc( *(pszHead++), stdout );
+  }
+  return ( pszTail );
+}
+// End of function:  PrintGoodChars( pszHead, pszTail )
diff --git a/reactos/apps/utils/net/telnet/src/ansiprsr.h b/reactos/apps/utils/net/telnet/src/ansiprsr.h
new file mode 100644 (file)
index 0000000..aef43c6
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef __ANSIPRSR_H
+#define __ANSIPRSR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include "tnconfig.h"
+#include "tparser.h"
+
+// added this color table to make things go faster (Paul Branann 5/8/98)
+enum Colors {BLACK=0, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE};
+static const int ANSIColors[] = {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
+
+// This should be greater than the largest conceivable window size
+// 200 should suffice
+#define MAX_TAB_POSITIONS 200
+
+// Added by Frediano Ziglio 6/2/2000
+// Include Meridian Emulator support
+// undefine it to remove support
+#define MTE_SUPPORT 1
+
+// TANSIParser is now properly no longer a base class for TTelnetParser.
+// Screen output is handled in TConsole.cpp.
+// (Paul Brannan 6/15/98)
+class TANSIParser : public TParser {
+private:
+       char* ParseEscapeANSI(char* pszBuffer, char* pszBufferEnd);
+       char* ParseANSIBuffer(char* pszBuffer, char* pszBufferEnd);
+       char* ParseEscape(char* pszBuffer, char* pszBufferEnd);
+       // Added by I.Ioannou 06/04/97
+       char* PrintBuffer(char* pszBuffer, char* pszBufferEnd);
+       char* PrintGoodChars(char * pszHead, char * pszTail);
+
+#ifdef MTE_SUPPORT
+    // Added by Frediano Ziglio, 5/31/2000
+    char* ParseEscapeMTE(char* pszBuffer, char* pszBufferEnd);
+       short int mteRegionXF,mteRegionYF;
+#endif
+
+       void ConSetAttribute(unsigned char wAttr);
+       char *GetTerminalID();
+       void ConSetCursorPos(int x, int y);
+       void ResetTerminal();
+       void Init();
+
+       void SaveCurX(int iX);
+       void SaveCurY(int iY);
+
+       void resetTabStops();
+       
+       int iSavedCurX;
+       int iSavedCurY;
+       unsigned char iSavedAttributes;
+       FILE * dumpfile;
+
+       // Added by I.Ioannou 06 April 1997
+       FILE * printfile;
+       char InPrintMode;
+       int inGraphMode;
+
+       char last_char;                 // TITUS++: 2. November 98
+
+       char map_G0, map_G1;
+       int current_map;
+       bool vt52_mode;
+       bool print_ctrl;
+       bool ignore_margins;
+       bool fast_write;
+       bool newline_mode;
+
+       int tab_stops[MAX_TAB_POSITIONS];
+
+public:
+       // Changed by Paul Brannan 5/13/98
+       TANSIParser(TConsole &Console, KeyTranslator &RefKeyTrans,
+               TScroller &RefScroller, TNetwork &NetHandler, TCharmap &RefCharmap);
+       ~TANSIParser();
+       
+       char* ParseBuffer(char* pszBuffer, char* pszBufferEnd);
+       static int StripBuffer(char* pszBuffer, char* pszBufferEnd, int width);
+};
+
+#endif
diff --git a/reactos/apps/utils/net/telnet/src/keytrans.cpp b/reactos/apps/utils/net/telnet/src/keytrans.cpp
new file mode 100644 (file)
index 0000000..518b962
--- /dev/null
@@ -0,0 +1,227 @@
+///////////////////////////////////////////////////////////////////////////////
+//Telnet Win32 : an ANSI telnet client.
+//Copyright (C) 1998-2000 Paul Brannan
+//Copyright (C) 1998 I.Ioannou
+//Copyright (C) 1997 Brad Johnson
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,