home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B23.ZIP
/
NETWORK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-01
|
44KB
|
1,756 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <mem.h>
#include <conio.h>
#include <io.h>
#include <share.h>
#include <errno.h>
#include <malloc.h>
#include <dir.h>
#include <time.h>
#include <process.h>
#include <direct.h>
#include "vardec.h"
#include "net.h"
#include "version.h"
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define MAX_PATH 79
#define SHARE_LEVEL 10
#define WAIT_TIME 10
#define TRIES 100
#define MT_DESQVIEW 0x01
#define MT_WINDOWS 0x02
#define MT_OS2 0x04
#define MT_NB 0x40
#define VIDEO 0x10
#define INI_NETWORK 0x01
#define INI_GENERAL 0x02
#define INI_NEWS 0x04
char *version = "Freeware PPP Net Packet Engine " VERSION;
char *author = "Contact Frank Reid at edare@abs.net or 1@8213.WWIVnet for support";
unsigned _stklen = 15360;
configrec syscfg;
configoverrec syscfgovr;
net_networks_rec netcfg;
net_system_list_rec *netsys;
int multitasker = 0, ini_section = 0;
char wwiv_net_no[20], maindir[121];
char net_name[16], net_data[121];
unsigned short net_sysnum;
int num_sys_list, net_num, net_num_max, netnum, ninst;
static int lsl_loaded;
char SMTPHOST[60], POPHOST[60], NEWSHOST[60], POPNAME[60], POPPASS[25];
char IPADDR[21], NETMASK[21];
char DNS[21], DOMAIN[60], GATEWAY[60], tempdir[MAXPATH];
unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0, TIMEOUT = 60, SOCK_DELAY = 30, SOCK_INACTIVE = 60;
unsigned int ONECALL = 0;
int instance;
char *xenviron[50];
void dv_pause(void)
{
__emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
}
void win_pause(void)
{
__emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
}
int get_dos_version(void)
{
_AX = 0x3000;
geninterrupt(0x21);
if (_AX % 256 >= 10) {
multitasker |= MT_OS2;
}
return (_AX);
}
int get_dv_version(void)
{
int v;
if (multitasker & MT_OS2)
return 0;
_AX = 0x2b01;
_CX = 0x4445;
_DX = 0x5351;
geninterrupt(0x21);
if (_AL == 0xff) {
return 0;
} else {
v = _BX;
multitasker |= MT_DESQVIEW;
return v;
}
}
int get_win_version(void)
{
int v = 0;
__emit__(0x55, 0x06, 0x53);
_AX = 0x352f;
geninterrupt(0x21);
_AX = _ES;
if (_AX | _BX) {
_AX = 0x1600;
geninterrupt(0x2f);
v = _AX;
if (v % 256 <= 1)
v = 0;
}
__emit__(0x5b, 0x07, 0x5d);
if (v != 0)
multitasker |= MT_WINDOWS;
return (v);
}
int get_nb_version(void)
{
_AX = 0;
geninterrupt(0x2A);
return (_AH);
}
void detect_multitask(void)
{
get_dos_version();
get_win_version();
get_dv_version();
}
void giveup_timeslice(void)
{
if (multitasker) {
switch (multitasker) {
case 1:
case 3:
dv_pause();
break;
case 2:
case 4:
case 5:
case 6:
case 7:
win_pause();
break;
default:
break;
}
}
}
char *stripspace(char *str)
{
char *obuf, *nbuf;
if (str) {
for (obuf = str, nbuf = str; *obuf; ++obuf) {
if (!isspace(*obuf))
*nbuf++ = *obuf;
}
*nbuf = NULL;
}
return (str);
}
int sh_write(int handle, void *buffer, unsigned long len)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buffer, (unsigned) len));
}
int sh_open(char *path, int file_access, unsigned fmode)
{
int handle, count, share;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
share = SH_DENYRW;
} else {
share = SH_DENYWR;
}
handle = open(path, file_access | share, fmode);
if (handle < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
handle = open(path, file_access | share, fmode);
while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
if (count % 2)
delay(WAIT_TIME);
else
giveup_timeslice();
count++;
handle = open(path, file_access | share, fmode);
}
}
}
return (handle);
}
int sh_open1(char *path, int access)
{
unsigned fmode;
fmode = 0;
if ((access & O_RDWR) || (access & O_WRONLY))
fmode |= S_IWRITE;
if ((access & O_RDWR) || (access & O_RDONLY))
fmode |= S_IREAD;
return (sh_open(path, access, fmode));
}
int sh_close(int f)
{
if (f != -1)
close(f);
return (-1);
}
int sh_read(int handle, void *buf, unsigned len)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, len));
}
long sh_lseek(int handle, long offset, int fromwhere)
{
if (handle == -1) {
return (-1L);
}
return (lseek(handle, offset, fromwhere));
}
FILE *fsh_open(char *path, char *fmode)
{
FILE *f;
int count, share, md, fd;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
share = SH_DENYWR;
md = 0;
if (((char *) _fstrchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) _fstrchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) _fstrchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) _fstrchr(fmode, '+')) != NULL) {
md &= ~O_RDONLY;
md |= O_RDWR;
share = SH_DENYRD;
}
fd = open(path, md | share, S_IREAD | S_IWRITE);
if (fd < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if ((access(path, 0)) != -1) {
delay(WAIT_TIME);
fd = open(path, md | share, S_IREAD | S_IWRITE);
while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
delay(WAIT_TIME);
count++;
fd = open(path, md | share, S_IREAD | S_IWRITE);
}
}
}
if (fd > 0) {
if (((char *) _fstrchr(fmode, 'a')) != NULL)
sh_lseek(fd, 0L, SEEK_END);
f = fdopen(fd, fmode);
if (!f) {
close(fd);
}
} else
f = 0;
return (f);
}
void backline(void)
{
int i;
fprintf(stderr, " ");
for (i = wherex(); i > 0; i--)
fprintf(stderr, "\b \b");
}
int do_spawn(char *cl)
{
int i, i1, l;
char *s, *ss[50];
s = strdup(cl);
ss[0] = s;
i = 1;
l = strlen(s);
for (i1 = 1; i1 < l; i1++)
if (s[i1] == 32) {
s[i1] = 0;
ss[i++] = &(s[i1 + 1]);
}
ss[i] = NULL;
i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
free(s);
return (i);
}
void unload_klos(void)
{
char s[101];
sprintf(s, "%s\\IPSTUB U", maindir);
do_spawn(s);
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
}
void cd_to(char *s)
{
char *s1;
int i, db;
s1 = s;
i = strlen(s1) - 1;
db = (s1[i] == '\\');
if (i == 0)
db = 0;
if ((i == 2) && (s1[1] == ':'))
db = 0;
if (db)
s1[i] = 0;
chdir(s1);
if (s[1] == ':')
setdisk(s[0] - 'A');
}
void get_dir(char *s, int be)
{
strcpy(s, "X:\\");
s[0] = 'A' + getdisk();
getcurdir(0, s + 3);
if (be) {
if (s[strlen(s) - 1] != '\\')
strcat(s, "\\");
}
}
unsigned char *trimstr1(unsigned char *s)
{
int i;
static char *whitespace = " \r\n\t";
i = (int) strlen(s);
while ((i > 0) && ((char *) _fstrchr(whitespace, s[i - 1]) != NULL))
--i;
while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
memmove(s, s + 1, --i);
}
s[i] = NUL;
return (s);
}
char *make_abs_path(unsigned char *checkdir)
{
char newdir[121];
if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
cd_to(maindir);
cd_to(checkdir);
if (LAST(checkdir) == '\\')
get_dir(newdir, 1);
else
get_dir(newdir, 0);
cd_to(maindir);
strcpy(checkdir, newdir);
}
return checkdir;
}
int exist(char *s)
{
int i;
struct ffblk ff;
i = findfirst(s, &ff, 0);
if (i)
return (0);
else
return (1);
}
void set_net_num(int n)
{
char s[121];
int f;
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0)
return;
lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
sh_read(f, &netcfg, sizeof(net_networks_rec));
close(f);
net_num = n;
net_sysnum = netcfg.sysnum;
strcpy(net_name, netcfg.name);
strcpy(net_data, make_abs_path(netcfg.dir));
if (LAST(net_data) != '\\')
strcat(net_data, "\\");
sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
}
int make_path(char *s)
{
unsigned int i;
char drive, current_path[MAX_PATH], current_drive, *p, *flp;
union REGS r;
p = flp = strdup(s);
_getdcwd(0, current_path, MAX_PATH);
current_drive = *current_path - '@';
if (LAST(s) == '\\')
LAST(s) = 0;
if (p[1] == ':') {
drive = toupper(p[0]) - 'A' + 1;
if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
r.x.ax = 0x4409;
r.h.bl = drive;
int86(0x21, &r, &r);
if (r.x.cflag)
return -3;
}
if (_chdrive(drive)) {
chdir(current_path);
_dos_setdrive(current_drive, &i);
return -2;
}
p += 2;
}
if (*p == '\\') {
chdir("\\");
p++;
}
for (; (p = strtok(p, "\\")) != 0; p = 0) {
if (chdir(p)) {
if (mkdir(p)) {
chdir(current_path);
_dos_setdrive(current_drive, &i);
return -1;
}
chdir(p);
}
}
chdir(current_path);
if (flp)
free(flp);
return 0;
}
void rename_pend(char *dir, char *file)
{
char s[121], s1[121], s2[121];
int i;
sprintf(s, "%s%s", dir, file);
if (atoi(file + 1))
strcpy(s2, "P1-");
else
strcpy(s2, "P0-");
for (i = 0; i < 1000; i++) {
sprintf(s1, "%s%s%u.NET", dir, s2, i);
if (!rename(s, s1) || (errno != EACCES))
break;
}
}
int process_mail(void)
{
char s[121];
int f1, i, i1, i2, done, ok;
struct ffblk ff;
sprintf(s, "%s\\FLINK.EXE", maindir);
if (exist(s))
do_spawn(s);
sprintf(s, "%s\\LINKER.EXE", maindir);
if (exist(s))
do_spawn(s);
done = 0;
for (i2 = 0; i2 < 2; i2++) {
for (i = 0; i < net_num_max; i++) {
set_net_num(i);
ok = 0;
fprintf(stderr, "\r ■ Cleaning up pending packets : %-20s", net_name);
for (i1 = 0; i1 < ninst; i1++) {
sprintf(s, "%sP*.%3.3d", net_data, i1);
f1 = findfirst(s, &ff, 0);
while (f1 == 0) {
rename_pend(net_data, ff.ff_name);
f1 = findnext(&ff);
ok = 1;
}
}
if (!ok) {
sprintf(s, "%sP*.NET", net_data);
ok = (findfirst(s, &ff, 0) == 0);
}
if (ok) {
sprintf(s, "NETWORK1 .%d", net_num);
do_spawn(s);
done = 1;
}
ok = 0;
sprintf(s, "%sLOCAL.NET", net_data);
ok = (findfirst(s, &ff, 0) == 0);
if (ok) {
fprintf(stderr, "\n ■ Processing packets in %s...\n", net_name);
sprintf(s, "NETWORK2 .%d", net_num);
do_spawn(s);
done = 1;
} else {
fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%-20s", "Done!");
}
}
}
return done;
}
int valid_system(unsigned int ts)
{
int i;
for (i = 0; i < num_sys_list; i++) {
if (netsys[i].sysnum == ts) {
if (netsys[i].numhops == 1)
return (1);
else
return (0);
}
}
return (0);
}
void good_addr(char *address, unsigned short sn)
{
char *ss, fn[101], s[81];
unsigned short node;
FILE *fp;
sprintf(fn, "%sADDRESS.NET", net_data);
fp = fsh_open(fn, "rt");
if (!fp) {
fprintf(stderr, "\n ■ %s not found.", fn);
return;
}
while (fgets(s, 80, fp) != NULL) {
if (s[0] != '@')
continue;
ss = strtok(s, " ");
node = atoi(&ss[1]);
if (node == sn) {
ss = strtok(NULL, "\r");
trimstr1(ss);
strcpy(address, ss);
break;
}
}
fclose(fp);
}
int copyfile(char *input, char *output)
{
int f1, f2, i;
char *b;
struct ftime ft;
if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
if ((b = (char *) malloc(16400)) == NULL)
return 0;
f1 = sh_open1(input, O_RDONLY | O_BINARY);
if (!f1) {
free(b);
b = NULL;
return 0;
}
getftime(f1, &ft);
f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (!f2) {
free(b);
b = NULL;
sh_close(f1);
return 0;
}
i = read(f1, (void *) b, 16384);
while (i > 0) {
sh_write(f2, (void *) b, i);
i = read(f1, (void *) b, 16384);
}
f1 = sh_close(f1);
setftime(f2, &ft);
f2 = sh_close(f2);
free(b);
b = NULL;
}
return 1;
}
int uu(char *fn, char *pktname, char *dest)
{
int ok;
char s[121], s1[121], s2[81];
FILE *fp;
sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
if ((fp = fsh_open(s, "wt")) == NULL) {
fprintf(stderr, "\n ■ Unable to open %s for write operations!", s);
exit(EXIT_FAILURE);
} else {
sprintf(s2, "from: %s@%s\n", POPNAME, DOMAIN);
fprintf(fp, s2);
sprintf(s2, "to: %s\n", dest);
fprintf(fp, s2);
sprintf(s2, "subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
fprintf(fp, s2);
}
fclose(fp);
sprintf(s1, "%s\\UU -encode %s %s", maindir, fn, s);
ok = do_spawn(s1);
return ok;
}
int uu_packets(void)
{
char fn[121], pktname[21], s[121], s1[121], s2[121], s3[121], destaddr[101], *ss, temp[121];
int found, sz, f;
long fpos;
unsigned short node;
FILE *fp;
sprintf(s, "%sBBSDATA.NET", net_data);
f = sh_open1(s, O_RDONLY | O_BINARY);
num_sys_list = 0;
if (f > 0) {
num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
if ((netsys = (net_system_list_rec *) malloc((num_sys_list + 2) *
sizeof(net_system_list_rec))) == NULL) {
fprintf(stderr, "\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
(int) (num_sys_list + 2) * sizeof(net_system_list_rec));
sh_close(f);
return 0;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
sh_close(f);
} else
return 0;
sprintf(fn, "%sADDRESS.NET", net_data);
fp = fsh_open(fn, "rt");
if (!fp) {
free(netsys);
return 0;
}
found = 0;
while (fgets(s, 80, fp) != NULL) {
node = 0;
if (s[0] != '@')
continue;
ss = strtok(s, " ");
node = atoi(&ss[1]);
if ((valid_system(node)) && (node != 32767)) {
sprintf(s1, "%sS%hd.NET", net_data, node);
if (exist(s1))
sz = 0;
else {
sprintf(s1, "%sZ%hd.NET", net_data, node);
if (exist(s1))
sz = 1;
else
continue;
}
do {
sprintf(pktname, "%lx", time(NULL));
sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
} while (exist(temp));
good_addr(destaddr, node);
backline();
fprintf(stderr, "\r ■ Encoding %s%hd.NET as %s.UUE -",
sz ? "Z" : "S", node, strupr(pktname));
fpos = ftell(fp);
fclose(fp);
if ((uu(s1, pktname, destaddr)) == EXIT_FAILURE) {
fprintf(stderr, "\n ■ Error creating %sMQUEUE\\%s.UUE", net_data, pktname);
free(netsys);
exit(EXIT_FAILURE);
} else {
found = 1;
if (KEEPSENT) {
sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
if (!copyfile(s3, s2))
fprintf(stderr, "\n ■ Error moving %s%hd.NET", sz ? "Z" : "S", node);
}
unlink(s1);
}
fp = fsh_open(fn, "rt");
fseek(fp, fpos, 0);
} else {
continue;
}
ss = strtok(NULL, "\r");
ss = NULL;
}
if (netsys)
free(netsys);
fclose(fp);
return found;
}
int purge_sent(void)
{
char s[121];
int f1, howmany = 0;
long age;
struct ffblk ff;
struct stat fileinfo;
sprintf(s, "%sSENT\\*.*", net_data);
f1 = findfirst(s, &ff, 0);
while (f1 == 0) {
sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
if (stat(s, &fileinfo) == 0) {
age = (time(NULL) - fileinfo.st_atime);
if (age > (86400L * KEEPSENT)) {
++howmany;
unlink(s);
}
}
f1 = findnext(&ff);
}
return howmany;
}
/****************************************************************************/
int parse_net_ini(void)
{
char cursect;
char line[121], *ss;
FILE *fp;
fp = fsh_open("NET.INI", "rt");
if (!fp)
return (0);
while (fgets(line, 80, fp)) {
stripspace(line);
ss = NULL;
ss = strtok(line, "=");
if (ss)
ss = strtok(NULL, "\n");
/* fprintf(stderr, "\nCurrent : %s\n", line); */
if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
continue;
if ((strnicmp(line, "[FILENET]", 9) == 0) ||
(strnicmp(line, "[PPPNET]", 8) == 0)) {
cursect = INI_NETWORK;
ini_section |= INI_NETWORK;
continue;
}
if (strnicmp(line, "[GENERAL]", 9) == 0) {
cursect = INI_GENERAL;
ini_section |= INI_GENERAL;
continue;
}
if (strnicmp(line, "[NEWS]", 6) == 0) {
cursect = INI_NEWS;
ini_section |= INI_NEWS;
continue;
}
if (cursect & INI_NETWORK) {
if (strnicmp(line, "SMTPHOST", 8) == 0) {
if (ss)
strcpy(SMTPHOST, ss);
continue;
}
if (strnicmp(line, "POPHOST", 7) == 0) {
if (ss)
strcpy(POPHOST, ss);
continue;
}
if (strnicmp(line, "POPNAME", 7) == 0) {
if (ss)
strcpy(POPNAME, ss);
continue;
}
if (strnicmp(line, "POPPASS", 7) == 0) {
if (ss)
strcpy(POPPASS, ss);
continue;
}
}
if (cursect & INI_GENERAL) {
if (strnicmp(line, "TIMEOUT", 7) == 0) {
if (atoi(ss))
TIMEOUT = atoi(ss);
continue;
}
if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
if (atoi(ss))
SOCK_DELAY = atoi(ss);
continue;
}
if (strnicmp(line, "SOCK_INACTIVE", 13) == 0) {
if (atoi(ss))
SOCK_INACTIVE = atoi(ss);
continue;
}
if (strnicmp(line, "KEEPSENT", 8) == 0) {
if (atoi(ss))
KEEPSENT = atoi(ss);
continue;
}
if (strnicmp(line, "ALLMAIL", 7) == 0) {
if (toupper(ss[0]) == 'N')
ALLMAIL = 0;
continue;
}
if (strnicmp(line, "ONECALL", 7) == 0) {
if (toupper(ss[0]) == 'Y')
ONECALL = 1;
continue;
}
if (strnicmp(line, "MOREINFO", 8) == 0) {
if (toupper(ss[0]) == 'Y')
MOREINFO = 1;
continue;
}
if (strnicmp(line, "CLEANUP", 7) == 0) {
if (toupper(ss[0]) == 'Y')
CLEANUP = 1;
continue;
}
if (strnicmp(line, "IPADDR", 6) == 0) {
if ((ss) && (ss[0] != '0'))
strcpy(IPADDR, ss);
continue;
}
if (strnicmp(line, "NETMASK", 7) == 0) {
if (ss)
strcpy(NETMASK, ss);
continue;
}
if (strnicmp(line, "DNS", 3) == 0) {
if (ss)
strcpy(DNS, ss);
continue;
}
if (strnicmp(line, "DOMAIN", 6) == 0) {
if (ss)
strcpy(DOMAIN, ss);
continue;
}
if (strnicmp(line, "GATEWAY", 7) == 0) {
if ((ss) && (ss[0] != '0'))
strcpy(GATEWAY, ss);
continue;
}
}
if (cursect & INI_NEWS) {
if (strnicmp(line, "NEWSHOST", 8) == 0) {
if (ss)
strcpy(NEWSHOST, ss);
continue;
}
}
}
fclose(fp);
return (1);
}
int write_contact(unsigned short sy2, unsigned long sb, unsigned long rb, int sent, int news)
{
char s[101], buf[81];
int i, i1, f;
long cur_time, l;
unsigned short sy;
FILE *fp;
sprintf(s, "%sCONTACT.NET", net_data);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f >= 0) {
l = filelength(f);
netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
if ((netcfg.ncn = (net_contact_rec *) malloc((netcfg.num_ncn + 2) *
sizeof(net_contact_rec))) == NULL) {
fprintf(stderr, "\n ■ Unable to allocate %d bytes of memory to update CONTACT.NET",
(int) (netcfg.num_ncn + 2) * sizeof(net_contact_rec));
sh_close(f);
return 1;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netcfg.ncn,
netcfg.num_ncn * sizeof(net_contact_rec));
sh_close(f);
}
sprintf(s, "%sCALLOUT.NET", net_data);
fp = fsh_open(s, "rt");
if (!fp) {
fprintf(stderr, "\n ■ Unable to access %sCALLOUT.NET", net_data);
if (netcfg.ncn)
free(netcfg.ncn);
return 1;
}
while (fgets(buf, 80, fp) != NULL) {
if (buf[0] != '@')
continue;
sy = atoi(&buf[1]);
if ((news) && (sy != 32767))
continue;
else {
if ((!news) && (sy == 32767))
continue;
}
for (i = 0; i < netcfg.num_ncn; i++)
if (netcfg.ncn[i].systemnumber == sy)
i1 = i;
time(&cur_time);
netcfg.ncn[i1].lasttry = cur_time;
if (!sent) {
netcfg.ncn[i1].numfails++;
} else {
++netcfg.ncn[i1].numcontacts;
if (!netcfg.ncn[i1].firstcontact)
netcfg.ncn[i1].firstcontact = cur_time;
netcfg.ncn[i1].lastcontact = cur_time;
netcfg.ncn[i1].lastcontactsent = cur_time;
if (sy == sy2) {
netcfg.ncn[i1].bytes_sent += sb;
if (rb)
netcfg.ncn[i1].bytes_received += rb;
}
netcfg.ncn[i1].bytes_waiting = 0L;
sprintf(s, "%sS%hd.net", net_data, sy);
if (!exist(s))
sprintf(s, "%sZ%hd.net", net_data, sy);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f > 0) {
netcfg.ncn[i1].bytes_waiting += filelength(f);
close(f);
}
}
sprintf(s, "%sCONTACT.NET", net_data);
f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
if (f > 0) {
sh_lseek(f, 0L, SEEK_SET);
sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn *
sizeof(net_contact_rec));
sh_close(f);
}
}
if (netcfg.ncn)
free(netcfg.ncn);
fclose(fp);
return 0;
}
long count_lines(char *s)
{
FILE *fp;
char fn[121];
long int nl = 0;
const int NEWLINE = '\n';
int c;
strcpy(fn, s);
fp = fsh_open(fn, "rt");
if (fp == NULL) {
printf("\n ■ Cannot open %s", fn);
return 0;
}
while ((c = getc(fp)) != EOF) {
if (c == NEWLINE)
++nl;
}
fclose(fp);
return nl;
}
typedef struct {
char line[81];
} nlines;
nlines *NETLOG;
int write_netlog(int sn, long sent, long recd, char *tmused)
{
FILE *fp;
int i = 0;
unsigned lines = 0L;
char s[81], s1[81], s2[81], fn[121];
struct tm *time_now;
time_t some;
sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
lines = count_lines(fn);
if ((NETLOG = ((nlines *) malloc((lines + 2) * 81))) == NULL) {
fprintf(stderr, "\n ■ Unable to allocate %d bytes for NET.LOG entry",
(lines + 2) * 81);
return 1;
}
fp = fsh_open(fn, "r");
if (!fp)
return 1;
while (fgets(s, 80, fp)) {
strtok(s, "\n");
strcpy(NETLOG[i++].line, s);
}
fclose(fp);
time(&some);
time_now = localtime(&some);
strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
if ((sent) || (recd)) {
if ((recd) && (!sent))
sprintf(s2, " R:%4ldk,", recd);
else {
if ((recd) && (sent))
sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
else
sprintf(s2, "S:%4ldk, ", sent);
}
} else
strcpy(s2, " ");
fp = fsh_open(fn, "wt+");
fprintf(fp, "%s To %5d, %s %4s min %s\n", s1, sn, s2,
tmused, net_name);
for (i = 0; i < lines; i++)
fprintf(fp, "%s\n", NETLOG[i].line);
if (NETLOG)
free(NETLOG);
NETLOG = NULL;
fclose(fp);
return 0;
}
void read_networks(void)
{
int f;
char s[121];
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
net_num_max = 0;
if (f > 0) {
net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
sh_close(f);
}
}
void init(void)
{
char s[81], s1[81], *ss;
int i, i1, dv, f;
struct tm *time_now;
time_t some;
fprintf(stderr, "\n%s\n%s\n\n", version, author);
get_dir(maindir, 0);
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance > 999)) {
fprintf(stderr, "\n ■ WWIV_INSTANCE can only be 1..999!");
instance = 1;
}
} else {
instance = 1;
}
if (get_nb_version())
multitasker = 8;
else
detect_multitask();
switch (multitasker) {
case 1:
dv = get_dv_version();
sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
break;
case 2:
dv = get_win_version();
if (dv == 4)
strcpy(s1, "Windows 95");
else
sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
break;
case 3:
dv = get_dv_version();
sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
break;
case 4:
case 5:
case 6:
case 7:
if ((_osmajor / 10 == 2) && (_osminor >= 30))
strcpy(s1, "OS/2 Warp");
else
sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
break;
case 8:
sprintf(s1, "NETBIOS network");
multitasker = 1;
break;
default:
strcpy(s1, "DOS");
break;
}
strcpy(s, "CONFIG.DAT");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
fprintf(stderr, "\n ■ %s NOT FOUND.", s);
return;
}
sh_read(f, (void *) (&syscfg), sizeof(configrec));
sh_close(f);
fprintf(stderr, " ■ Running under %s on instance %d ", s1, instance);
time(&some);
time_now = localtime(&some);
strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
printf(s);
strcpy(s, "CONFIG.OVR");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
fprintf(stderr, "\n ■ %s NOT FOUND.", s);
return;
}
sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
read(f, &syscfgovr, sizeof(configoverrec));
f = sh_close(f);
sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
fprintf(stderr, "\n ■ %s NOT FOUND.", s);
return;
}
ninst = (int) ((filelength(f) / (long) sizeof(instancerec)));
f = sh_close(f);
read_networks();
i = i1 = 0;
while (environ[i] != NULL) {
xenviron[i1++] = environ[i];
++i;
}
xenviron[i1] = NULL;
}
long getfctime(char *s)
{
struct stat statbuf;
if (stat(s, &statbuf) < 0)
return (0L);
else
return (statbuf.st_atime);
}
int process_bbsdata(void)
{
char s[101];
unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
int tf, n, net3;
net3 = 0;
sprintf(s, "%sBBSLIST.NET", net_data);
bbslist_ctime = getfctime(s);
sprintf(s, "%sCONNECT.NET", net_data);
connect_ctime = getfctime(s);
sprintf(s, "%sCALLOUT.NET", net_data);
callout_ctime = getfctime(s);
sprintf(s, "%sBBSDATA.NET", net_data);
bbsdata_ctime = getfctime(s);
sprintf(s, "%sBBSLIST.UPD", net_data);
bbslist_ctime = getfctime(s);
sprintf(s, "%sCONNECT.UPD", net_data);
connect_ctime = getfctime(s);
n = 0;
tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
if (tf)
n = 1;
tf = (tf || (callout_ctime > bbsdata_ctime));
if (tf) {
sprintf(s, "NETWORK3 .%d", netnum);
if (n) {
sprintf(s, "NETWORK3 .%d Y", netnum);
net3 = 1;
}
do_spawn(s);
}
return (net3);
}
void do_it(char *cl)
{
int i, i1, l;
char *s, *ss[30];
s = strdup(cl);
ss[0] = s;
i = 1;
l = strlen(s);
for (i1 = 1; i1 < l; i1++)
if (s[i1] == 32) {
s[i1] = 0;
ss[i++] = &(s[i1 + 1]);
}
ss[i] = NULL;
execvpe(ss[0], ss, xenviron);
}
int create_wattcp_cfg(void)
{
char s[101], s1[41];
FILE *fp;
if ((fp = fsh_open("WATTCP.CFG", "wt+")) == NULL) {
fprintf(stderr, "\n ■ Can't open %s for output!", s);
return 1;
}
sprintf(s, "my_ip=%s\n", IPADDR);
fprintf(fp, s);
fprintf(fp, "netmask=%s\n", NETMASK);
fprintf(fp, "nameserver=%s\n", DNS);
if (GATEWAY[0] == 0) {
strcpy(s1, IPADDR);
while (LAST(s1) != '.')
LAST(s1) = 0;
strcat(s1, "1");
strcpy(GATEWAY, s1);
}
sprintf(s, "gateway=%s\n", GATEWAY);
fprintf(fp, s);
fprintf(fp, "domainslist=\"%s\"\n", DOMAIN);
fprintf(fp, "hostname=\"%s\"\n", POPNAME);
fprintf(fp, "sockdelay=\"%d\"\n", SOCK_DELAY);
fprintf(fp, "sockinactive=\"%d\"\n", SOCK_INACTIVE);
fclose(fp);
return 0;
}
int check_for_lsl(void)
{
union REGS r;
struct SREGS s;
char *intstr;
for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
r.h.al = 0;
int86x(0x2f, &r, &r, &s);
if (r.h.al == 0xff) {
intstr = (char *) MK_FP(s.es, r.x.si);
if (strncmp(intstr, "LINKSUP$", 8) == 0)
return 1;
}
}
return 0;
}
void klos_ppp(void)
{
char s[121], *ss;
int i;
FILE *fp;
lsl_loaded = check_for_lsl();
if (!lsl_loaded) {
sprintf(s, "%s\\LSL.COM", maindir);
if (exist(s)) {
fprintf(stderr, "\n ■ Loading Link Support Layer and ");
do_spawn(s);
} else {
fprintf(stderr, "\n ■ LSL.COM not in BBS main directory!");
exit(EXIT_FAILURE);
}
} else
fprintf(stderr, "\n ■ LSL already in memory - loading ");
sprintf(s, "%s\\PPP.EXE", maindir);
if (exist(s)) {
fprintf(stderr, "PPP packet driver... ");
do_spawn(s);
} else {
fprintf(stderr, "\n ■ KLOS PPP.EXE not in BBS main directory!");
exit(EXIT_FAILURE);
}
sprintf(s, "%s\\PPPSTATE.EXE", maindir);
if (exist(s)) {
fprintf(stderr, "\n ■ Dialing %s and waiting %d seconds for connection... ", DOMAIN, TIMEOUT);
sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
i = do_spawn(s);
switch (i) {
case 0:
fprintf(stderr, " connected!");
break;
case 1:
fprintf(stderr, "\n ■ Unable to establish connection... aborting");
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
exit(EXIT_FAILURE);
case 2:
fprintf(stderr, "\n ■ Unable to find PPP layer... aborting");
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
exit(EXIT_FAILURE);
default:
fprintf(stderr, "\n ■ Unknown PPPState Error #%d... aborting", i);
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
exit(EXIT_FAILURE);
}
} else {
fprintf(stderr, "\n ■ PPPSTATE.EXE not in BBS main directory!");
exit(EXIT_FAILURE);
}
sprintf(s, "%s\\PPPWAT.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
fprintf(stderr, "\n ■ KLOS PPPWAT.EXE not in BBS main directory!");
exit(EXIT_FAILURE);
}
if (!IPADDR[0]) {
fp = fsh_open("WATTCP.CFG", "rt");
if (fp) {
while (fgets(s, 80, fp) != NULL) {
if (strnicmp(s, "my_ip", 5) == 0) {
ss = strtok(s, "=");
ss = strtok(NULL, "\r");
trimstr1(ss);
strcpy(IPADDR, ss);
break;
}
}
fclose(fp);
}
}
if (IPADDR) {
create_wattcp_cfg();
fprintf(stderr, "\n ■ IP address is %s... ", IPADDR);
} else {
fprintf(stderr, "\n ■ Could not find IP Address for WATTCP.CFG... aborting!");
unload_klos();
exit(EXIT_FAILURE);
}
sprintf(s, "%s\\IPSTUB.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
fprintf(stderr, "\n ■ KLOS PPPWAT.EXE not in BBS main directory!");
exit(EXIT_FAILURE);
}
fprintf(stderr, "establishing socket ");
for (i = 5; i >= 0; i--) {
fprintf(stderr, "\b\b\b\b%d...", i);
sleep(1);
}
fprintf(stderr, "\b\b\b\b- ready!");
}
double freek(int dr)
{
float d;
struct dfree df;
getdfree(dr, &df);
d = (float) df.df_avail;
d *= ((float) df.df_bsec);
d *= ((float) df.df_sclus);
d /= 1024.0;
if (df.df_sclus == 0xffff)
d = -1.0;
return (d);
}
int main(int argc, char *argv[])
{
int i, ok, news, send, f1;
unsigned short sy;
double dspace;
char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
char ttotal[21];
clock_t starttime;
unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
FILE *fp;
struct ffblk ff;
init();
news = 0;
ss = argv[argc - 1];
ok = 0;
if (_fstrstr((char *) ss, ".") != NULL) {
if (atoi(&ss[1]) < net_num_max) {
netnum = atoi(&ss[1]);
ok = 1;
}
} else {
ss = (getenv("WWIV_NET"));
netnum = atoi(ss);
if (netnum < net_num_max)
ok = 1;
}
if (!ok) {
strcpy(s, "WWIV_NET.DAT");
if ((fp = fsh_open(s, "rb")) != NULL) {
fgets(s, 3, fp);
netnum = atoi(s);
fclose(fp);
if (netnum < net_num_max)
ok = 1;
}
}
ss = argv[1];
if (strncmpi(ss, "/N", 2))
ok = 0;
if (ok) {
SMTPHOST[0] = 0;
POPHOST[0] = 0;
NEWSHOST[0] = 0;
POPNAME[0] = 0;
POPPASS[0] = 0;
IPADDR[0] = 0;
NETMASK[0] = 0;
DNS[0] = 0;
DOMAIN[0] = 0;
GATEWAY[0] = 0;
if (parse_net_ini()) {
set_net_num(netnum);
if (ini_section & INI_NETWORK) {
if (!(ini_section & INI_GENERAL)) {
fprintf(stderr, "\n ■ [GENERAL] tag missing from NET.INI!");
ok = 0;
}
} else {
ok = 0;
fprintf(stderr, "\n ■ [FILENET] tag missing from NET.INI!");
}
} else {
fprintf(stderr, "\n ■ Could not open file NET.INI!");
ok = 0;
}
}
if (ok) {
fprintf(stderr, "\n ■ Available memory : %lu bytes...", coreleft());
if (net_data[1] == ':')
i = net_data[0];
else
i = maindir[0];
i = toupper(i) - 'A' + 1;
dspace = freek(i);
if (dspace < 1024.0) {
fprintf(stderr, "\n ■ Only %.1fK available on drive %c:... aborting!",
dspace, i + '@');
exit(EXIT_FAILURE);
} else {
fprintf(stderr, " disk space ");
if (dspace < 10000.0)
fprintf(stderr, ": %c:%.1fK", i + '@', dspace);
else
fprintf(stderr, ": %c:%.1fM", i + '@', dspace / 1024.0);
}
set_net_num(netnum);
ss = argv[1];
sy = atoi(&ss[2]);
destaddr[0] = 0;
if (sy != 32767)
good_addr(destaddr, sy);
if ((destaddr[0] == 0) && (sy != 32767)) {
fprintf(stderr, "\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
ok = 0;
} else {
ok = 1;
if (sy == 32767) {
if (ini_section & INI_NEWS) {
fprintf(stderr, "\n ■ Initiating newsgroup retrieval session...");
news = 1;
} else {
fprintf(stderr, "\n ■ [NEWS] tag missing from NET.INI!");
exit(EXIT_FAILURE);
}
}
}
}
if (ok) {
if (!MOREINFO)
freopen(NULL, "w", stdout);
if (CLEANUP)
process_mail();
set_net_num(netnum);
sprintf(s, "%sSPOOL", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
sprintf(s, "%sMQUEUE", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
sprintf(s, "%sOUTBOUND", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
sprintf(s, "%sINBOUND", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
sprintf(s, "%sSENT", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
if ((KEEPSENT) && (sy != 32767)) {
fprintf(stderr, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
KEEPSENT == 1 ? "" : "s");
i = purge_sent();
fprintf(stderr, " %d packet%s deleted.", i, i == 1 ? "" : "s");
}
sprintf(s, "%sCHECKNET", net_data);
if ((make_path(s)) < 0) {
fprintf(stderr, "\n ■ Unable to create \"%s\"", s);
exit(EXIT_FAILURE);
}
send = 1;
cd_to(maindir);
if ((sy != 32767) || (ONECALL)) {
fprintf(stderr, "\n ■ Preparing outbound mail for transmission...");
if (!uu_packets()) {
sprintf(s, "%sMQUEUE\\*.*", net_data);
if (findfirst(s, &ff, 0) == 0) {
fprintf(stderr, "\n ■ MQUEUE contains outbound mail and packets to deliver.");
} else {
fprintf(stderr, " no outbound mail or packets to send.");
send = 0;
}
} else {
backline();
fprintf(stderr, "\r ■ All packets prepared for transmission.");
}
}
sprintf(s, "%sNET%d.CFG", net_data, instance);
if (exist(s)) {
sprintf(s1, "%s\\NET.CFG", maindir);
unlink(s1);
if (!copyfile(s, s1))
fprintf(stderr, "\n ■ Unable to copy %s to %s", s, s1);
else
fprintf(stderr, "\n ■ Copied %s for use as NET.CFG", strlwr(s));
}
sprintf(s, "%s\\EXP.EXE", maindir);
if (!exist(s)) {
fprintf(stderr, "\n ■ Export module EXP.EXE not found!");
} else {
sprintf(s, "%sS32767.NET", net_data);
sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
if ((exist(s)) || (exist(s1))) {
sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
net_data, net_sysnum, POPNAME, DOMAIN, net_name);
if (do_spawn(s))
fprintf(stderr, "\n ■ Unknown error during export");
} else
fprintf(stderr, "\n ■ No inbound or outbound Internet mail or newsgroup posts to process.");
}
klos_ppp();
starttime = clock();
sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
cd_to(maindir);
create_wattcp_cfg();
sprintf(tempdir, "%sINBOUND\\", net_data);
if ((send) && ((sy != 32767) || (ONECALL))) {
sprintf(temp, "%sMQUEUE\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
if (f1 == 0)
fprintf(stderr, "\n");
while (f1 == 0) {
sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
sprintf(s, "%s\\POP -send %s %s %s", maindir, SMTPHOST, DOMAIN, s1);
backline();
fprintf(stderr, "\r ■ Sending %s ", ff.ff_name);
if (do_spawn(s) == EXIT_SUCCESS) {
unlink(s1);
sentbytes += ff.ff_fsize;
} else
fprintf(stderr, "\n ■ Unsuccessful! %s remains in MQUEUE.", ff.ff_name);
f1 = findnext(&ff);
}
backline();
fprintf(stderr, "\r ■ Outbound net packet transfers completed.");
send = 0;
}
if ((sy != 32767) || (ONECALL)) {
sprintf(s, "%s\\POP -receive %s %s %s %s %d", maindir, POPHOST, POPNAME, POPPASS,
tempdir, ALLMAIL);
fprintf(stderr, "\n ■ Checking %s for inbound net packets.", POPHOST);
sprintf(s1, "%s*.*", tempdir);
if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
sprintf(temp, "%s*.*", tempdir);
f1 = findfirst(temp, &ff, FA_ARCH);
i = 0;
send = 0;
while (f1 == 0) {
if (strncmp(ff.ff_name, "BAD", 3) != 0) {
recdbytes += ff.ff_fsize;
sprintf(s1, "%s%s", tempdir, ff.ff_name);
sprintf(temp, "%s\\UU -decode %s %s %s", maindir, ff.ff_name,
tempdir, net_data);
if (!do_spawn(temp)) {
send = 1;
unlink(s1);
}
}
f1 = findnext(&ff);
}
} else
fprintf(stderr, "\n ■ No network packets to process");
if ((send) && (CLEANUP)) {
fprintf(stderr, "\n ■ Processing received packets... please wait.");
process_mail();
set_net_num(netnum);
process_bbsdata();
}
}
if ((sy == 32767) || (ONECALL)) {
set_net_num(netnum);
sprintf(temp, "%sOUTBOUND\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
while (f1 == 0) {
snewsbytes += ff.ff_fsize;
f1 = findnext(&ff);
}
cd_to(maindir);
strcpy(s1, net_data);
if (LAST(s1) == '\\')
LAST(s1) = 0;
sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
ok = 1;
if (do_spawn(s) != EXIT_SUCCESS)
fprintf(stderr, "\n ■ Unsuccessful news retrieval session...");
set_net_num(netnum);
sprintf(temp, "%sP0*.*", net_data);
f1 = findfirst(temp, &ff, 0);
while (f1 == 0) {
rnewsbytes += ff.ff_fsize;
f1 = findnext(&ff);
}
}
} else {
fprintf(stderr, "\n");
set_net_num(netnum);
strcpy(s, "NETWORK0.EXE");
for (i = 1; i < argc; i++) {
strcat(s, " ");
strcat(s, argv[i]);
}
s[strlen(s)+1] = '\0';
do_it(s);
exit(EXIT_SUCCESS);
}
unload_klos();
starttime = clock() - starttime;
if (starttime)
sprintf(ttotal, "%2.1f", (starttime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
recdbytes = ((recdbytes + 1023) / 1024);
sentbytes = ((sentbytes + 1023) / 1024);
rnewsbytes = ((recdbytes + 1023) / 1024);
snewsbytes = ((sentbytes + 1023) / 1024);
fprintf(stderr, "\n ■ Updating network connection records...");
if (ONECALL) {
if (write_contact(sy, sentbytes, recdbytes, 1, 0))
fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
if (write_netlog(sy, sentbytes, recdbytes, ttotal))
fprintf(stderr, "\n ■ Unable to access NET.LOG!");
if (write_contact(32767, snewsbytes, rnewsbytes, 1, 1))
fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
fprintf(stderr, "\n ■ Unable to access NET.LOG!");
} else {
if (news) {
if (write_contact(32767, snewsbytes, rnewsbytes, 1, 1))
fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
fprintf(stderr, "\n ■ Unable to access NET.LOG!");
} else {
if (write_contact(sy, sentbytes, recdbytes, 1, 0))
fprintf(stderr, "\n ■ Unable to access CONTACT.NET!");
if (write_netlog(sy, sentbytes, recdbytes, ttotal))
fprintf(stderr, "\n ■ Unable to access NET.LOG!");
}
}
cd_to(maindir);
set_net_num(netnum);
fprintf(stderr, "\n ■ %s completed!\n\n", version);
return 0;
}