home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / Main / c / main < prev    next >
Text File  |  1995-02-05  |  27KB  |  1,065 lines

  1. /* Main network program - provides both client and server functions */
  2.  
  3. #define HOSTNAMELEN 32          /* changed from 16 by Bdale 860812 */
  4.  
  5. #define ESC 29
  6.  
  7. extern char config[];    /* File to read setup from */
  8. extern char startup[];   /* File to read startup commands from */
  9. extern char alternate[]; /* Directory for alternate startup commands */
  10. extern char scripts[];   /* Directory for command files for source command */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18.  
  19. #include "wimp.h"
  20. #include "wimpt.h"
  21. #include "visdelay.h"
  22.  
  23. #include "config.h"
  24. #include "global.h"
  25. #include "mbuf.h"
  26. #include "netuser.h"
  27. #include "timer.h"
  28. #include "icmp.h"
  29. #include "iface.h"
  30. #include "ip.h"
  31. #include "tcp.h"
  32. #include "ax25.h"
  33. #include "netrom.h"
  34. #include "remote.h"
  35. #include "ftp.h"
  36. #include "telnet.h"
  37. #include "session.h"
  38. #include "cmdparse.h"
  39. #include "asy.h"
  40. #include "chat.h"
  41. #include "slip.h"
  42. #include "nrs.h"
  43. #include "trace.h"
  44. #include "mem.h"
  45. #include "arp.h"
  46. #include "ax_mbx.h"
  47. #include "finger.h"
  48. #include "ident.h"
  49. #include "dns.h"
  50. #include "internet.h"
  51. #include "kiss.h"
  52. #include "lapb.h"
  53. #include "nr4.h"
  54. #include "ping.h"
  55. #include "pop.h"
  56. #include "nntp.h"
  57. #include "smtp.h"
  58. #include "NetTime.h"
  59. #include "udp.h"
  60. #include "misc.h"
  61. #include "domain.h"
  62. #include "arc.h"
  63. #include "driver.h"
  64. #include "pppdriver.h"
  65. #include "alarm.h"
  66. #include "var.h"
  67.  
  68. extern varlist global_vars;
  69.  
  70. extern int (*driver_load(char*))(int,...);
  71.  
  72. /* Dummy structure for loopback tracing */
  73. struct interface loopback = {
  74.   NULLIF, "loopback" };
  75.  
  76. extern struct interface *ifaces;
  77. extern char version[];
  78. extern struct mbuf *loopq;
  79.  
  80. extern Terminal *MWin;
  81.  
  82. int mode;
  83.  
  84. char badhost[] = "Unknown host %s\r\n";
  85. char hostname[HOSTNAMELEN];
  86. unsigned nsessions = NSESSIONS;
  87. int16 lport    = 1001;
  88. char *prompt   = "net> ";
  89. char nospace[] = "No space!!\r\n";        /* Generic malloc fail message */
  90. int attended = 1;
  91. int ttyflow = 1;                        /* tty flow control */
  92. int initialisation_completed = FALSE;
  93.  
  94. static char *ttybuf;
  95. static int quiet = FALSE;  /* Echo startup files */
  96.  
  97. extern int doresolve(int, char **);
  98. extern int dotransfer(int, char **);
  99.  
  100. static int doexit(int, char **);
  101. static int doattach(int, char **);
  102. static int doecho(int, char **);
  103. static int doeol(int, char **);
  104. static int dohostname(int, char **);
  105. static int dolog(int, char **);
  106. static int dohelp(int, char **);
  107. static int domode(int, char **);
  108. static int doparam(int, char **);
  109. static int doremote(int, char **);
  110. static int dostart(int, char **);
  111. static int dostop(int, char **);
  112. static int dotrace(int, char **);
  113. static int dosource(int, char **);
  114. static int dounattend(int, char **);
  115. static int dofiler(int, char **);
  116.  
  117. static int filer_open(int, char **);
  118. static int filer_run(int, char **);
  119.  
  120. extern int docredits(int argc, char **argv);
  121. extern int doterm(int argc, char **argv);
  122.  
  123. extern int doslipstat(int argc, char **argv);
  124.  
  125. extern int dosetvar(int argc, char **argv); /* In command parse */
  126. extern int dosetosvar(int argc, char **argv); /* In command parse */
  127. extern int doshowvar(int argc, char **argv); /* In command parse */
  128.  
  129. extern int doident(int argc, char **argv);
  130.  
  131. static void showtrace(struct interface *);
  132. static int  asy_attach(int, char **);
  133. extern int ether_attach(int argc, char **argv);
  134.  
  135. struct cmds cmds[] = {
  136.   /* The "go" command must be first */
  137.   "",             go,             0, NULLCHAR,    NULLCHAR,
  138.   "arp",          doarp,          0, NULLCHAR,    NULLCHAR,
  139.   "asystat",      doasystat,      0, NULLCHAR,    NULLCHAR,
  140.   "ax25",         doax25,         0, NULLCHAR,    NULLCHAR,
  141.   "attach",       doattach,       2, "attach <hardware> <hw specific options>", NULLCHAR,
  142.   /* This one is out of alpabetical order to allow abbreviation to "c" */
  143.   "connect",      doconnect,      3,"connect <interface> <callsign> [digipeaters]",
  144.   NULLCHAR,
  145.   "chat",         dochat,         0, "chat <interface> <error-send> [expect-send pairs]",    NULLCHAR,
  146.   "chattrace",    chat_trace,     0, NULLCHAR,    NULLCHAR,
  147.   "close",        doclose,        0, NULLCHAR,    NULLCHAR,
  148.   "credits",      docredits,      0, NULLCHAR,    NULLCHAR,
  149.   "disconnect",   doclose,        0, NULLCHAR,    NULLCHAR,
  150.   "domain",       dodomain,       0, NULLCHAR,    NULLCHAR,
  151.   "echo",         doecho,         0, NULLCHAR,    "echo [refuse|accept]",
  152.   "eol",          doeol,          0, NULLCHAR,    "eol options: unix, standard",
  153.   "exit",         doexit,         0, NULLCHAR,    NULLCHAR,
  154.   "finger",       dofinger,       0, NULLCHAR,    NULLCHAR,
  155.   "filer",        dofiler,        1, "open|run <file>",    NULLCHAR,
  156.   "forward",      doforward,      0, NULLCHAR,    NULLCHAR,
  157.   "ftp",          doftp,          2, "ftp <address> [ \\ <switches>[ \\ <chat strings>]]",     NULLCHAR,
  158.   "help",         dohelp,         0, NULLCHAR,    NULLCHAR,
  159.   "hop",          dohop,      0, NULLCHAR,    NULLCHAR,
  160.   "hostname",     dohostname,     0, NULLCHAR,    NULLCHAR,
  161.   "kick",         dokick,         0, NULLCHAR,    NULLCHAR,
  162.   "log",          dolog,          0, NULLCHAR,    NULLCHAR,
  163.   "ip",           doip,           0, NULLCHAR,    NULLCHAR,
  164.   "ident",        doident,        1, NULLCHAR,    NULLCHAR,
  165.   "mbox",         dombox,         0, NULLCHAR,    NULLCHAR,
  166.   "mem",          domem,          0, NULLCHAR,    NULLCHAR,
  167.   "mode",         domode,         2, "mode <interface>",  NULLCHAR,
  168.   "netrom",       donetrom,       0, NULLCHAR,    NULLCHAR,
  169.   "nntp",         donntp,         0, NULLCHAR,    NULLCHAR,
  170. /*  "nntp2",        donntp2,        0, NULLCHAR,    NULLCHAR, */
  171.   "nrstat",       donrstat,       0, NULLCHAR,    NULLCHAR,
  172.   "nsquery",      dodns,          0, "nsquery <options> [<namesever>] [<name>] [<type>]", NULLCHAR,
  173.   "param",        doparam,        2, "param <interface>", NULLCHAR,
  174.   "ping",         doping,         0, NULLCHAR,    NULLCHAR,
  175.   "pop",          dopop,          0, NULLCHAR,    NULLCHAR,
  176.   "quit",         doexit,         0, NULLCHAR,    NULLCHAR,
  177.   "record",       dorecord,       0, NULLCHAR,    NULLCHAR,
  178.   "remote",       doremote,       4, "remote <address> <port> <command>", NULLCHAR,
  179.   "reset",        doreset,        0, NULLCHAR,    NULLCHAR,
  180.   "resolve",      doresolve,      0, NULLCHAR,    NULLCHAR,
  181.   "route",        doroute,        0, NULLCHAR,    NULLCHAR,
  182.   "session",      dosession,      0, NULLCHAR,    NULLCHAR,
  183.   "setvar",       dosetvar,       3, "setvar <variable> <value_string>", NULLCHAR,
  184.   "setosvar",     dosetosvar,     3, "setvar <variable> <os variable name>", NULLCHAR,
  185.   "showvar",      doshowvar,      0, "showvar [<variable>]", NULLCHAR,
  186.   "smtp",         dosmtp,         0, NULLCHAR,    NULLCHAR,
  187.   "slipstat",     doslipstat,     2, "slipstat <interface>",    NULLCHAR,
  188.   "source",       dosource,       2, "source <filename>", NULLCHAR,
  189.   "start",        dostart,        2, "start <servername>",NULLCHAR,
  190.   "stop",         dostop,         2, "stop <servername>", NULLCHAR,
  191.   "tcp",          dotcp,          0, NULLCHAR,    NULLCHAR,
  192.   "telnet",       dotelnet,       2, "telnet <address> [<port>] [ \\ <switches>[ \\ <chat strings>]]",  NULLCHAR,
  193.   "time",         dotime,         1, NULLCHAR,  NULLCHAR,
  194.   "trace",        dotrace,        0, NULLCHAR,    NULLCHAR,
  195.   "trf",          dotransfer,     4, "trf <site> <port> <command>", NULLCHAR,
  196.   "udp",          doudp,          0, NULLCHAR,    NULLCHAR,
  197.   "unattended",   dounattend,     0, NULLCHAR,    NULLCHAR,
  198.   "upload",       doupload,       0, NULLCHAR,    NULLCHAR,
  199.   "window",       dowin,          0, NULLCHAR,    NULLCHAR,
  200.   "terminal",     doterm,         1, "terminal [*] <switches>[ \\ <chat strings>]",    NULLCHAR,
  201.   "?",            dohelp,         0, NULLCHAR,    NULLCHAR,
  202.   NULLCHAR,       NULLFP,         0,
  203.   "Unknown command; type \"?\" for list",   NULLCHAR,
  204. };
  205.  
  206. /* "start" and "stop" subcommands */
  207.  
  208. static struct cmds startcmds[] = {
  209.   "discard",      dis1,           0, NULLCHAR, NULLCHAR,
  210.   "echo",         echo1,          0, NULLCHAR, NULLCHAR,
  211.   "finger",       finger1,        0, NULLCHAR, NULLCHAR,
  212.   "ftp",          ftp1,           0, NULLCHAR, NULLCHAR,
  213.   "smtp",         smtp1,          0, NULLCHAR, NUL