home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B51.ZIP / NETWORK.CPP < prev    next >
C/C++ Source or Header  |  1997-10-17  |  47KB  |  1,883 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <dos.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8. #include <ctype.h>
  9. #include <mem.h>
  10. #include <conio.h>
  11. #include <io.h>
  12. #include <share.h>
  13. #include <errno.h>
  14. #include <malloc.h>
  15. #include <dir.h>
  16. #include <time.h>
  17. #include <process.h>
  18. #include <direct.h>
  19. #include "vardec.h"
  20. #include "net.h"
  21. #include "version.h"
  22. #include "retcode.h"
  23.  
  24. #define NUL '\0'
  25. #define LAST(s) s[strlen(s)-1]
  26. #define MAX_PATH 79
  27.  
  28. #define SHARE_LEVEL 10
  29. #define WAIT_TIME 10
  30. #define TRIES 100
  31.  
  32. #define MT_DESQVIEW 0x01
  33. #define MT_WINDOWS  0x02
  34. #define MT_OS2      0x04
  35. #define MT_NB       0x40
  36.  
  37. #define VIDEO 0x10
  38.  
  39. #define INI_NETWORK   0x01
  40. #define INI_GENERAL   0x02
  41. #define INI_NEWS      0x04
  42.  
  43. char *version = "Freeware PPP Project Net Packet Engine " VERSION " (" __DATE__ ")";
  44. char *author = "Contact Frank Reid at edare@ix.netcom.com or 1@8213.WWIVnet for support";
  45.  
  46. extern unsigned _stklen = 6132U;
  47.  
  48. typedef struct {
  49.   unsigned short sysnum;
  50.   char address[60];
  51. } net_address_rec;
  52.  
  53. configrec syscfg;
  54. configoverrec syscfgovr;
  55. net_networks_rec netcfg;
  56. net_system_list_rec *netsys;
  57.  
  58. int multitasker = 0, ini_section = 0, num_addr;
  59. char wwiv_net_no[20], maindir[121];
  60. char net_name[16], net_data[121];
  61. unsigned short net_sysnum;
  62. int num_sys_list, net_num, net_num_max, netnum;
  63. static int lsl_loaded;
  64.  
  65. char SMTPHOST[50], POPHOST[50], NEWSHOST[50], POPNAME[40], POPPASS[20];
  66.  
  67. char IPADDR[18], NETMASK[18], FWDNAME[40], FWDDOM[50], TIMEHOST[40];
  68. char DNS[21], SDNS[21], DOMAIN[50], GATEWAY[18], temp_dir[MAXPATH];
  69. unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0, TIMEOUT = 60, SOCK_DELAY = 30, INACTIVE = 60;
  70. unsigned int ONECALL = 0, PURGE = 1;
  71. int instance;
  72.  
  73. char *xenviron[50];
  74.  
  75. void dv_pause(void)
  76. {
  77.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  78.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  79.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  80. }
  81.  
  82. void win_pause(void)
  83. {
  84.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  85. }
  86.  
  87. int get_dos_version(void)
  88. {
  89.   _AX = 0x3000;
  90.   geninterrupt(0x21);
  91.   if (_AX % 256 >= 10) {
  92.     multitasker |= MT_OS2;
  93.   }
  94.   return (_AX);
  95. }
  96.  
  97. int get_dv_version(void)
  98. {
  99.   int v;
  100.  
  101.   if (multitasker & MT_OS2)
  102.     return 0;
  103.   _AX = 0x2b01;
  104.   _CX = 0x4445;
  105.   _DX = 0x5351;
  106.   geninterrupt(0x21);
  107.   if (_AL == 0xff) {
  108.     return 0;
  109.   } else {
  110.     v = _BX;
  111.     multitasker |= MT_DESQVIEW;
  112.     return v;
  113.   }
  114. }
  115.  
  116. int get_win_version(void)
  117. {
  118.   int v = 0;
  119.  
  120.   __emit__(0x55, 0x06, 0x53);
  121.   _AX = 0x352f;
  122.   geninterrupt(0x21);
  123.   _AX = _ES;
  124.   if (_AX | _BX) {
  125.     _AX = 0x1600;
  126.     geninterrupt(0x2f);
  127.     v = _AX;
  128.     if (v % 256 <= 1)
  129.       v = 0;
  130.   }
  131.   __emit__(0x5b, 0x07, 0x5d);
  132.   if (v != 0)
  133.     multitasker |= MT_WINDOWS;
  134.   return (v);
  135. }
  136.  
  137. int get_nb_version(void)
  138. {
  139.   _AX = 0;
  140.   geninterrupt(0x2A);
  141.   return (_AH);
  142. }
  143.  
  144. void detect_multitask(void)
  145. {
  146.   get_dos_version();
  147.   get_win_version();
  148.   get_dv_version();
  149.   if (multitasker < 2)
  150.     if (get_nb_version())
  151.       multitasker = MT_NB;
  152. }
  153.  
  154. void giveup_timeslice(void)
  155. {
  156.   if (multitasker) {
  157.     switch (multitasker) {
  158.  case 1:
  159.  case 3:
  160.         dv_pause();
  161.         break;
  162.       case 2:
  163.       case 4:
  164.       case 5:
  165.       case 6:
  166.       case 7:
  167.         win_pause();
  168.         break;
  169.       default:
  170.         break;
  171.     }
  172.   }
  173. }
  174.  
  175. char *stripspace(char *str)
  176. {
  177.   char *obuf, *nbuf;
  178.  
  179.   if (str) {
  180.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  181.       if (!isspace(*obuf))
  182.         *nbuf++ = *obuf;
  183.     }
  184.     *nbuf = NULL;
  185.   }
  186.   return (str);
  187. }
  188.  
  189. int sh_write(int handle, void *buffer, unsigned long len)
  190. {
  191.   if (handle == -1) {
  192.     return (-1);
  193.   }
  194.   return (write(handle, buffer, (unsigned) len));
  195. }
  196.  
  197. int sh_open(char *path, int file_access, unsigned fmode)
  198. {
  199.   int handle, count, share;
  200.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  201.  
  202.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  203.     share = SH_DENYRW;
  204.   } else {
  205.     share = SH_DENYWR;
  206.   }
  207.   handle = open(path, file_access | share, fmode);
  208.   if (handle < 0) {
  209.     count = 1;
  210.     fnsplit(path, drive, dir, file, ext);
  211.     if (access(path, 0) != -1) {
  212.       delay(WAIT_TIME);
  213.       handle = open(path, file_access | share, fmode);
  214.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  215.         if (count % 2)
  216.           delay(WAIT_TIME);
  217.         else
  218.           giveup_timeslice();
  219.         count++;
  220.         handle = open(path, file_access | share, fmode);
  221.       }
  222.     }
  223.   }
  224.   return (handle);
  225. }
  226.  
  227. int sh_open1(char *path, int access)
  228. {
  229.   unsigned fmode;
  230.  
  231.   fmode = 0;
  232.   if ((access & O_RDWR) || (access & O_WRONLY))
  233.     fmode |= S_IWRITE;
  234.   if ((access & O_RDWR) || (access & O_RDONLY))
  235.     fmode |= S_IREAD;
  236.   return (sh_open(path, access, fmode));
  237. }
  238.  
  239. int sh_close(int f)
  240. {
  241.   if (f != -1)
  242.     close(f);
  243.   return (-1);
  244. }
  245.  
  246. int sh_read(int handle, void *buf, unsigned len)
  247. {
  248.   if (handle == -1) {
  249.     return (-1);
  250.   }
  251.   return (read(handle, buf, len));
  252. }
  253.  
  254. long sh_lseek(int handle, long offset, int fromwhere)
  255. {
  256.   if (handle == -1) {
  257.     return (-1L);
  258.   }
  259.   return (lseek(handle, offset, fromwhere));
  260. }
  261.  
  262. FILE *fsh_open(char *path, char *fmode)
  263. {
  264.   FILE *f;
  265.   int count, share, md, fd;
  266.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  267.  
  268.   share = SH_DENYWR;
  269.   md = 0;
  270.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  271.     share = SH_DENYRD;
  272.     md = O_RDWR | O_CREAT | O_TRUNC;
  273.   } else
  274.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  275.     share = SH_DENYRD;
  276.     md = O_RDWR | O_CREAT;
  277.   } else {
  278.     md = O_RDONLY;
  279.   }
  280.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  281.     md |= O_BINARY;
  282.   }
  283.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  284.     md &= ~O_RDONLY;
  285.     md |= O_RDWR;
  286.     share = SH_DENYRD;
  287.   }
  288.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  289.   if (fd < 0) {
  290.     count = 1;
  291.     fnsplit(path, drive, dir, file, ext);
  292.     if ((access(path, 0)) != -1) {
  293.       delay(WAIT_TIME);
  294.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  295.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  296.         delay(WAIT_TIME);
  297.         count++;
  298.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  299.       }
  300.     }
  301.   }
  302.   if (fd > 0) {
  303.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  304.       sh_lseek(fd, 0L, SEEK_END);
  305.     f = fdopen(fd, fmode);
  306.     if (!f) {
  307.       close(fd);
  308.     }
  309.   } else
  310.     f = NULL;
  311.   return (f);
  312. }
  313.  
  314. void output(char *fmt, ...)
  315. {
  316.   va_list v;
  317.   char s[255];
  318.  
  319.   va_start(v, fmt);
  320.   vsprintf(s, fmt, v);
  321.   va_end(v);
  322.   fputs(s, stderr);
  323. }
  324.  
  325.  
  326. void backline(void)
  327. {
  328.   int i;
  329.  
  330.   output(" ");
  331.   for (i = wherex(); i > 0; i--)
  332.     output("\b \b");
  333. }
  334.  
  335.  
  336. int do_spawn(char *cl)
  337. {
  338.   int i, i1, l;
  339.   char *s, *ss[50];
  340.  
  341.   s = strdup(cl);
  342.   ss[0] = s;
  343.   i = 1;
  344.   l = strlen(s);
  345.   for (i1 = 1; i1 < l; i1++)
  346.     if (s[i1] == 32) {
  347.       s[i1] = 0;
  348.       ss[i++] = &(s[i1 + 1]);
  349.     }
  350.   ss[i] = NULL;
  351.   if (MOREINFO)
  352.     output("\n");
  353.   i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
  354.   free(s);
  355.   return (i);
  356. }
  357.  
  358. void unload_klos(void)
  359. {
  360.   char s[101];
  361.  
  362.   sprintf(s, "%s\\IPSTUB U", maindir);
  363.   do_spawn(s);
  364.   sprintf(s, "%s\\PPP U", maindir);
  365.   do_spawn(s);
  366.   if (!lsl_loaded) {
  367.     sprintf(s, "%s\\LSL U", maindir);
  368.     do_spawn(s);
  369.   }
  370. }
  371.  
  372. void cd_to(char *s)
  373. {
  374.   char *s1;
  375.   int i, db;
  376.  
  377.   s1 = s;
  378.   i = strlen(s1) - 1;
  379.   db = (s1[i] == '\\');
  380.   if (i == 0)
  381.     db = 0;
  382.   if ((i == 2) && (s1[1] == ':'))
  383.     db = 0;
  384.   if (db)
  385.     s1[i] = 0;
  386.   chdir(s1);
  387.   if (s[1] == ':')
  388.     setdisk(s[0] - 'A');
  389. }
  390.  
  391. void get_dir(char *s, int be)
  392. {
  393.   strcpy(s, "X:\\");
  394.   s[0] = 'A' + getdisk();
  395.   getcurdir(0, s + 3);
  396.   if (be) {
  397.     if (s[strlen(s) - 1] != '\\')
  398.       strcat(s, "\\");
  399.   }
  400. }
  401.  
  402. unsigned char *trimstr1(unsigned char *s)
  403. {
  404.   int i;
  405.   static char *whitespace = " \r\n\t";
  406.  
  407.   i = (int) strlen(s);
  408.   while ((i > 0) && ((char *) _fstrchr(whitespace, s[i - 1]) != NULL))
  409.     --i;
  410.   while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
  411.     memmove(s, s + 1, --i);
  412.   }
  413.   s[i] = NUL;
  414.   return (s);
  415. }
  416.  
  417. char *make_abs_path(unsigned char *checkdir)
  418. {
  419.   char newdir[121];
  420.  
  421.   if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
  422.     cd_to(maindir);
  423.     cd_to(checkdir);
  424.     if (LAST(checkdir) == '\\')
  425.       get_dir(newdir, 1);
  426.     else
  427.       get_dir(newdir, 0);
  428.     cd_to(maindir);
  429.     strcpy(checkdir, newdir);
  430.   }
  431.   return checkdir;
  432. }
  433.  
  434. int exist(char *s)
  435. {
  436.   int i;
  437.   struct ffblk ff;
  438.  
  439.   i = findfirst(s, &ff, 0);
  440.   if (i)
  441.     return (0);
  442.   else
  443.     return (1);
  444. }
  445.  
  446. void set_net_num(int n)
  447. {
  448.   char s[121];
  449.   int f;
  450.  
  451.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  452.   f = sh_open1(s, O_RDONLY | O_BINARY);
  453.   if (f < 0)
  454.     return;
  455.   lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
  456.   sh_read(f, &netcfg, sizeof(net_networks_rec));
  457.   close(f);
  458.   net_num = n;
  459.   net_sysnum = netcfg.sysnum;
  460.   strcpy(net_name, netcfg.name);
  461.   strcpy(net_data, make_abs_path(netcfg.dir));
  462.   if (LAST(net_data) != '\\')
  463.     strcat(net_data, "\\");
  464.   sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
  465. }
  466.  
  467. int make_path(char *s)
  468. {
  469.   unsigned int i;
  470.   char drive, current_path[MAX_PATH], current_drive, *p, *flp;
  471.   union REGS r;
  472.  
  473.   p = flp = strdup(s);
  474.   _getdcwd(0, current_path, MAX_PATH);
  475.   current_drive = *current_path - '@';
  476.   if (LAST(s) == '\\')
  477.     LAST(s) = 0;
  478.   if (p[1] == ':') {
  479.     drive = toupper(p[0]) - 'A' + 1;
  480.     if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
  481.       r.x.ax = 0x4409;
  482.       r.h.bl = drive;
  483.       int86(0x21, &r, &r);
  484.       if (r.x.cflag)
  485.         return -3;
  486.     }
  487.     if (_chdrive(drive)) {
  488.       chdir(current_path);
  489.       _dos_setdrive(current_drive, &i);
  490.       return -2;
  491.     }
  492.     p += 2;
  493.   }
  494.   if (*p == '\\') {
  495.     chdir("\\");
  496.     p++;
  497.   }
  498.   for (; (p = strtok(p, "\\")) != 0; p = 0) {
  499.     if (chdir(p)) {
  500.       if (mkdir(p)) {
  501.         chdir(current_path);
  502.         _dos_setdrive(current_drive, &i);
  503.         return -1;
  504.       }
  505.       chdir(p);
  506.     }
  507.   }
  508.   chdir(current_path);
  509.   if (flp)
  510.     free(flp);
  511.   return 0;
  512. }
  513.  
  514. void process_mail(void)
  515. {
  516.   char s[121];
  517.  
  518.   output("\n ■ Running FLink/Linker... please wait.");
  519.   sprintf(s, "%s\\FLINK.EXE", maindir);
  520.   if (exist(s))
  521.     do_spawn(s);
  522.   sprintf(s, "%s\\LINKER.EXE", maindir);
  523.   if (exist(s))
  524.     do_spawn(s);
  525. }
  526.  
  527. int valid_system(unsigned int ts)
  528. {
  529.   int i;
  530.  
  531.   for (i = 0; i < num_sys_list; i++) {
  532.     if (netsys[i].sysnum == ts) {
  533.       if (netsys[i].numhops == 1)
  534.         return (1);
  535.       else
  536.         return (0);
  537.     }
  538.   }
  539.   return (0);
  540. }
  541.  
  542. int create_contact_ppp(void)
  543. {
  544.   char *ss, fn[101], s[81];
  545.   unsigned short node;
  546.   int curfile, i;
  547.   net_address_rec curaddr;
  548.   FILE *fp, *fc;
  549.  
  550.   sprintf(fn, "%sCONTACT.PPP", net_data);
  551.   if ((fc = fsh_open(fn, "wb+")) == NULL) {
  552.     output("\n ■ Unable to create %s!\n", fn);
  553.     return (1);
  554.   }
  555.   curfile = 1;
  556.   num_addr = 0;
  557.   do {
  558.     sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  559.     if ((fp = fsh_open(fn, "rt")) == NULL)
  560.       curfile = -1;
  561.     while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
  562.       if (s[0] != '@')
  563.         continue;
  564.       ss = strtok(s, " \t\r");
  565.       node = atoi(&ss[1]);
  566.       if (node) {
  567.         ss = strtok(NULL, " \t\r");
  568.         trimstr1(ss);
  569.         curaddr.sysnum = node;
  570.         strcpy(curaddr.address, ss);
  571.         if (ss[0]) {
  572.           fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  573.           ++num_addr;
  574.         }
  575.       }
  576.     }
  577.     if (fp != NULL)
  578.       fclose(fp);
  579.     ++curfile;
  580.   } while (curfile > 0);
  581.   fseek(fc, 0L, SEEK_SET);
  582.   sprintf(fn, "%sADDRESS.0", net_data);
  583.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  584.     if (fc != NULL)
  585.       fclose(fc);
  586.     return(0);
  587.   }
  588.   while (fgets(s, 80, fp) != NULL) {
  589.     if (s[0] != '@')
  590.       continue;
  591.     ss = strtok(s, " \t\r");
  592.     node = atoi(&ss[1]);
  593.     do {
  594.       ss = strtok(NULL, " \t\r");
  595.       switch (ss[0]) {
  596.         case '-':
  597.           for (i = 0; i < num_addr; i++) {
  598.             fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  599.             fread(&curaddr, sizeof(net_address_rec), 1, fc);
  600.             if (node == curaddr.sysnum) {
  601.               curaddr.sysnum = 0;
  602.               fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  603.               fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  604.             }
  605.           }
  606.           break;
  607.       }
  608.     } while (ss);
  609.   }
  610.   if (fp != NULL)
  611.     fclose(fp);
  612.   if (fc != NULL)
  613.     fclose(fc);
  614.   return (0);
  615. }
  616.  
  617. void good_addr(char *address, unsigned short sn)
  618. {
  619.   char fn[101];
  620.   int i;
  621.   net_address_rec curaddr;
  622.   FILE *fc;
  623.  
  624.   address[0] = 0;
  625.   sprintf(fn, "%sCONTACT.PPP", net_data);
  626.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  627.     output("\n ■ Unable to read %s!\n", fn);
  628.     return;
  629.   }
  630.   for (i=0; ((i < num_addr) && (!address[0])); i++) {
  631.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  632.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  633.     if (sn == curaddr.sysnum)
  634.       strcpy(address, curaddr.address);
  635.   }
  636.   if (fc != NULL)
  637.     fclose(fc);
  638. }
  639.  
  640. int copyfile(char *input, char *output)
  641. {
  642.   int f1, f2, i;
  643.   char *b;
  644.   struct ftime ft;
  645.  
  646.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  647.     if ((b = (char *) malloc(16400)) == NULL)
  648.       return 0;
  649.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  650.     if (!f1) {
  651.       free(b);
  652.       b = NULL;
  653.       return 0;
  654.     }
  655.     getftime(f1, &ft);
  656.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  657.     if (!f2) {
  658.       free(b);
  659.       b = NULL;
  660.       f1 = sh_close(f1);
  661.       return 0;
  662.     }
  663.     i = read(f1, (void *) b, 16384);
  664.     while (i > 0) {
  665.       sh_write(f2, (void *) b, i);
  666.       i = read(f1, (void *) b, 16384);
  667.     }
  668.     f1 = sh_close(f1);
  669.     setftime(f2, &ft);
  670.     f2 = sh_close(f2);
  671.     free(b);
  672.     b = NULL;
  673.   }
  674.   return 1;
  675. }
  676.  
  677. void do_exit(int exitlevel)
  678. {
  679.   delay(2000);
  680.   exit(2 - exitlevel);
  681. }
  682.  
  683. int uu(char *fn, char *pktname, char *dest)
  684. {
  685.   int ok;
  686.   char s[121], s1[121], s2[81];
  687.   FILE *fp;
  688.  
  689.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  690.   if ((fp = fsh_open(s, "wt")) == NULL) {
  691.     output("\n ■ Unable to open %s for write operations!", s);
  692.     do_exit(EXIT_FAILURE);
  693.   } else {
  694.     sprintf(s2, "from: %s@%s\n", POPNAME, DOMAIN);
  695.     fprintf(fp, s2);
  696.     sprintf(s2, "to: %s\n", dest);
  697.     fprintf(fp, s2);
  698.     sprintf(s2, "subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
  699.     fprintf(fp, s2);
  700.   }
  701.   if (fp != NULL)
  702.     fclose(fp);
  703.   sprintf(s1, "%s\\UU -encode %s %s", maindir, fn, s);
  704.   ok = do_spawn(s1);
  705.   return ok;
  706. }
  707.  
  708. int update_contact(unsigned short sy, unsigned long sb, unsigned long rb)
  709. {
  710.   char s[101];
  711.   int i, i1, f;
  712.   long cur_time, l;
  713.  
  714.   sprintf(s, "%sCONTACT.NET", net_data);
  715.   f = sh_open1(s, O_RDONLY | O_BINARY);
  716.   if (f >= 0) {
  717.     l = filelength(f);
  718.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  719.     if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
  720.                                         sizeof(net_contact_rec))) == NULL) {
  721.       output("\n ■ Unable to allocate %d bytes of memory to update CONTACT.NET",
  722.               (int) (netcfg.num_ncn + 2) * sizeof(net_contact_rec));
  723.       f = sh_close(f);
  724.       return 1;
  725.     }
  726.     sh_lseek(f, 0L, SEEK_SET);
  727.     sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  728.     f = sh_close(f);
  729.   }
  730.   for (i = 0; i < netcfg.num_ncn; i++)
  731.     if (netcfg.ncn[i].systemnumber == sy)
  732.       i1 = i;
  733.   time(&cur_time);
  734.   netcfg.ncn[i1].lasttry = cur_time;
  735.   ++netcfg.ncn[i1].numcontacts;
  736.   if (!netcfg.ncn[i1].firstcontact)
  737.     netcfg.ncn[i1].firstcontact = cur_time;
  738.   netcfg.ncn[i1].lastcontact = cur_time;
  739.   netcfg.ncn[i1].lastcontactsent = cur_time;
  740.   netcfg.ncn[i1].bytes_sent += sb;
  741.   if (rb)
  742.     netcfg.ncn[i1].bytes_received += rb;
  743.   netcfg.ncn[i1].bytes_waiting = 0L;
  744.   sprintf(s, "%sS%hd.net", net_data, sy);
  745.   if (!exist(s))
  746.     sprintf(s, "%sZ%hd.net", net_data, sy);
  747.   f = sh_open1(s, O_RDONLY | O_BINARY);
  748.   if (f > 0) {
  749.     netcfg.ncn[i1].bytes_waiting += filelength(f);
  750.     close(f);
  751.   }
  752.   sprintf(s, "%sCONTACT.NET", net_data);
  753.   f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  754.   if (f > 0) {
  755.     sh_lseek(f, 0L, SEEK_SET);
  756.     sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  757.     f = sh_close(f);
  758.   }
  759.   if (netcfg.ncn)
  760.     farfree(netcfg.ncn);
  761.   return 0;
  762. }
  763.  
  764.  
  765. int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
  766. {
  767.   int i, i1, rc;
  768.   char fn[101];
  769.   net_address_rec curaddr;
  770.   FILE *fc;
  771.  
  772.   rc = 0;
  773.   sprintf(fn, "%sCONTACT.PPP", net_data);
  774.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  775.     output("\n ■ Unable to read %s!\n", fn);
  776.     rc = 1;
  777.     return (rc);
  778.   }
  779.   for (i = 0; i < num_addr; i++) {
  780.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  781.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  782.     if (curaddr.sysnum != 0) {
  783.       if (curaddr.sysnum == sy)
  784.         i1 = update_contact(curaddr.sysnum, sb, rb);
  785.       else
  786.         i1 = update_contact(curaddr.sysnum, 0, 0);
  787.       if (i1)
  788.         rc = 1;
  789.     }
  790.   }
  791.   if (fc != NULL)
  792.     fclose(fc);
  793.   return (rc);
  794. }
  795.  
  796. int uu_packets(void)
  797. {
  798.   char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
  799.   int found, sz, f, f1, i;
  800.   unsigned long sbytes, basename;
  801.   net_address_rec curaddr;
  802.   FILE *fc;
  803.  
  804.   num_sys_list = 0;
  805.   basename = time(NULL);
  806.   sprintf(s, "%sBBSDATA.NET", net_data);
  807.   f = sh_open1(s, O_RDONLY | O_BINARY);
  808.   if (f > 0) {
  809.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  810.     if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
  811.                                     sizeof(net_system_list_rec))) == NULL) {
  812.       output("\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  813.               (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  814.       f = sh_close(f);
  815.       return 0;
  816.     }
  817.     sh_lseek(f, 0L, SEEK_SET);
  818.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  819.     f = sh_close(f);
  820.   } else
  821.     return 0;
  822.  
  823.   sprintf(s1, "%sCONTACT.PPP", net_data);
  824.   if ((fc = fsh_open(s1, "rb+")) == NULL) {
  825.     output("\n ■ Unable to read %s!\n", s1);
  826.     farfree(netsys);
  827.     return 0;
  828.   }
  829.   for (i=0; i < num_addr; i++) {
  830.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  831.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  832.     if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
  833.       sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
  834.       if (exist(s1))
  835.         sz = 0;
  836.       else {
  837.         sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
  838.         if (exist(s1))
  839.           sz = 1;
  840.         else
  841.           continue;
  842.       }
  843.       do {
  844.         sprintf(pktname, "%8.8lx", ++basename);
  845.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  846.       } while (exist(temp));
  847.       backline();
  848.       output("\r ■ Encoding %s%hd.NET as %s.UUE -",
  849.               sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
  850.       if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
  851.         output("\n ■ Error creating %sMQUEUE\\%s.UUE", net_data, pktname);
  852.         if (fc != NULL)
  853.           fclose(fc);
  854.         farfree(netsys);
  855.         do_exit(EXIT_FAILURE);
  856.       } else {
  857.         found = 1;
  858.         if (KEEPSENT) {
  859.           sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  860.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  861.           f1 = sh_open1(s3, O_RDONLY | O_BINARY);
  862.           if (f1 > 0) {
  863.             sbytes = filelength(f1);
  864.             f = sh_close(f1);
  865.           }
  866.           if (!copyfile(s3, s2))
  867.             output("\n ■ Error moving %s%hd.NET", sz ? "Z" : "S", curaddr.sysnum);
  868.         }
  869.         unlink(s1);
  870.         update_contact(curaddr.sysnum, sbytes, 0);
  871.       }
  872.     }
  873.   }
  874.   if (fc != NULL)
  875.     fclose(fc);
  876.   farfree(netsys);
  877.   return found;
  878. }
  879.  
  880. int purge_sent(void)
  881. {
  882.   char s[121];
  883.   int f1, howmany = 0;
  884.   long age;
  885.   struct ffblk ff;
  886.   struct stat fileinfo;
  887.  
  888.   sprintf(s, "%sSENT\\*.*", net_data);
  889.   f1 = findfirst(s, &ff, 0);
  890.   while (f1 == 0) {
  891.     sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
  892.     if (stat(s, &fileinfo) == 0) {
  893.       age = (time(NULL) - fileinfo.st_atime);
  894.       if (age > (86400L * KEEPSENT)) {
  895.         ++howmany;
  896.         unlink(s);
  897.       }
  898.     }
  899.     f1 = findnext(&ff);
  900.   }
  901.   return howmany;
  902. }
  903.  
  904. int parse_net_ini(void)
  905. {
  906.   char cursect;
  907.   char line[121], *ss;
  908.   FILE *fp;
  909.  
  910.   if ((fp = fsh_open("NET.INI", "rt")) == NULL)
  911.     return (0);
  912.   while (fgets(line, 80, fp)) {
  913.     stripspace(line);
  914.     ss = NULL;
  915.     ss = strtok(line, "=");
  916.     if (ss)
  917.       ss = strtok(NULL, "\n");
  918.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  919.       continue;
  920.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  921.         (strnicmp(line, "[PPPNET]", 8) == 0)) {
  922.       cursect = INI_NETWORK;
  923.       ini_section |= INI_NETWORK;
  924.       continue;
  925.     }
  926.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  927.       cursect = INI_GENERAL;
  928.       ini_section |= INI_GENERAL;
  929.       continue;
  930.     }
  931.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  932.       cursect = INI_NEWS;
  933.       ini_section |= INI_NEWS;
  934.       continue;
  935.     }
  936.     if (cursect & INI_NETWORK) {
  937.       if (strnicmp(line, "TIMEHOST", 8) == 0) {
  938.         if (ss)
  939.           strcpy(TIMEHOST, ss);
  940.         continue;
  941.       }
  942.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  943.         if (ss)
  944.           strcpy(SMTPHOST, ss);
  945.         continue;
  946.       }
  947.       if (strnicmp(line, "POPHOST", 7) == 0) {
  948.         if (ss)
  949.           strcpy(POPHOST, ss);
  950.         continue;
  951.       }
  952.       if (strnicmp(line, "POPNAME", 7) == 0) {
  953.         if (ss)
  954.           strcpy(POPNAME, ss);
  955.         continue;
  956.       }
  957.       if (strnicmp(line, "POPPASS", 7) == 0) {
  958.         if (ss)
  959.           strcpy(POPPASS, ss);
  960.         continue;
  961.       }
  962.     }
  963.     if (cursect & INI_GENERAL) {
  964.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  965.         if (atoi(ss))
  966.           TIMEOUT = atoi(ss);
  967.         continue;
  968.       }
  969.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  970.         if (atoi(ss))
  971.           SOCK_DELAY = atoi(ss);
  972.         continue;
  973.       }
  974.       if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
  975.         if (atoi(ss))
  976.           INACTIVE = atoi(ss);
  977.         continue;
  978.       }
  979.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  980.         if (atoi(ss))
  981.           KEEPSENT = atoi(ss);
  982.         continue;
  983.       }
  984.       if (strnicmp(line, "PURGE", 5) == 0) {
  985.         if (toupper(ss[0]) == 'N')
  986.           PURGE = 0;
  987.         continue;
  988.       }
  989.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  990.         if (toupper(ss[0]) == 'N')
  991.           ALLMAIL = 0;
  992.         continue;
  993.       }
  994.       if (strnicmp(line, "ONECALL", 7) == 0) {
  995.         if (toupper(ss[0]) == 'Y')
  996.           ONECALL = 1;
  997.         continue;
  998.       }
  999.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  1000.         if (toupper(ss[0]) == 'Y')
  1001.           MOREINFO = 1;
  1002.         continue;
  1003.       }
  1004.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  1005.         if (toupper(ss[0]) == 'Y')
  1006.           CLEANUP = 1;
  1007.         continue;
  1008.       }
  1009.       if (strnicmp(line, "IPADDR", 6) == 0) {
  1010.         if ((ss) && (ss[0] != '0'))
  1011.           strcpy(IPADDR, ss);
  1012.         continue;
  1013.       }
  1014.       if (strnicmp(line, "NETMASK", 7) == 0) {
  1015.         if (ss)
  1016.           strcpy(NETMASK, ss);
  1017.         continue;
  1018.       }
  1019.       if (strnicmp(line, "DNS", 3) == 0) {
  1020.         if (ss)
  1021.           strcpy(DNS, ss);
  1022.         continue;
  1023.       }
  1024.       if (strnicmp(line, "SDNS", 3) == 0) {
  1025.         if (ss)
  1026.           strcpy(SDNS, ss);
  1027.         continue;
  1028.       }
  1029.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  1030.         if (ss)
  1031.           strcpy(DOMAIN, ss);
  1032.         continue;
  1033.       }
  1034.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  1035.         if (ss)
  1036.           strcpy(FWDNAME, ss);
  1037.         continue;
  1038.       }
  1039.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  1040.         if (ss)
  1041.           strcpy(FWDDOM, ss);
  1042.         continue;
  1043.       }
  1044.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  1045.         if ((ss) && (ss[0] != '0'))
  1046.           strcpy(GATEWAY, ss);
  1047.         continue;
  1048.       }
  1049.     }
  1050.     if (cursect & INI_NEWS) {
  1051.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  1052.         if (ss)
  1053.           strcpy(NEWSHOST, ss);
  1054.         continue;
  1055.       }
  1056.     }
  1057.   }
  1058.   if (!FWDNAME[0])
  1059.     strcpy(FWDNAME, POPNAME);
  1060.   if (!FWDDOM[0])
  1061.     strcpy(FWDDOM, DOMAIN);
  1062.   if (fp != NULL)
  1063.     fclose(fp);
  1064.   return (1);
  1065. }
  1066.  
  1067. #define MAX_LEN 12288
  1068.  
  1069. int open_netlog(char *fn)
  1070. {
  1071.   int f, count = 0;
  1072.  
  1073.   do {
  1074.     f = open(fn, O_RDWR | O_BINARY | SH_DENYRW | O_CREAT, S_IREAD | S_IWRITE);
  1075.   } while ((f < 0) && (errno == EACCES) && (count++ < 500));
  1076.  
  1077.   return(f);
  1078. }
  1079.  
  1080.  
  1081. int write_netlog(int sn, long sent, long recd, char *tmused)
  1082. {
  1083.   int f;
  1084.   char *ss, s[101], s1[81], s2[81], fn[121];
  1085.   long l;
  1086.   struct tm *time_now;
  1087.   time_t some;
  1088.  
  1089.   ss = (char *) malloc(MAX_LEN+1024L);
  1090.   if (ss == NULL) {
  1091.     output("\n ■ Insufficient memory to update NET.LOG!");
  1092.     return 1;
  1093.   }
  1094.  
  1095.   time(&some);
  1096.   time_now = localtime(&some);
  1097.   strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
  1098.   if ((sent) || (recd)) {
  1099.     if ((recd) && (!sent))
  1100.       sprintf(s2, "       , R:%4ldk,", recd);
  1101.     else {
  1102.       if ((recd) && (sent))
  1103.         sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
  1104.       else
  1105.         sprintf(s2, "S:%4ldk,         ", sent);
  1106.     }
  1107.   } else
  1108.     strcpy(s2, "                 ");
  1109.   sprintf(s, "%s To %5d, %s          %4s min  %s\r\n", s1, sn, s2,
  1110.             tmused, net_name);
  1111.  
  1112.   strcpy(ss, s);
  1113.  
  1114.   sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
  1115.   f = open_netlog(fn);
  1116.   sh_lseek(f, 0L, SEEK_SET);
  1117.   l = (long) (sh_read(f, (void *)(&(ss[strlen(s)])), MAX_LEN) + strlen(s));
  1118.   while ((l > 0) && (ss[l] != '\n'))
  1119.     --l;
  1120.   sh_lseek(f, 0L, SEEK_SET);
  1121.   write(f, (void *) ss, l + 1);
  1122.   chsize(f, l + 1);
  1123.   sh_close(f);
  1124.   if (ss) {
  1125.     free(ss);
  1126.     ss = NULL;
  1127.   }
  1128.   return 0;
  1129. }
  1130.  
  1131. void read_networks(void)
  1132. {
  1133.   int f;
  1134.   char s[121];
  1135.  
  1136.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1137.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1138.   net_num_max = 0;
  1139.   if (f > 0) {
  1140.     net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
  1141.     f = sh_close(f);
  1142.   }
  1143. }
  1144.  
  1145. void init(void)
  1146. {
  1147.   char s[81], s1[81], *ss;
  1148.   int i, i1, dv, f;
  1149.   struct tm *time_now;
  1150.   time_t some;
  1151.  
  1152.   output("\n%s\n%s\n\n", version, author);
  1153.   get_dir(maindir, 0);
  1154.   ss = getenv("WWIV_INSTANCE");
  1155.   if (ss) {
  1156.     instance = atoi(ss);
  1157.     if ((instance <= 0) || (instance > 999)) {
  1158.       output("\n ■ WWIV_INSTANCE can only be 1..999!");
  1159.       instance = 1;
  1160.     }
  1161.   } else {
  1162.     instance = 1;
  1163.   }
  1164.  
  1165.   detect_multitask();
  1166.  
  1167.   switch (multitasker) {
  1168.     case 1:
  1169.       dv = get_dv_version();
  1170.       sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
  1171.       break;
  1172.     case 2:
  1173.       dv = get_win_version();
  1174.       if (dv == 4)
  1175.         strcpy(s1, "Windows 95");
  1176.       else
  1177.         sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
  1178.       break;
  1179.     case 3:
  1180.       dv = get_dv_version();
  1181.       sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
  1182.       break;
  1183.     case 4:
  1184.     case 5:
  1185.     case 6:
  1186.     case 7:
  1187.       if ((_osmajor / 10 == 2) && (_osminor >= 30))
  1188.         strcpy(s1, "OS/2 Warp");
  1189.       else
  1190.         sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
  1191.       break;
  1192.     case 8:
  1193.       sprintf(s1, "NETBIOS network");
  1194.       multitasker = 1;
  1195.       break;
  1196.     default:
  1197.       strcpy(s1, "DOS");
  1198.       break;
  1199.   }
  1200.   strcpy(s, "CONFIG.DAT");
  1201.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1202.   if (f < 0) {
  1203.     output("\n ■ %s NOT FOUND.", s);
  1204.     return;
  1205.   }
  1206.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1207.   f = sh_close(f);
  1208.   output(" ■ Running under %s on instance %d ", s1, instance);
  1209.   time(&some);
  1210.   time_now = localtime(&some);
  1211.   strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1212.   printf(s);
  1213.   strcpy(s, "CONFIG.OVR");
  1214.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1215.   if (f < 0) {
  1216.     output("\n ■ %s NOT FOUND.", s);
  1217.     return;
  1218.   }
  1219.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1220.   read(f, &syscfgovr, sizeof(configoverrec));
  1221.   f = sh_close(f);
  1222.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1223.   if (!exist(s)) {
  1224.     output("\n ■ %s NOT FOUND.", s);
  1225.     return;
  1226.   }
  1227.   read_networks();
  1228.   i = i1 = 0;
  1229.   while (environ[i] != NULL) {
  1230.     xenviron[i1++] = environ[i];
  1231.     ++i;
  1232.   }
  1233.   xenviron[i1] = NULL;
  1234. }
  1235.  
  1236. long getfctime(char *s)
  1237. {
  1238.   struct stat statbuf;
  1239.  
  1240.   if (stat(s, &statbuf) < 0)
  1241.     return (0L);
  1242.   else
  1243.     return (statbuf.st_atime);
  1244. }
  1245.  
  1246. int process_bbsdata(void)
  1247. {
  1248.   char s[101];
  1249.   unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
  1250.   int tf, n, net3;
  1251.  
  1252.   net3 = 0;
  1253.   sprintf(s, "%sBBSLIST.NET", net_data);
  1254.   bbslist_ctime = getfctime(s);
  1255.   sprintf(s, "%sCONNECT.NET", net_data);
  1256.   connect_ctime = getfctime(s);
  1257.   sprintf(s, "%sCALLOUT.NET", net_data);
  1258.   callout_ctime = getfctime(s);
  1259.   sprintf(s, "%sBBSDATA.NET", net_data);
  1260.   bbsdata_ctime = getfctime(s);
  1261.   sprintf(s, "%sBBSLIST.UPD", net_data);
  1262.   bbslist_ctime = getfctime(s);
  1263.   sprintf(s, "%sCONNECT.UPD", net_data);
  1264.   connect_ctime = getfctime(s);
  1265.  
  1266.   n = 0;
  1267.   tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
  1268.   if (tf)
  1269.     n = 1;
  1270.   tf = (tf || (callout_ctime > bbsdata_ctime));
  1271.   if (tf) {
  1272.     sprintf(s, "NETWORK3 .%d", netnum);
  1273.     if (n) {
  1274.       sprintf(s, "NETWORK3 .%d Y", netnum);
  1275.       net3 = 1;
  1276.     }
  1277.     do_spawn(s);
  1278.   }
  1279.   return (net3);
  1280. }
  1281.  
  1282. void do_it(char *cl)
  1283. {
  1284.   int i, i1, l;
  1285.   char *s, *ss[30];
  1286.  
  1287.   s = strdup(cl);
  1288.   ss[0] = s;
  1289.   i = 1;
  1290.   l = strlen(s);
  1291.   for (i1 = 1; i1 < l; i1++)
  1292.     if (s[i1] == 32) {
  1293.       s[i1] = 0;
  1294.       ss[i++] = &(s[i1 + 1]);
  1295.     }
  1296.   ss[i] = NULL;
  1297.   execvpe(ss[0], ss, xenviron);
  1298. }
  1299.  
  1300. int create_wattcp_cfg(void)
  1301. {
  1302.   char s[MAXPATH], s1[41];
  1303.   FILE *fp;
  1304.  
  1305.   sprintf(s, "%s\\WATTCP.CFG", maindir);
  1306.   if ((fp = fsh_open(s, "wt")) == NULL) {
  1307.     output("\n ■ Can't open %s for output!", s);
  1308.     return 1;
  1309.   }
  1310.   fseek(fp, 0L, SEEK_SET);
  1311.   sprintf(s, "my_ip=%s\n", IPADDR);
  1312.   fprintf(fp, s);
  1313.   fprintf(fp, "netmask=%s\n", NETMASK);
  1314.   fprintf(fp, "nameserver=%s\n", DNS);
  1315.   if (*SDNS)
  1316.     fprintf(fp, "nameserver=%s\n", SDNS);
  1317.   if (GATEWAY[0] == 0) {
  1318.     strcpy(s1, IPADDR);
  1319.     while (LAST(s1) != '.')
  1320.       LAST(s1) = 0;
  1321.     strcat(s1, "1");
  1322.     strcpy(GATEWAY, s1);
  1323.   }
  1324.   sprintf(s, "gateway=%s\n", GATEWAY);
  1325.   fprintf(fp, s);
  1326.   fprintf(fp, "domains=\"%s\"\n", DOMAIN);
  1327.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1328.   fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
  1329.   fprintf(fp, "inactive=%d\n", INACTIVE);
  1330.   if (fp != NULL)
  1331.     fclose(fp);
  1332.   return 0;
  1333. }
  1334.  
  1335. int check_for_lsl(void)
  1336. {
  1337.   union REGS r;
  1338.   struct SREGS s;
  1339.   char *intstr;
  1340.  
  1341.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1342.     r.h.al = 0;
  1343.     int86x(0x2f, &r, &r, &s);
  1344.     if (r.h.al == 0xff) {
  1345.       intstr = (char *) MK_FP(s.es, r.x.si);
  1346.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1347.         return 1;
  1348.     }
  1349.   }
  1350.   return 0;
  1351. }
  1352.  
  1353. void klos_ppp(void)
  1354. {
  1355.   char s[121], fn[MAXPATH], *ss;
  1356.   int i;
  1357.   FILE *fp;
  1358.  
  1359.   lsl_loaded = check_for_lsl();
  1360.   if (!lsl_loaded) {
  1361.     sprintf(s, "%s\\LSL.COM", maindir);
  1362.     if (exist(s)) {
  1363.       if (MOREINFO)
  1364.         output("\n ■ Loading Link Support Layer and ");
  1365.       do_spawn(s);
  1366.     } else {
  1367.       output("\n ■ LSL.COM not in BBS main directory!");
  1368.       do_exit(EXIT_FAILURE);
  1369.     }
  1370.   } else {
  1371.     if (MOREINFO)
  1372.       output("\n ■ LSL already in memory - loading ");
  1373.   }
  1374.   sprintf(s, "%s\\PPP.EXE", maindir);
  1375.   if (exist(s)) {
  1376.     if (MOREINFO)
  1377.       output("PPP packet driver.");
  1378.     do_spawn(s);
  1379.   } else {
  1380.     output("\n ■ %s\\PPP.EXE not found!", maindir);
  1381.     do_exit(EXIT_FAILURE);
  1382.   }
  1383.   while (kbhit())
  1384.     getch();
  1385.   sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1386.   if (exist(s)) {
  1387.     output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
  1388.     delay(2000);
  1389.     sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1390.     i = do_spawn(s);
  1391.     switch (i) {
  1392.       case 0:
  1393.         output(" connected!");
  1394.         break;
  1395.       case 1:
  1396.         output("\n ■ Unable to establish connection... aborting");
  1397.         sprintf(s, "%s\\PPP U", maindir);
  1398.         do_spawn(s);
  1399.         if (!lsl_loaded) {
  1400.           sprintf(s, "%s\\LSL U", maindir);
  1401.           do_spawn(s);
  1402.         }
  1403.         do_exit(EXIT_FAILURE);
  1404.       case 2:
  1405.         output("\n ■ Unable to find PPP layer... aborting");
  1406.         if (!lsl_loaded) {
  1407.           sprintf(s, "%s\\LSL U", maindir);
  1408.           do_spawn(s);
  1409.         }
  1410.         do_exit(EXIT_FAILURE);
  1411.       default:
  1412.         output("\n ■ Unknown PPPState Error #%d... aborting", i);
  1413.         sprintf(s, "%s\\PPP U", maindir);
  1414.         do_spawn(s);
  1415.         if (!lsl_loaded) {
  1416.           sprintf(s, "%s\\LSL U", maindir);
  1417.           do_spawn(s);
  1418.         }
  1419.         do_exit(EXIT_FAILURE);
  1420.     }
  1421.   } else {
  1422.     output("\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1423.     do_exit(EXIT_FAILURE);
  1424.   }
  1425.   if (!IPADDR[0]) {
  1426.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1427.     if (exist(s)) {
  1428.       do_spawn(s);
  1429.     } else {
  1430.       output("\n ■ %s\\PPPWAT.EXE not found!", maindir);
  1431.       unload_klos();
  1432.       do_exit(EXIT_FAILURE);
  1433.     }
  1434.     sprintf(fn, "%s\\WATTCP.CFG", maindir);
  1435.     if ((fp = fsh_open(fn, "rt")) == NULL) {
  1436.       output("\n ■ Unable to read %s\\WATTCP.CFG... aborting!", maindir);
  1437.       unload_klos();
  1438.       do_exit(EXIT_FAILURE);
  1439.     } else {
  1440.       while (fgets(s, 100, fp) != NULL) {
  1441.         if (strnicmp(s, "my_ip", 5) == 0) {
  1442.           ss = strtok(s, "=");
  1443.           ss = strtok(NULL, "\r");
  1444.           trimstr1(ss);
  1445.           strcpy(IPADDR, ss);
  1446.           break;
  1447.         }
  1448.       }
  1449.     }
  1450.     if (fp != NULL)
  1451.       fclose(fp);
  1452.   }
  1453.   if (IPADDR) {
  1454.     output("\n ■ Session IP address is %s... ", IPADDR);
  1455.     if (create_wattcp_cfg()) {
  1456.       unload_klos();
  1457.       do_exit(EXIT_FAILURE);
  1458.     }
  1459.   } else {
  1460.     output("\n ■ Could not find IP Address... aborting!");
  1461.     unload_klos();
  1462.     do_exit(EXIT_FAILURE);
  1463.   }
  1464.   sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1465.   if (exist(s)) {
  1466.     do_spawn(s);
  1467.   } else {
  1468.     output("\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1469.     do_exit(EXIT_FAILURE);
  1470.   }
  1471.   output("establishing socket     ");
  1472.   for (i = 5; i >= 0; i--) {
  1473.     output("\b\b\b\b%d...", i);
  1474.     delay(1000);
  1475.   }
  1476.   output("\b\b\b\b\b... ready!");
  1477. }
  1478.  
  1479. double freek(int dr)
  1480. {
  1481.   float d;
  1482.   struct dfree df;
  1483.  
  1484.   getdfree(dr, &df);
  1485.   d = (float) df.df_avail;
  1486.   d *= ((float) df.df_bsec);
  1487.   d *= ((float) df.df_sclus);
  1488.   d /= 1024.0;
  1489.   if (df.df_sclus == 0xffff)
  1490.     d = -1.0;
  1491.   return (d);
  1492. }
  1493.  
  1494. int main(int argc, char *argv[])
  1495. {
  1496.   int i, ok, news, totf, send, f1;
  1497.   unsigned short sy;
  1498.   float dspace;
  1499.   char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
  1500.   char ttotal[21];
  1501.   clock_t starttime, mailtime, newstime;
  1502.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1503.   FILE *fp;
  1504.   struct ffblk ff;
  1505.  
  1506.   init();
  1507.   news = 0;
  1508.   num_addr = 0;
  1509.   ss = argv[argc - 1];
  1510.   ok = 0;
  1511.   if (_fstrstr((char *) ss, ".") != NULL) {
  1512.     if (atoi(&ss[1]) < net_num_max) {
  1513.       netnum = atoi(&ss[1]);
  1514.       ok = 1;
  1515.     }
  1516.   } else {
  1517.     ss = (getenv("WWIV_NET"));
  1518.     netnum = atoi(ss);
  1519.     if (netnum < net_num_max)
  1520.       ok = 1;
  1521.   }
  1522.   if (!ok) {
  1523.     strcpy(s, "WWIV_NET.DAT");
  1524.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1525.       fgets(s, 3, fp);
  1526.       netnum = atoi(s);
  1527.       if (fp != NULL)
  1528.         fclose(fp);
  1529.       if (netnum < net_num_max)
  1530.         ok = 1;
  1531.     }
  1532.   }
  1533.   ss = argv[1];
  1534.   if (strncmpi(ss, "/N", 2))
  1535.     ok = 0;
  1536.   set_net_num(netnum);
  1537.   sprintf(s, "%sADDRESS.1", net_data);
  1538.   if (!exist(s))
  1539.     ok = 0;
  1540.   if (ok) {
  1541.     *SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = 0;
  1542.     *IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
  1543.     if (parse_net_ini()) {
  1544.       set_net_num(netnum);
  1545.       if (ini_section & INI_NETWORK) {
  1546.         if (!(ini_section & INI_GENERAL)) {
  1547.           output("\n ■ [GENERAL] tag missing from NET.INI!");
  1548.           ok = 0;
  1549.         }
  1550.       } else {
  1551.         ok = 0;
  1552.         output("\n ■ [FILENET] tag missing from NET.INI!");
  1553.       }
  1554.     } else {
  1555.       output("\n ■ Could not open file NET.INI!");
  1556.       ok = 0;
  1557.     }
  1558.   }
  1559.   if (ok)
  1560.     if (create_contact_ppp())
  1561.       ok = 0;
  1562.   if (ok) {
  1563.     output("\n ■ Memory available : %ld bytes -", coreleft());
  1564.     if (net_data[1] == ':')
  1565.       i = net_data[0];
  1566.     else
  1567.       i = maindir[0];
  1568.     i = toupper(i) - 'A' + 1;
  1569.     dspace = freek(i);
  1570.     if (dspace < 1024.0) {
  1571.       output("\n ■ Only %.1fK available on drive %c:... aborting!",
  1572.               dspace, i + '@');
  1573.       do_exit(EXIT_FAILURE);
  1574.     } else {
  1575.       output(" Disk space ");
  1576.       if (dspace < 10000.0)
  1577.         output(": %c:%.1fK", i + '@', dspace);
  1578.       else
  1579.         output(": %c:%.1fM", i + '@', dspace / 1024.0);
  1580.     }
  1581.  
  1582.     set_net_num(netnum);
  1583.     ss = argv[1];
  1584.     sy = atoi(&ss[2]);
  1585.     destaddr[0] = 0;
  1586.     if (sy != 32767)
  1587.       good_addr(destaddr, sy);
  1588.  
  1589.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1590.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1591.       ok = 0;
  1592.     } else {
  1593.       ok = 1;
  1594.       if (sy == 32767) {
  1595.         if (ini_section & INI_NEWS) {
  1596.           output("\n ■ Initiating newsgroup retrieval session...");
  1597.           news = 1;
  1598.         } else {
  1599.           output("\n ■ [NEWS] tag missing from NET.INI!");
  1600.           do_exit(EXIT_FAILURE);
  1601.         }
  1602.       }
  1603.     }
  1604.   }
  1605.   if (ok) {
  1606.     if (!MOREINFO)
  1607.       freopen(NULL, "w", stdout);
  1608.     if (CLEANUP)
  1609.       process_mail();
  1610.     set_net_num(netnum);
  1611.     sprintf(s, "%sSPOOL", net_data);
  1612.     if ((make_path(s)) < 0) {
  1613.       output("\n ■ Unable to create \"%s\"", s);
  1614.       do_exit(EXIT_FAILURE);
  1615.     }
  1616.     sprintf(s, "%sMQUEUE", net_data);
  1617.     if ((make_path(s)) < 0) {
  1618.       output("\n ■ Unable to create \"%s\"", s);
  1619.       do_exit(EXIT_FAILURE);
  1620.     }
  1621.     sprintf(s, "%sOUTBOUND", net_data);
  1622.     if ((make_path(s)) < 0) {
  1623.       output("\n ■ Unable to create \"%s\"", s);
  1624.       do_exit(EXIT_FAILURE);
  1625.     }
  1626.     sprintf(s, "%sINBOUND", net_data);
  1627.     if ((make_path(s)) < 0) {
  1628.       output("\n ■ Unable to create \"%s\"", s);
  1629.       do_exit(EXIT_FAILURE);
  1630.     }
  1631.     sprintf(s, "%sSENT", net_data);
  1632.     if ((make_path(s)) < 0) {
  1633.       output("\n ■ Unable to create \"%s\"", s);
  1634.       do_exit(EXIT_FAILURE);
  1635.     }
  1636.     if (PURGE) {
  1637.       if ((KEEPSENT) && (sy != 32767)) {
  1638.         output("\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1639.                 KEEPSENT == 1 ? "" : "s");
  1640.         i = purge_sent();
  1641.         output(" %d packet%s deleted.", i, i == 1 ? "" : "s");
  1642.       }
  1643.     }
  1644.     sprintf(s, "%sCHECKNET", net_data);
  1645.     if ((make_path(s)) < 0) {
  1646.       output("\n ■ Unable to create \"%s\"", s);
  1647.       do_exit(EXIT_FAILURE);
  1648.     }
  1649.     send = 1;
  1650.  
  1651.     cd_to(maindir);
  1652.     sprintf(s, "%s\\EXP.EXE", maindir);
  1653.     if (!exist(s)) {
  1654.       output("\n ■ Export module EXP.EXE not found!");
  1655.     } else {
  1656.       sprintf(s, "%sS32767.NET", net_data);
  1657.       sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
  1658.       if ((exist(s)) || (exist(s1))) {
  1659.         sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1660.                 net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1661.         if (do_spawn(s))
  1662.           output("\n ■ Unknown error during export.");
  1663.       } else {
  1664.         if (MOREINFO)
  1665.           output("\n ■ No Internet mail or newsgroup articles to export.");
  1666.       }
  1667.     }
  1668.  
  1669.     cd_to(maindir);
  1670.     if ((sy != 32767) || (ONECALL)) {
  1671.       output("\n ■ Preparing outbound mail for transmission...");
  1672.       if (!uu_packets()) {
  1673.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1674.         if (findfirst(s, &ff, 0) == 0) {
  1675.           output(" outbound packets in MQUEUE.");
  1676.         } else {
  1677.           output(" no mail or packets to send.");
  1678.           send = 0;
  1679.         }
  1680.       } else {
  1681.         backline();
  1682.         output(" ■ All packets prepared for transmission.");
  1683.       }
  1684.     }
  1685.     sprintf(s, "%sNET%d.CFG", net_data, instance);
  1686.     if (exist(s)) {
  1687.       sprintf(s1, "%s\\NET.CFG", maindir);
  1688.       unlink(s1);
  1689.       if (!copyfile(s, s1))
  1690.         output("\n ■ Unable to copy %s to %s", s, s1);
  1691.     }
  1692.  
  1693.     starttime = clock();
  1694.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1695.  
  1696.     cd_to(maindir);
  1697.  
  1698.     klos_ppp();
  1699.  
  1700.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1701.  
  1702.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1703.       totf = 0;
  1704.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1705.       f1 = findfirst(temp, &ff, FA_ARCH);
  1706.       if (f1 == 0)
  1707.         output("\n");
  1708.       while (f1 == 0) {
  1709.         sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
  1710.         sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
  1711.         backline();
  1712.         output(" ■ SND : %s ", ff.ff_name);
  1713.         if (do_spawn(s) == EXIT_SUCCESS) {
  1714.           unlink(s1);
  1715.           sentbytes += ff.ff_fsize;
  1716.           ++totf;
  1717.         } else
  1718.           output("\n ■ Unsuccessful - %s remains in MQUEUE!", ff.ff_name);
  1719.         f1 = findnext(&ff);
  1720.       }
  1721.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1722.       f1 = findfirst(temp, &ff, FA_ARCH);
  1723.       if (f1 == 0) {
  1724.         backline();
  1725.         output(" ■ Second pass for SMTP transfers...\n");
  1726.       }
  1727.       while (f1 == 0) {
  1728.         sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
  1729.         sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
  1730.         backline();
  1731.         output(" ■ SND : %s ", ff.ff_name);
  1732.         if (do_spawn(s) == EXIT_SUCCESS) {
  1733.           unlink(s1);
  1734.           sentbytes += ff.ff_fsize;
  1735.           ++totf;
  1736.         } else
  1737.           output("\n ■ Unsuccessful!  %s remains in MQUEUE.", ff.ff_name);
  1738.         f1 = findnext(&ff);
  1739.       }
  1740.       backline();
  1741.       output(" ■ Outbound mail transfer completed : %d file%s (%ldK).",
  1742.               totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1743.       send = 0;
  1744.     }
  1745.     if ((sy != 32767) || (ONECALL)) {
  1746.       sprintf(s, "%s\\POP -receive %s %s %s %s %d %s %d", maindir, POPHOST, POPNAME, POPPASS,
  1747.               temp_dir, ALLMAIL, DOMAIN, MOREINFO);
  1748.       output("\n ■ Checking %s for mail... ", POPHOST);
  1749.       sprintf(s1, "%s*.*", temp_dir);
  1750.       if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
  1751.         sprintf(temp, "%s*.*", temp_dir);
  1752.         f1 = findfirst(temp, &ff, FA_ARCH);
  1753.         i = 0;
  1754.         send = 0;
  1755.         while (f1 == 0) {
  1756.           if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (ff.ff_fsize)) {
  1757.             recdbytes += ff.ff_fsize;
  1758.             sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1759.             sprintf(temp, "%s\\UU -decode %s %s %s", maindir, ff.ff_name,
  1760.                     temp_dir, net_data);
  1761.             if (!do_spawn(temp)) {
  1762.               send = 1;
  1763.               unlink(s1);
  1764.             }
  1765.           }
  1766.           f1 = findnext(&ff);
  1767.         }
  1768.       } else
  1769.         output("\n ■ No network packets to process");
  1770.  
  1771.       if (CLEANUP) {
  1772.         process_mail();
  1773.         set_net_num(netnum);
  1774.         process_bbsdata();
  1775.       }
  1776.     }
  1777.     sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1778.     if (exist(s)) {
  1779.       sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1780.               net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1781.       if (do_spawn(s))
  1782.         output("\n ■ Unknown error during export");
  1783.     }
  1784.     mailtime = clock() - starttime;
  1785.     if ((sy == 32767) || (ONECALL)) {
  1786.       starttime = clock();
  1787.       set_net_num(netnum);
  1788.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1789.       f1 = findfirst(temp, &ff, FA_ARCH);
  1790.       while (f1 == 0) {
  1791.         snewsbytes += ff.ff_fsize;
  1792.         f1 = findnext(&ff);
  1793.       }
  1794.       cd_to(maindir);
  1795.       strcpy(s1, net_data);
  1796.       if (LAST(s1) == '\\')
  1797.         LAST(s1) = 0;
  1798.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1799.       ok = 1;
  1800.       do_spawn(s);
  1801.       set_net_num(netnum);
  1802.       sprintf(temp, "%sP0*.*", net_data);
  1803.       f1 = findfirst(temp, &ff, 0);
  1804.       while (f1 == 0) {
  1805.         rnewsbytes += ff.ff_fsize;
  1806.         f1 = findnext(&ff);
  1807.       }
  1808.     }
  1809.   } else {
  1810.     output("\n");
  1811.     set_net_num(netnum);
  1812.     strcpy(s, "NETWORK0.EXE");
  1813.     for (i = 1; i < argc; i++) {
  1814.       strcat(s, " ");
  1815.       strcat(s, argv[i]);
  1816.     }
  1817.     s[strlen(s) + 1] = '\0';
  1818.     do_it(s);
  1819.     exit(EXIT_SUCCESS);
  1820.   }
  1821.  
  1822.   sprintf(s1, "%s\\NTIME.EXE", maindir);
  1823.   if ((exist(s1)) && (*TIMEHOST)) {
  1824.     output("\n ■ Checking %s...  ", TIMEHOST);
  1825.     sprintf(s, "%s %s", s1, TIMEHOST);
  1826.     do_spawn(s);
  1827.   }
  1828.   unload_klos();
  1829.  
  1830.   newstime = clock() - starttime;
  1831.   output("\n ■ Updating network connection records...");
  1832.   if (ONECALL) {
  1833.     recdbytes = ((recdbytes + 1023) / 1024);
  1834.     sentbytes = ((sentbytes + 1023) / 1024);
  1835.     if (mailtime)
  1836.       sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1837.     else
  1838.       strcpy(ttotal, "0.1");
  1839.     if (update_contacts(sy, sentbytes, recdbytes))
  1840.       output("\n ■ Unable to access CONTACT.NET!");
  1841.     if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1842.       output("\n ■ Unable to access NET.LOG!");
  1843.     if (newstime)
  1844.       sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1845.     else
  1846.       strcpy(ttotal, "0.1");
  1847.     rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1848.     snewsbytes = ((snewsbytes + 1023) / 1024);
  1849.     if (update_contact(32767, snewsbytes, rnewsbytes))
  1850.       output("\n ■ Unable to access CONTACT.NET!");
  1851.     if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1852.       output("\n ■ Unable to access NET.LOG!");
  1853.   } else {
  1854.     if (news) {
  1855.       if (newstime)
  1856.         sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1857.       else
  1858.         strcpy(ttotal, "0.1");
  1859.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1860.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1861.       if (update_contact(32767, snewsbytes, rnewsbytes))
  1862.         output("\n ■ Unable to access CONTACT.NET!");
  1863.       if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1864.         output("\n ■ Unable to access NET.LOG!");
  1865.     } else {
  1866.       recdbytes = ((recdbytes + 1023) / 1024);
  1867.       sentbytes = ((sentbytes + 1023) / 1024);
  1868.       if (mailtime)
  1869.         sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1870.       else
  1871.         strcpy(ttotal, "0.1");
  1872.       if (update_contacts(sy, sentbytes, recdbytes))
  1873.         output("\n ■ Unable to access CONTACT.NET!");
  1874.       if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1875.         output("\n ■ Unable to access NET.LOG!");
  1876.     }
  1877.   }
  1878.   cd_to(maindir);
  1879.   set_net_num(netnum);
  1880.   output("\n ■ %s completed!\n\n", version);
  1881.   return 0;
  1882. }
  1883.