summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfunc/tnet.icn
blob: 1ab3546c3a02155e4f2c1cd5e187b58e1ea5bae3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
############################################################################
#
#	File:     tnet.icn
#
#	Subject:  Program to talk to telnet port
#
#	Author:   Gregg M. Townsend
#
#	Date:     August 4, 2000
#
############################################################################
#
#  Usage:  tnet hostname portnumber
#
#  This is a VERY simple telnet client.  It connects to a remote port
#  and exchanges data between the port and the terminal.  The port is
#  read and echoed to the terminal until the port is quiet for 200 msec;
#  then one line from the terminal is sent to the port.  This process
#  repeats until an EOF is read from either source.
#
#  Some interesting port numbers can usually be found in /etc/services.
#  For example, network news is read from a news server using port 119.
#
#  This program does not work under Irix because poll(2) always returns 1.
#
############################################################################

link cfunc			# link standard C functions transparently

procedure main(args)
   local h, p, f, s

   h := args[1] | &host		# default is current host
   p := integer(args[2]) | 13	# default is port 13 (time of day)

   f := tconnect(h, p) | stop("can't connect to port ", p, " of ", h)

   fpoll(f, 2000)		# wait up to 2 sec for initial response
   repeat {
      while fpoll(f, 200) do	# read characters from port until timeout
         writes(reads(f)) | { write("EOF"); break break }
      writes("\n> ")		# issue prompt
      s := read() | break	# read line from terminal
      seek(f)			# enable switch from input to output
      flush(f)			# workaround for Dec Alpha bug
      write(f, s)		# write terminal input to port
      seek(f)			# enable switch from output to input
      }
end