home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
internet
/
netlite
/
NET
/
c
/
MAIN
< prev
next >
Wrap
Text File
|
1993-04-24
|
6KB
|
232 lines
/* Main network program - provides both client and server functions */
#define HOSTNAMELEN 32 /* changed from 16 by Bdale 860812 */
extern char startup[]; /* File to read startup commands from */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <ctype.h>
#include "werr.h"
#include "config.h"
#include "global.h"
#include "mbuf.h"
#include "netuser.h"
#include "timer.h"
#include "icmp.h"
#include "iface.h"
#include "ip.h"
#include "tcp.h"
#include "ftp.h"
#include "telnet.h"
#include "session.h"
#include "cmdparse.h"
#include "driver.h"
#include "asy.h"
#include "slip.h"
#include "trace.h"
#include "ethernet.h"
#include "internet.h"
#include "finger.h"
#include "ping.h"
#include "smtp.h"
#include "udp.h"
#include "domain.h"
#include "misc.h"
#include "arc.h"
/* Dummy structure for loopback tracing */
struct interface loopback = { NULLIF, "loopback" };
struct interface *ifaces;
extern struct mbuf *loopq;
char badhost[] = "Unknown host %s\n";
char hostname[HOSTNAMELEN];
unsigned nsessions = NSESSIONS;
int16 lport = 1001;
char nospace[] = "No space!!\n"; /* Generic malloc fail message */
static int donothing(int, char **);
static int doattach(int, char **);
static int doecho(int, char **);
static int doeol(int, char **);
static int dohostname(int, char **);
static int dostart(int, char **);
static void readconfig(void);
static struct cmds cmds[] = {
"", donothing, 0, NULLCHAR, NULLCHAR,
"attach", doattach, 2, "attach <hardware> <hw specific options>", NULLCHAR,
"colour", docolour, 0, NULLCHAR, NULLCHAR,
"domain", dodomain, 0, NULLCHAR, NULLCHAR,
"echo", doecho, 0, NULLCHAR, "echo [refuse|accept]",
"eol", doeol, 0, NULLCHAR, "eol options: unix, standard",
"hostname", dohostname, 0, NULLCHAR, NULLCHAR,
"ip", doip, 0, NULLCHAR, NULLCHAR,
"route", doroute, 0, NULLCHAR, NULLCHAR,
"smtp", dosmtp, 0, NULLCHAR, NULLCHAR,
"start", dostart, 2, "start <servername>",NULLCHAR,
"tcp", dotcp, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0, "Unknown command; type \"?\" for list", NULLCHAR,
};
/* "start" subcommands */
static struct cmds startcmds[] = {
"finger", finger1, 0, NULLCHAR, NULLCHAR,
"ftp", ftp1, 0, NULLCHAR, NULLCHAR,
"smtp", smtp1, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0,
"start options: finger, ftp, smtp", NULLCHAR,
};
void net_init(void)
{
sessions = (struct session *)calloc(nsessions,sizeof(struct session));
readconfig();
}
void net_poll(void)
{
struct interface *ifp;
struct mbuf *bp;
struct ip ip;
/* Service the loopback queue */
if((bp = dequeue(&loopq)) != NULLBUF){
ntohip(&ip,&bp);
ip_recv(&ip,bp,0);
}
/* Service the interfaces */
for(ifp = ifaces; ifp != NULLIF; ifp = ifp->next){
if(ifp->recv != NULLFP)
(*ifp->recv)(ifp);
}
/* Service the clock if it has ticked */
check_time();
}
void iostop(void)
{
struct interface *ifp;
/* Stop the interfaces */
for(ifp = ifaces; ifp != NULLIF; ifp = ifp->next){
if(ifp->stop != NULLFP)
(*ifp->stop)(ifp);
}
}
static int donothing(int argc, char **argv)
{
argc = argc;
argv = argv;
return 0;
}
static int dohostname(int argc, char **argv)
{
if (argc > 1) strncpy(hostname,argv[1],HOSTNAMELEN);
return 0;
}
static int doecho(int argc, char **argv)
{
extern int refuse_echo;
if (argc > 1) {
if(argv[1][0] == 'r')
refuse_echo = 1;
else if(argv[1][0] == 'a')
refuse_echo = 0;
else
return -1;
}
return 0;
}
/* set for unix end of line for remote echo mode telnet */
static int doeol(int argc, char **argv)
{
extern int unix_line_mode;
if (argc > 1) {
if(strcmp(argv[1],"unix") == 0)
unix_line_mode = 1;
else if(strcmp(argv[1],"standard") == 0)
unix_line_mode = 0;
else {
return -1;
}
}
return 0;
}
/* Attach an interface
* Syntax: attach <hw type> <port> <mode> <label> <mtu> <speed>
*/
static int doattach(int argc, char **argv)
{
extern struct cmds attab[];
return subcmd(attab,argc,argv);
}
/* Configuration-dependent code */
/* List of supported hardware devices */
struct cmds attab[] = {
/* Ordinary asynchronous adaptor */
"asy", asy_attach, 7,
"attach asy internal <port> <mode> <label> <mtu> <speed>",
"Could not attach asy",
/* Driver spec asynchronous adaptor */
"driver", driver_attach, 7,
"attach driver <driver> <port> <mode> <label> <mtu> <speed>",
"Could not attach driver",
/* Ethernet driver via DCI */
"ether", ether_attach, 4,
"attach ether <port> <label> <mtu>",
"Could not attach ether",
NULLCHAR, NULLFP, 0,
"Unknown device",
NULLCHAR,
};
static int dostart(int argc, char **argv)
{
return subcmd(startcmds,argc,argv);
}
static void readconfig(void)
{
static char inbuf[200],savebuf[200]; /* keep it off the stack */
int linenum = 0;
FILE *fp;
if((fp = fopen(startup,"r")) == NULLFILE){
werr(1,"Cannot open startup file\n");
return;
}
while(fgets(inbuf,sizeof(inbuf),fp) != NULLCHAR){
rip(inbuf);
strcpy(savebuf,inbuf);
linenum++;
if(cmdparse(cmds,inbuf) != 0)
werr(0,"startup: line %d: %s\n",linenum,savebuf);
}
fclose(fp);
}