main.c
资源名称:export.zip [点击查看]
上传用户:hepax88
上传日期:2007-01-03
资源大小:1101k
文件大小:16k
源码类别:
TCP/IP协议栈
开发平台:
Visual C++
- /* Main-level NOS program:
- * initialization
- * keyboard processing
- * generic user commands
- *
- * Copyright 1986-1995 Phil Karn, KA9Q
- */
- #include <stdio.h>
- #include <time.h>
- #include <ctype.h>
- #if defined(__TURBOC__) && defined(MSDOS)
- #include <io.h>
- #include <conio.h>
- #endif
- #include "global.h"
- #include <stdarg.h>
- #include "mbuf.h"
- #include "timer.h"
- #include "proc.h"
- #include "iface.h"
- #include "ip.h"
- #include "tcp.h"
- #include "udp.h"
- #include "ax25.h"
- #include "kiss.h"
- #include "enet.h"
- #include "netrom.h"
- #include "ftpcli.h"
- #include "telnet.h"
- #include "tty.h"
- #include "session.h"
- #include "hardware.h"
- #include "usock.h"
- #include "socket.h"
- #include "cmdparse.h"
- #include "commands.h"
- #include "daemon.h"
- #include "devparam.h"
- #include "domain.h"
- #include "files.h"
- #include "main.h"
- #include "remote.h"
- #include "trace.h"
- #include "display.h"
- extern struct cmds Cmds[],Startcmds[],Stopcmds[],Attab[];
- #ifndef MSDOS /* PC uses F-10 key always */
- static char Escape = 0x1d; /* default escape character is ^] */
- #endif
- char Badhost[] = "Unknown host %sn";
- char *Hostname;
- char Nospace[] = "No space!!n"; /* Generic malloc fail message */
- struct proc *Cmdpp;
- struct proc *Display;
- char *Cmdline; /* Copy of most recent command line */
- int main_exit = FALSE; /* from main program (flag) */
- static char Prompt[] = "net> ";
- static FILE *Logfp;
- static time_t StartTime; /* time that NOS was started */
- static int Verbose;
- static int keychar(int c);
- static void pass(char *,int len);
- static void passchar(int c);
- int
- main(argc,argv)
- int argc;
- char *argv[];
- {
- FILE *fp;
- struct daemon *tp;
- int c;
- char cmdbuf[256];
- long hinit = 102400;
- unsigned chunk;
- void **list;
- StartTime = time(&StartTime);
- while((c = getopt(argc,argv,"f:s:d:bvh:")) != EOF){
- switch(c){
- case 'h': /* Heap initialization */
- hinit = atol(optarg);
- break;
- case 'f': /* Number of files */
- Nfiles = atoi(optarg);
- break;
- case 's': /* Number of sockets */
- Nsock = atoi(optarg);
- break;
- case 'd': /* Root directory for various files */
- initroot(optarg);
- break;
- #ifdef __TURBOC__
- case 'b': /* Use BIOS for screen output */
- directvideo = 0;
- break;
- #endif
- case 'v':
- Verbose = 1;
- break;
- }
- }
- /* Get some memory on the heap so interrupt calls to malloc
- * won't fail unnecessarily
- */
- list = calloc(sizeof(void *),(hinit / 32768L) + 1);
- for(c=0;hinit > 0;hinit -= chunk){
- chunk = min(hinit,32768U);
- list[c++] = malloc(chunk);
- }
- while(c > 0)
- free(list[--c]);
- free(list);
- kinit();
- ipinit();
- ioinit();
- sockinit();
- Cmdpp = mainproc("cmdintrp");
- Sessions = (struct session **)callocw(Nsessions,sizeof(struct session *));
- Command = Lastcurr = newsession("command interpreter",COMMAND,1);
- Display = newproc("display",350,display,0,NULL,NULL,0);
- printf("KA9Q NOS version %sn",Version);
- #ifdef CPU386
- printf("Compiled for 386/486 CPUn");
- #endif
- printf("Copyright 1986-1995 by Phil Karn, KA9Qn");
- usercvt();
- /* Start background Daemons */
- for(tp=Daemons;;tp++){
- if(tp->name == NULL)
- break;
- newproc(tp->name,tp->stksize,tp->fp,0,NULL,NULL,0);
- }
- Encap.txproc = newproc("encap tx",512,if_tx,0,&Encap,NULL,0);
- if(optind < argc){
- /* Read startup file named on command line */
- if((fp = fopen(argv[optind],READ_TEXT)) == NULL){
- printf("Can't read config file %s",argv[optind]);
- perror("");
- }
- } else {
- fp = fopen(Startup,READ_TEXT);
- }
- if(fp != NULL){
- while(fgets(cmdbuf,sizeof(cmdbuf),fp) != NULL){
- rip(cmdbuf);
- if(Cmdline != NULL)
- free(Cmdline);
- Cmdline = strdup(cmdbuf);
- if(Verbose)
- printf("%sn",Cmdline);
- if(cmdparse(Cmds,cmdbuf,NULL) != 0){
- printf("input line: %sn",Cmdline);
- }
- }
- fclose(fp);
- }
- /* Now loop forever, processing commands */
- for(;;){
- printf(Prompt);
- fflush(stdout);
- if(fgets(cmdbuf,sizeof(cmdbuf),stdin) != NULL){
- rip(cmdbuf);
- if(Cmdline)
- free(Cmdline);
- Cmdline = strdup(cmdbuf);
- (void)cmdparse(Cmds,cmdbuf,Lastcurr);
- }
- }
- }
- /* Keyboard input process */
- void
- keyboard(i,v1,v2)
- int i;
- void *v1;
- void *v2;
- {
- int c;
- int j;
- /* Keyboard process loop */
- loop:
- c = kbread();
- #ifdef MSDOS
- if(c >= 256){
- /* Pass all special characters to app upcall */
- if(Current->ctlproc != NULL && (c = (*Current->ctlproc)(c)) == 0)
- goto loop; /* Upcall took them */
- c -= 256;
- if(Current->scrollmode == SCROLL_INBAND){
- /* In inband scroll mode, pass escape sequences
- * for cursor control keys. Otherwise fall thru
- */
- switch(c){
- case CURSHOM:
- pass("