home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B42.ZIP / NETWORK.C < prev    next >
C/C++ Source or Header  |  1997-09-26  |  47KB  |  1,882 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 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 = 10240;
  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[60], POPHOST[60], NEWSHOST[60], POPNAME[60], POPPASS[25];
  66.  
  67. char IPADDR[21], NETMASK[21], FWDNAME[60], FWDDOM[60];
  68. char DNS[21], DOMAIN[60], GATEWAY[60], 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 *) strchr(fmode, 'w')) != NULL) {
  271.     share = SH_DENYRD;
  272.     md = O_RDWR | O_CREAT | O_TRUNC;
  273.   } else
  274.     if (((char *) strchr(fmode, 'a')) != NULL) {
  275.     share = SH_DENYRD;
  276.     md = O_RDWR | O_CREAT;
  277.   } else {
  278.     md = O_RDONLY;
  279.   }
  280.   if (((char *) strchr(fmode, 'b')) != NULL) {
  281.     md |= O_BINARY;
  282.   }
  283.   if (((char *) strchr(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 *) strchr(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 *) strchr(whitespace, s[i - 1]) != NULL))
  409.     --i;
  410.   while ((i > 0) && ((char *) strchr(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.   sprintf(s, "%s\\FLINK.EXE", maindir);
  519.   if (exist(s))
  520.     do_spawn(s);
  521.   sprintf(s, "%s\\LINKER.EXE", maindir);
  522.   if (exist(s))
  523.     do_spawn(s);
  524. }
  525.  
  526. int valid_system(unsigned int ts)
  527. {
  528.   int i;
  529.  
  530.   for (i = 0; i < num_sys_list; i++) {
  531.     if (netsys[i].sysnum == ts) {
  532.       if (netsys[i].numhops == 1)
  533.         return (1);
  534.       else
  535.         return (0);
  536.     }
  537.   }
  538.   return (0);
  539. }
  540.  
  541. int create_contact_ppp(void)
  542. {
  543.   char *ss, fn[101], s[81];
  544.   unsigned short node;
  545.   int curfile, i;
  546.   net_address_rec curaddr;
  547.   FILE *fp, *fc;
  548.  
  549.   sprintf(fn, "%sCONTACT.PPP", net_data);
  550.   if ((fc = fsh_open(fn, "wb+")) == NULL) {
  551.     output("\n ■ Unable to create %s!\n", fn);
  552.     return (1);
  553.   }
  554.   curfile = 1;
  555.   num_addr = 0;
  556.   do {
  557.     sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  558.     if ((fp = fsh_open(fn, "rt")) == NULL)
  559.       curfile = -1;
  560.     while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
  561.       if (s[0] != '@')
  562.         continue;
  563.       ss = strtok(s, " \t\r");
  564.       node = atoi(&ss[1]);
  565.       if (node) {
  566.         ss = strtok(NULL, " \t\r");
  567.         trimstr1(ss);
  568.         curaddr.sysnum = node;
  569.         strcpy(curaddr.address, ss);
  570.         if (ss[0]) {
  571.           fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  572.           ++num_addr;
  573.         }
  574.       }
  575.     }
  576.     if (fp != NULL)
  577.       fclose(fp);
  578.     ++curfile;
  579.   } while (curfile > 0);
  580.   fseek(fc, 0L, SEEK_SET);
  581.   sprintf(fn, "%sADDRESS.0", net_data);
  582.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  583.     if (fc != NULL)
  584.       fclose(fc);
  585.     return(0);
  586.   }
  587.   while (fgets(s, 80, fp) != NULL) {
  588.     if (s[0] != '@')
  589.       continue;
  590.     ss = strtok(s, " \t\r");
  591.     node = atoi(&ss[1]);
  592.     do {
  593.       ss = strtok(NULL, " \t\r");
  594.       switch (ss[0]) {
  595.         case '-':
  596.           for (i = 0; i < num_addr; i++) {
  597.             fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  598.             fread(&curaddr, sizeof(net_address_rec), 1, fc);
  599.             if (node == curaddr.sysnum) {
  600.               curaddr.sysnum = 0;
  601.               fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  602.               fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  603.             }
  604.           }
  605.           break;
  606.       }
  607.     } while (ss);
  608.   }
  609.   if (fp != NULL)
  610.     fclose(fp);
  611.   if (fc != NULL)
  612.     fclose(fc);
  613.   return (0);
  614. }
  615.  
  616. void good_addr(char *address, unsigned short sn)
  617. {
  618.   char fn[101];
  619.   int i;
  620.   net_address_rec curaddr;
  621.   FILE *fc;
  622.  
  623.   address[0] = 0;
  624.   sprintf(fn, "%sCONTACT.PPP", net_data);
  625.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  626.     output("\n ■ Unable to read %s!\n", fn);
  627.     return;
  628.   }
  629.   for (i=0; ((i < num_addr) && (!address[0])); i++) {
  630.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  631.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  632.     if (sn == curaddr.sysnum)
  633.       strcpy(address, curaddr.address);
  634.   }
  635.   if (fc != NULL)
  636.     fclose(fc);
  637. }
  638.  
  639. int copyfile(char *input, char *output)
  640. {
  641.   int f1, f2, i;
  642.   char *b;
  643.   struct ftime ft;
  644.  
  645.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  646.     if ((b = (char *) malloc(16400)) == NULL)
  647.       return 0;
  648.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  649.     if (!f1) {
  650.       free(b);
  651.       b = NULL;
  652.       return 0;
  653.     }
  654.     getftime(f1, &ft);
  655.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  656.     if (!f2) {
  657.       free(b);
  658.       b = NULL;
  659.       sh_close(f1);
  660.       return 0;
  661.     }
  662.     i = read(f1, (void *) b, 16384);
  663.     while (i > 0) {
  664.       sh_write(f2, (void *) b, i);
  665.       i = read(f1, (void *) b, 16384);
  666.     }
  667.     f1 = sh_close(f1);
  668.     setftime(f2, &ft);
  669.     f2 = sh_close(f2);
  670.     free(b);
  671.     b = NULL;
  672.   }
  673.   return 1;
  674. }
  675.  
  676. void do_exit(int exitlevel)
  677. {
  678.   delay(2000);
  679.   exit(2 - exitlevel);
  680. }
  681.  
  682. int uu(char *fn, char *pktname, char *dest)
  683. {
  684.   int ok;
  685.   char s[121], s1[121], s2[81];
  686.   FILE *fp;
  687.  
  688.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  689.   if ((fp = fsh_open(s, "wt")) == NULL) {
  690.     output("\n ■ Unable to open %s for write operations!", s);
  691.     do_exit(EXIT_FAILURE);
  692.   } else {
  693.     sprintf(s2, "from: %s@%s\n", POPNAME, DOMAIN);
  694.     fprintf(fp, s2);
  695.     sprintf(s2, "to: %s\n", dest);
  696.     fprintf(fp, s2);
  697.     sprintf(s2, "subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
  698.     fprintf(fp, s2);
  699.   }
  700.   if (fp != NULL)
  701.     fclose(fp);
  702.   sprintf(s1, "%s\\UU -encode %s %s", maindir, fn, s);
  703.   ok = do_spawn(s1);
  704.   return ok;
  705. }
  706.  
  707. int update_contact(unsigned short sy, unsigned long sb, unsigned long rb)
  708. {
  709.   char s[101];
  710.   int i, i1, f;
  711.   long cur_time, l;
  712.  
  713.   sprintf(s, "%sCONTACT.NET", net_data);
  714.   f = sh_open1(s, O_RDONLY | O_BINARY);
  715.   if (f >= 0) {
  716.     l = filelength(f);
  717.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  718.     if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
  719.                                         sizeof(net_contact_rec))) == NULL) {
  720.       output("\n ■ Unable to allocate %d bytes of memory to update CONTACT.NET",
  721.               (int) (netcfg.num_ncn + 2) * sizeof(net_contact_rec));
  722.       sh_close(f);
  723.       return 1;
  724.     }
  725.     sh_lseek(f, 0L, SEEK_SET);
  726.     sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  727.     sh_close(f);
  728.   }
  729.   for (i = 0; i < netcfg.num_ncn; i++)
  730.     if (netcfg.ncn[i].systemnumber == sy)
  731.       i1 = i;
  732.   time(&cur_time);
  733.   netcfg.ncn[i1].lasttry = cur_time;
  734.   ++netcfg.ncn[i1].numcontacts;
  735.   if (!netcfg.ncn[i1].firstcontact)
  736.     netcfg.ncn[i1].firstcontact = cur_time;
  737.   netcfg.ncn[i1].lastcontact = cur_time;
  738.   netcfg.ncn[i1].lastcontactsent = cur_time;
  739.   netcfg.ncn[i1].bytes_sent += sb;
  740.   if (rb)
  741.     netcfg.ncn[i1].bytes_received += rb;
  742.   netcfg.ncn[i1].bytes_waiting = 0L;
  743.   sprintf(s, "%sS%hd.net", net_data, sy);
  744.   if (!exist(s))
  745.     sprintf(s, "%sZ%hd.net", net_data, sy);
  746.   f = sh_open1(s, O_RDONLY | O_BINARY);
  747.   if (f > 0) {
  748.     netcfg.ncn[i1].bytes_waiting += filelength(f);
  749.     close(f);
  750.   }
  751.   sprintf(s, "%sCONTACT.NET", net_data);
  752.   f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  753.   if (f > 0) {
  754.     sh_lseek(f, 0L, SEEK_SET);
  755.     sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  756.     sh_close(f);
  757.   }
  758.   if (netcfg.ncn)
  759.     farfree(netcfg.ncn);
  760.   return 0;
  761. }
  762.  
  763.  
  764. int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
  765. {
  766.   int i, i1, rc;
  767.   char fn[101];
  768.   net_address_rec curaddr;
  769.   FILE *fc;
  770.  
  771.   rc = 0;
  772.   sprintf(fn, "%sCONTACT.PPP", net_data);
  773.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  774.     output("\n ■ Unable to read %s!\n", fn);
  775.     rc = 1;
  776.     return (rc);
  777.   }
  778.   for (i = 0; i < num_addr; i++) {
  779.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  780.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  781.     if (curaddr.sysnum != 0) {
  782.       if (curaddr.sysnum == sy)
  783.         i1 = update_contact(curaddr.sysnum, sb, rb);
  784.       else
  785.         i1 = update_contact(curaddr.sysnum, 0, 0);
  786.       if (i1)
  787.         rc = 1;
  788.     }
  789.   }
  790.   if (fc != NULL)
  791.     fclose(fc);
  792.   return (rc);
  793. }
  794.  
  795. int uu_packets(void)
  796. {
  797.   char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
  798.   int found, sz, f, f1, i;
  799.   unsigned long sbytes, basename;
  800.   net_address_rec curaddr;
  801.   FILE *fc;
  802.  
  803.   num_sys_list = 0;
  804.   basename = time(NULL);
  805.   sprintf(s, "%sBBSDATA.NET", net_data);
  806.   f = sh_open1(s, O_RDONLY | O_BINARY);
  807.   if (f > 0) {
  808.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  809.     if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
  810.                                     sizeof(net_system_list_rec))) == NULL) {
  811.       output("\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  812.               (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  813.       sh_close(f);
  814.       return 0;
  815.     }
  816.     sh_lseek(f, 0L, SEEK_SET);
  817.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  818.     sh_close(f);
  819.   } else
  820.     return 0;
  821.  
  822.   sprintf(s1, "%sCONTACT.PPP", net_data);
  823.   if ((fc = fsh_open(s1, "rb+")) == NULL) {
  824.     output("\n ■ Unable to read %s!\n", s1);
  825.     farfree(netsys);
  826.     return 0;
  827.   }
  828.   for (i=0; i < num_addr; i++) {
  829.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  830.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  831.     if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
  832.       sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
  833.       if (exist(s1))
  834.         sz = 0;
  835.       else {
  836.         sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
  837.         if (exist(s1))
  838.           sz = 1;
  839.         else
  840.           continue;
  841.       }
  842.       do {
  843.         sprintf(pktname, "%8.8lx", ++basename);
  844.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  845.       } while (exist(temp));
  846.       backline();
  847.       output("\r ■ Encoding %s%hd.NET as %s.UUE -",
  848.               sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
  849.       if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
  850.         output("\n ■ Error creating %sMQUEUE\\%s.UUE", net_data, pktname);
  851.         if (fc != NULL)
  852.           fclose(fc);
  853.         farfree(netsys);
  854.         do_exit(EXIT_FAILURE);
  855.       } else {
  856.         found = 1;
  857.         if (KEEPSENT) {
  858.           sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  859.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  860.           f1 = sh_open1(s3, O_RDONLY | O_BINARY);
  861.           if (f1 > 0) {
  862.             sbytes = filelength(f1);
  863.             sh_close(f1);
  864.           }
  865.           if (!copyfile(s3, s2))
  866.             output("\n ■ Error moving %s%hd.NET", sz ? "Z" : "S", curaddr.sysnum);
  867.         }
  868.         unlink(s1);
  869.         update_contact(curaddr.sysnum, sbytes, 0);
  870.       }
  871.     }
  872.   }
  873.   if (fc != NULL)
  874.     fclose(fc);
  875.   farfree(netsys);
  876.   return found;
  877. }
  878.  
  879. int purge_sent(void)
  880. {
  881.   char s[121];
  882.   int f1, howmany = 0;
  883.   long age;
  884.   struct ffblk ff;
  885.   struct stat fileinfo;
  886.  
  887.   sprintf(s, "%sSENT\\*.*", net_data);
  888.   f1 = findfirst(s, &ff, 0);
  889.   while (f1 == 0) {
  890.     sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
  891.     if (stat(s, &fileinfo) == 0) {
  892.       age = (time(NULL) - fileinfo.st_atime);
  893.       if (age > (86400L * KEEPSENT)) {
  894.         ++howmany;
  895.         unlink(s);
  896.       }
  897.     }
  898.     f1 = findnext(&ff);
  899.   }
  900.   return howmany;
  901. }
  902.  
  903. int parse_net_ini(void)
  904. {
  905.   char cursect;
  906.   char line[121], *ss;
  907.   FILE *fp;
  908.  
  909.   if ((fp = fsh_open("NET.INI", "rt")) == NULL)
  910.     return (0);
  911.   while (fgets(line, 80, fp)) {
  912.     stripspace(line);
  913.     ss = NULL;
  914.     ss = strtok(line, "=");
  915.     if (ss)
  916.       ss = strtok(NULL, "\n");
  917.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  918.       continue;
  919.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  920.         (strnicmp(line, "[PPPNET]", 8) == 0)) {
  921.       cursect = INI_NETWORK;
  922.       ini_section |= INI_NETWORK;
  923.       continue;
  924.     }
  925.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  926.       cursect = INI_GENERAL;
  927.       ini_section |= INI_GENERAL;
  928.       continue;
  929.     }
  930.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  931.       cursect = INI_NEWS;
  932.       ini_section |= INI_NEWS;
  933.       continue;
  934.     }
  935.     if (cursect & INI_NETWORK) {
  936.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  937.         if (ss)
  938.           strcpy(SMTPHOST, ss);
  939.         continue;
  940.       }
  941.       if (strnicmp(line, "POPHOST", 7) == 0) {
  942.         if (ss)
  943.           strcpy(POPHOST, ss);
  944.         continue;
  945.       }
  946.       if (strnicmp(line, "POPNAME", 7) == 0) {
  947.         if (ss)
  948.           strcpy(POPNAME, ss);
  949.         continue;
  950.       }
  951.       if (strnicmp(line, "POPPASS", 7) == 0) {
  952.         if (ss)
  953.           strcpy(POPPASS, ss);
  954.         continue;
  955.       }
  956.     }
  957.     if (cursect & INI_GENERAL) {
  958.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  959.         if (atoi(ss))
  960.           TIMEOUT = atoi(ss);
  961.         continue;
  962.       }
  963.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  964.         if (atoi(ss))
  965.           SOCK_DELAY = atoi(ss);
  966.         continue;
  967.       }
  968.       if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
  969.         if (atoi(ss))
  970.           INACTIVE = atoi(ss);
  971.         continue;
  972.       }
  973.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  974.         if (atoi(ss))
  975.           KEEPSENT = atoi(ss);
  976.         continue;
  977.       }
  978.       if (strnicmp(line, "PURGE", 5) == 0) {
  979.         if (toupper(ss[0]) == 'N')
  980.           PURGE = 0;
  981.         continue;
  982.       }
  983.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  984.         if (toupper(ss[0]) == 'N')
  985.           ALLMAIL = 0;
  986.         continue;
  987.       }
  988.       if (strnicmp(line, "ONECALL", 7) == 0) {
  989.         if (toupper(ss[0]) == 'Y')
  990.           ONECALL = 1;
  991.         continue;
  992.       }
  993.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  994.         if (toupper(ss[0]) == 'Y')
  995.           MOREINFO = 1;
  996.         continue;
  997.       }
  998.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  999.         if (toupper(ss[0]) == 'Y')
  1000.           CLEANUP = 1;
  1001.         continue;
  1002.       }
  1003.       if (strnicmp(line, "IPADDR", 6) == 0) {
  1004.         if ((ss) && (ss[0] != '0'))
  1005.           strcpy(IPADDR, ss);
  1006.         continue;
  1007.       }
  1008.       if (strnicmp(line, "NETMASK", 7) == 0) {
  1009.         if (ss)
  1010.           strcpy(NETMASK, ss);
  1011.         continue;
  1012.       }
  1013.       if (strnicmp(line, "DNS", 3) == 0) {
  1014.         if (ss)
  1015.           strcpy(DNS, ss);
  1016.         continue;
  1017.       }
  1018.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  1019.         if (ss)
  1020.           strcpy(DOMAIN, ss);
  1021.         continue;
  1022.       }
  1023.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  1024.         if (ss)
  1025.           strcpy(FWDNAME, ss);
  1026.         continue;
  1027.       }
  1028.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  1029.         if (ss)
  1030.           strcpy(FWDDOM, ss);
  1031.         continue;
  1032.       }
  1033.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  1034.         if ((ss) && (ss[0] != '0'))
  1035.           strcpy(GATEWAY, ss);
  1036.         continue;
  1037.       }
  1038.     }
  1039.     if (cursect & INI_NEWS) {
  1040.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  1041.         if (ss)
  1042.           strcpy(NEWSHOST, ss);
  1043.         continue;
  1044.       }
  1045.     }
  1046.   }
  1047.   if (!FWDNAME[0])
  1048.     strcpy(FWDNAME, POPNAME);
  1049.   if (!FWDDOM[0])
  1050.     strcpy(FWDDOM, DOMAIN);
  1051.   if (fp != NULL)
  1052.     fclose(fp);
  1053.   return (1);
  1054. }
  1055.  
  1056.  
  1057. int count_lines(char *s)
  1058. {
  1059.   FILE *fp;
  1060.   char fn[121];
  1061.   unsigned int nl = 0;
  1062.   const int NEWLINE = '\n';
  1063.   int c;
  1064.  
  1065.   strcpy(fn, s);
  1066.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  1067.     printf("\n ■ Cannot open %s", fn);
  1068.     return 0;
  1069.   }
  1070.   while ((c = getc(fp)) != EOF) {
  1071.     if (c == NEWLINE)
  1072.       ++nl;
  1073.   }
  1074.   if (fp != NULL)
  1075.     fclose(fp);
  1076.   return nl;
  1077. }
  1078.  
  1079. typedef struct {
  1080.   char line[81];
  1081. } nlines;
  1082.  
  1083. nlines *NETLOG;
  1084.  
  1085. int write_netlog(int sn, long sent, long recd, char *tmused)
  1086. {
  1087.   FILE *fp;
  1088.   int i = 0;
  1089.   unsigned int lines;
  1090.   char s[81], s1[81], s2[81], fn[121];
  1091.   struct tm *time_now;
  1092.   time_t some;
  1093.  
  1094.   sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
  1095.   lines = 0;
  1096.   lines = count_lines(fn);
  1097.   if ((NETLOG = ((nlines *) farmalloc((lines + 2) * 81))) == NULL) {
  1098.     output("\n ■ Unable to allocate %d bytes for NET.LOG entry",
  1099.             (lines + 2) * 81);
  1100.     return 1;
  1101.   }
  1102.   if ((fp = fsh_open(fn, "r")) == NULL) {
  1103.     farfree(NETLOG);
  1104.     return 1;
  1105.   }
  1106.   while (fgets(s, 80, fp)) {
  1107.     strtok(s, "\n");
  1108.     strcpy(NETLOG[i++].line, s);
  1109.   }
  1110.   if (fp != NULL)
  1111.     fclose(fp);
  1112.   time(&some);
  1113.   time_now = localtime(&some);
  1114.   strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
  1115.   if ((sent) || (recd)) {
  1116.     if ((recd) && (!sent))
  1117.       sprintf(s2, "       , R:%4ldk,", recd);
  1118.     else {
  1119.       if ((recd) && (sent))
  1120.         sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
  1121.       else
  1122.         sprintf(s2, "S:%4ldk,         ", sent);
  1123.     }
  1124.   } else
  1125.     strcpy(s2, "                 ");
  1126.   if ((fp = fsh_open(fn, "wt+")) != NULL) {
  1127.     fprintf(fp, "%s To %5d, %s          %4s min  %s\n", s1, sn, s2,
  1128.             tmused, net_name);
  1129.     for (i = 0; i < lines; i++)
  1130.       fprintf(fp, "%s\n", NETLOG[i].line);
  1131.     fclose(fp);
  1132.   }
  1133.   farfree(NETLOG);
  1134.   return 0;
  1135. }
  1136.  
  1137. void read_networks(void)
  1138. {
  1139.   int f;
  1140.   char s[121];
  1141.  
  1142.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1143.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1144.   net_num_max = 0;
  1145.   if (f > 0) {
  1146.     net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
  1147.     sh_close(f);
  1148.   }
  1149. }
  1150.  
  1151. void init(void)
  1152. {
  1153.   char s[81], s1[81], *ss;
  1154.   int i, i1, dv, f;
  1155.   struct tm *time_now;
  1156.   time_t some;
  1157.  
  1158.   output("\n%s\n%s\n\n", version, author);
  1159.   get_dir(maindir, 0);
  1160.   ss = getenv("WWIV_INSTANCE");
  1161.   if (ss) {
  1162.     instance = atoi(ss);
  1163.     if ((instance <= 0) || (instance > 999)) {
  1164.       output("\n ■ WWIV_INSTANCE can only be 1..999!");
  1165.       instance = 1;
  1166.     }
  1167.   } else {
  1168.     instance = 1;
  1169.   }
  1170.  
  1171.   detect_multitask();
  1172.  
  1173.   switch (multitasker) {
  1174.     case 1:
  1175.       dv = get_dv_version();
  1176.       sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
  1177.       break;
  1178.     case 2:
  1179.       dv = get_win_version();
  1180.       if (dv == 4)
  1181.         strcpy(s1, "Windows 95");
  1182.       else
  1183.         sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
  1184.       break;
  1185.     case 3:
  1186.       dv = get_dv_version();
  1187.       sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
  1188.       break;
  1189.     case 4:
  1190.     case 5:
  1191.     case 6:
  1192.     case 7:
  1193.       if ((_osmajor / 10 == 2) && (_osminor >= 30))
  1194.         strcpy(s1, "OS/2 Warp");
  1195.       else
  1196.         sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
  1197.       break;
  1198.     case 8:
  1199.       sprintf(s1, "NETBIOS network");
  1200.       multitasker = 1;
  1201.       break;
  1202.     default:
  1203.       strcpy(s1, "DOS");
  1204.       break;
  1205.   }
  1206.   strcpy(s, "CONFIG.DAT");
  1207.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1208.   if (f < 0) {
  1209.     output("\n ■ %s NOT FOUND.", s);
  1210.     return;
  1211.   }
  1212.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1213.   sh_close(f);
  1214.   output(" ■ Running under %s on instance %d ", s1, instance);
  1215.   time(&some);
  1216.   time_now = localtime(&some);
  1217.   strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1218.   printf(s);
  1219.   strcpy(s, "CONFIG.OVR");
  1220.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1221.   if (f < 0) {
  1222.     output("\n ■ %s NOT FOUND.", s);
  1223.     return;
  1224.   }
  1225.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1226.   read(f, &syscfgovr, sizeof(configoverrec));
  1227.   f = sh_close(f);
  1228.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1229.   if (!exist(s)) {
  1230.     output("\n ■ %s NOT FOUND.", s);
  1231.     return;
  1232.   }
  1233.   read_networks();
  1234.   i = i1 = 0;
  1235.   while (environ[i] != NULL) {
  1236.     xenviron[i1++] = environ[i];
  1237.     ++i;
  1238.   }
  1239.   xenviron[i1] = NULL;
  1240. }
  1241.  
  1242. long getfctime(char *s)
  1243. {
  1244.   struct stat statbuf;
  1245.  
  1246.   if (stat(s, &statbuf) < 0)
  1247.     return (0L);
  1248.   else
  1249.     return (statbuf.st_atime);
  1250. }
  1251.  
  1252. int process_bbsdata(void)
  1253. {
  1254.   char s[101];
  1255.   unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
  1256.   int tf, n, net3;
  1257.  
  1258.   net3 = 0;
  1259.   sprintf(s, "%sBBSLIST.NET", net_data);
  1260.   bbslist_ctime = getfctime(s);
  1261.   sprintf(s, "%sCONNECT.NET", net_data);
  1262.   connect_ctime = getfctime(s);
  1263.   sprintf(s, "%sCALLOUT.NET", net_data);
  1264.   callout_ctime = getfctime(s);
  1265.   sprintf(s, "%sBBSDATA.NET", net_data);
  1266.   bbsdata_ctime = getfctime(s);
  1267.   sprintf(s, "%sBBSLIST.UPD", net_data);
  1268.   bbslist_ctime = getfctime(s);
  1269.   sprintf(s, "%sCONNECT.UPD", net_data);
  1270.   connect_ctime = getfctime(s);
  1271.  
  1272.   n = 0;
  1273.   tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
  1274.   if (tf)
  1275.     n = 1;
  1276.   tf = (tf || (callout_ctime > bbsdata_ctime));
  1277.   if (tf) {
  1278.     sprintf(s, "NETWORK3 .%d", netnum);
  1279.     if (n) {
  1280.       sprintf(s, "NETWORK3 .%d Y", netnum);
  1281.       net3 = 1;
  1282.     }
  1283.     do_spawn(s);
  1284.   }
  1285.   return (net3);
  1286. }
  1287.  
  1288. void do_it(char *cl)
  1289. {
  1290.   int i, i1, l;
  1291.   char *s, *ss[30];
  1292.  
  1293.   s = strdup(cl);
  1294.   ss[0] = s;
  1295.   i = 1;
  1296.   l = strlen(s);
  1297.   for (i1 = 1; i1 < l; i1++)
  1298.     if (s[i1] == 32) {
  1299.       s[i1] = 0;
  1300.       ss[i++] = &(s[i1 + 1]);
  1301.     }
  1302.   ss[i] = NULL;
  1303.   execvpe(ss[0], ss, xenviron);
  1304. }
  1305.  
  1306. int create_wattcp_cfg(void)
  1307. {
  1308.   char s[MAXPATH], s1[41];
  1309.   FILE *fp;
  1310.  
  1311.   sprintf(s, "%s\\WATTCP.CFG", maindir);
  1312.   if ((fp = fsh_open(s, "wt")) == NULL) {
  1313.     output("\n ■ Can't open %s for output!", s);
  1314.     return 1;
  1315.   }
  1316.   fseek(fp, 0L, SEEK_SET);
  1317.   sprintf(s, "my_ip=%s\n", IPADDR);
  1318.   fprintf(fp, s);
  1319.   fprintf(fp, "netmask=%s\n", NETMASK);
  1320.   fprintf(fp, "nameserver=%s\n", DNS);
  1321.   if (GATEWAY[0] == 0) {
  1322.     strcpy(s1, IPADDR);
  1323.     while (LAST(s1) != '.')
  1324.       LAST(s1) = 0;
  1325.     strcat(s1, "1");
  1326.     strcpy(GATEWAY, s1);
  1327.   }
  1328.   sprintf(s, "gateway=%s\n", GATEWAY);
  1329.   fprintf(fp, s);
  1330.   fprintf(fp, "domainslist=\"%s\"\n", DOMAIN);
  1331.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1332.   fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
  1333.   fprintf(fp, "inactive=%d\n", INACTIVE);
  1334.   if (fp != NULL)
  1335.     fclose(fp);
  1336.   return 0;
  1337. }
  1338.  
  1339. int check_for_lsl(void)
  1340. {
  1341.   union REGS r;
  1342.   struct SREGS s;
  1343.   char *intstr;
  1344.  
  1345.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1346.     r.h.al = 0;
  1347.     int86x(0x2f, &r, &r, &s);
  1348.     if (r.h.al == 0xff) {
  1349.       intstr = (char *) MK_FP(s.es, r.x.si);
  1350.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1351.         return 1;
  1352.     }
  1353.   }
  1354.   return 0;
  1355. }
  1356.  
  1357. void klos_ppp(void)
  1358. {
  1359.   char s[121], fn[MAXPATH], *ss;
  1360.   int i;
  1361.   FILE *fp;
  1362.  
  1363.   lsl_loaded = check_for_lsl();
  1364.   if (!lsl_loaded) {
  1365.     sprintf(s, "%s\\LSL.COM", maindir);
  1366.     if (exist(s)) {
  1367.       output("\n ■ Loading Link Support Layer and ");
  1368.       do_spawn(s);
  1369.     } else {
  1370.       output("\n ■ LSL.COM not in BBS main directory!");
  1371.       do_exit(EXIT_FAILURE);
  1372.     }
  1373.   } else
  1374.     output("\n ■ LSL already in memory - loading ");
  1375.   sprintf(s, "%s\\PPP.EXE", maindir);
  1376.   if (exist(s)) {
  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.     sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1389.     i = do_spawn(s);
  1390.     switch (i) {
  1391.       case 0:
  1392.         output(" connected!");
  1393.         break;
  1394.       case 1:
  1395.         output("\n ■ Unable to establish connection... aborting");
  1396.         sprintf(s, "%s\\PPP U", maindir);
  1397.         do_spawn(s);
  1398.         if (!lsl_loaded) {
  1399.           sprintf(s, "%s\\LSL U", maindir);
  1400.           do_spawn(s);
  1401.         }
  1402.         do_exit(EXIT_FAILURE);
  1403.       case 2:
  1404.         output("\n ■ Unable to find PPP layer... aborting");
  1405.         if (!lsl_loaded) {
  1406.           sprintf(s, "%s\\LSL U", maindir);
  1407.           do_spawn(s);
  1408.         }
  1409.         do_exit(EXIT_FAILURE);
  1410.       default:
  1411.         output("\n ■ Unknown PPPState Error #%d... aborting", i);
  1412.         sprintf(s, "%s\\PPP U", maindir);
  1413.         do_spawn(s);
  1414.         if (!lsl_loaded) {
  1415.           sprintf(s, "%s\\LSL U", maindir);
  1416.           do_spawn(s);
  1417.         }
  1418.         do_exit(EXIT_FAILURE);
  1419.     }
  1420.   } else {
  1421.     output("\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1422.     do_exit(EXIT_FAILURE);
  1423.   }
  1424.   if (!IPADDR[0]) {
  1425.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1426.     if (exist(s)) {
  1427.       do_spawn(s);
  1428.     } else {
  1429.       output("\n ■ %s\\PPPWAT.EXE not found!", maindir);
  1430.       unload_klos();
  1431.       do_exit(EXIT_FAILURE);
  1432.     }
  1433.     sprintf(fn, "%s\\WATTCP.CFG", maindir);
  1434.     if ((fp = fsh_open(fn, "rt")) == NULL) {
  1435.       output("\n ■ Unable to read %s\\WATTCP.CFG... aborting!", maindir);
  1436.       unload_klos();
  1437.       do_exit(EXIT_FAILURE);
  1438.     } else {
  1439.       while (fgets(s, 100, fp) != NULL) {
  1440.         if (strnicmp(s, "my_ip", 5) == 0) {
  1441.           ss = strtok(s, "=");
  1442.           ss = strtok(NULL, "\r");
  1443.           trimstr1(ss);
  1444.           strcpy(IPADDR, ss);
  1445.           break;
  1446.         }
  1447.       }
  1448.     }
  1449.     if (fp != NULL)
  1450.       fclose(fp);
  1451.   }
  1452.   if (IPADDR) {
  1453.     output("\n ■ Session IP address is %s... ", IPADDR);
  1454.     if (create_wattcp_cfg()) {
  1455.       unload_klos();
  1456.       do_exit(EXIT_FAILURE);
  1457.     }
  1458.   } else {
  1459.     output("\n ■ Could not find IP Address... aborting!");
  1460.     unload_klos();
  1461.     do_exit(EXIT_FAILURE);
  1462.   }
  1463.   sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1464.   if (exist(s)) {
  1465.     do_spawn(s);
  1466.   } else {
  1467.     output("\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1468.     do_exit(EXIT_FAILURE);
  1469.   }
  1470.   output("establishing socket     ");
  1471.   for (i = 5; i >= 0; i--) {
  1472.     output("\b\b\b\b%d...", i);
  1473.     delay(1000);
  1474.   }
  1475.   output("\b\b\b\b\b... ready!");
  1476. }
  1477.  
  1478. double freek(int dr)
  1479. {
  1480.   float d;
  1481.   struct dfree df;
  1482.  
  1483.   getdfree(dr, &df);
  1484.   d = (float) df.df_avail;
  1485.   d *= ((float) df.df_bsec);
  1486.   d *= ((float) df.df_sclus);
  1487.   d /= 1024.0;
  1488.   if (df.df_sclus == 0xffff)
  1489.     d = -1.0;
  1490.   return (d);
  1491. }
  1492.  
  1493. int main(int argc, char *argv[])
  1494. {
  1495.   int i, ok, news, totf, send, f1;
  1496.   unsigned short sy;
  1497.   double dspace;
  1498.   char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
  1499.   char ttotal[21];
  1500.   clock_t starttime, mailtime, newstime;
  1501.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1502.   FILE *fp;
  1503.   struct ffblk ff;
  1504.  
  1505.   init();
  1506.   news = 0;
  1507.   num_addr = 0;
  1508.   ss = argv[argc - 1];
  1509.   ok = 0;
  1510.   if (strstr((char *) ss, ".") != NULL) {
  1511.     if (atoi(&ss[1]) < net_num_max) {
  1512.       netnum = atoi(&ss[1]);
  1513.       ok = 1;
  1514.     }
  1515.   } else {
  1516.     ss = (getenv("WWIV_NET"));
  1517.     netnum = atoi(ss);
  1518.     if (netnum < net_num_max)
  1519.       ok = 1;
  1520.   }
  1521.   if (!ok) {
  1522.     strcpy(s, "WWIV_NET.DAT");
  1523.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1524.       fgets(s, 3, fp);
  1525.       netnum = atoi(s);
  1526.       if (fp != NULL)
  1527.         fclose(fp);
  1528.       if (netnum < net_num_max)
  1529.         ok = 1;
  1530.     }
  1531.   }
  1532.   ss = argv[1];
  1533.   if (strncmpi(ss, "/N", 2))
  1534.     ok = 0;
  1535.   set_net_num(netnum);
  1536.   sprintf(s, "%sADDRESS.1", net_data);
  1537.   if (!exist(s))
  1538.     ok = 0;
  1539.   if (ok) {
  1540.     SMTPHOST[0] = 0;
  1541.     POPHOST[0] = 0;
  1542.     NEWSHOST[0] = 0;
  1543.     POPNAME[0] = 0;
  1544.     POPPASS[0] = 0;
  1545.     IPADDR[0] = 0;
  1546.     NETMASK[0] = 0;
  1547.     DNS[0] = 0;
  1548.     DOMAIN[0] = 0;
  1549.     GATEWAY[0] = 0;
  1550.     FWDNAME[0] = 0;
  1551.     FWDDOM[0] = 0;
  1552.     if (parse_net_ini()) {
  1553.       set_net_num(netnum);
  1554.       if (ini_section & INI_NETWORK) {
  1555.         if (!(ini_section & INI_GENERAL)) {
  1556.           output("\n ■ [GENERAL] tag missing from NET.INI!");
  1557.           ok = 0;
  1558.         }
  1559.       } else {
  1560.         ok = 0;
  1561.         output("\n ■ [FILENET] tag missing from NET.INI!");
  1562.       }
  1563.     } else {
  1564.       output("\n ■ Could not open file NET.INI!");
  1565.       ok = 0;
  1566.     }
  1567.   }
  1568.   if (ok)
  1569.     if (create_contact_ppp())
  1570.       ok = 0;
  1571.   if (ok) {
  1572.     output("\n ■ Memory available : %ld bytes -", coreleft());
  1573.     if (net_data[1] == ':')
  1574.       i = net_data[0];
  1575.     else
  1576.       i = maindir[0];
  1577.     i = toupper(i) - 'A' + 1;
  1578.     dspace = freek(i);
  1579.     if (dspace < 1024.0) {
  1580.       output("\n ■ Only %.1fK available on drive %c:... aborting!",
  1581.               dspace, i + '@');
  1582.       do_exit(EXIT_FAILURE);
  1583.     } else {
  1584.       output(" Disk space ");
  1585.       if (dspace < 10000.0)
  1586.         output(": %c:%.1fK", i + '@', dspace);
  1587.       else
  1588.         output(": %c:%.1fM", i + '@', dspace / 1024.0);
  1589.     }
  1590.  
  1591.     set_net_num(netnum);
  1592.     ss = argv[1];
  1593.     sy = atoi(&ss[2]);
  1594.     destaddr[0] = 0;
  1595.     if (sy != 32767)
  1596.       good_addr(destaddr, sy);
  1597.  
  1598.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1599.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1600.       ok = 0;
  1601.     } else {
  1602.       ok = 1;
  1603.       if (sy == 32767) {
  1604.         if (ini_section & INI_NEWS) {
  1605.           output("\n ■ Initiating newsgroup retrieval session...");
  1606.           news = 1;
  1607.         } else {
  1608.           output("\n ■ [NEWS] tag missing from NET.INI!");
  1609.           do_exit(EXIT_FAILURE);
  1610.         }
  1611.       }
  1612.     }
  1613.   }
  1614.   if (ok) {
  1615.     if (!MOREINFO)
  1616.       freopen(NULL, "w", stdout);
  1617.     if (CLEANUP)
  1618.       process_mail();
  1619.     set_net_num(netnum);
  1620.     sprintf(s, "%sSPOOL", net_data);
  1621.     if ((make_path(s)) < 0) {
  1622.       output("\n ■ Unable to create \"%s\"", s);
  1623.       do_exit(EXIT_FAILURE);
  1624.     }
  1625.     sprintf(s, "%sMQUEUE", net_data);
  1626.     if ((make_path(s)) < 0) {
  1627.       output("\n ■ Unable to create \"%s\"", s);
  1628.       do_exit(EXIT_FAILURE);
  1629.     }
  1630.     sprintf(s, "%sOUTBOUND", net_data);
  1631.     if ((make_path(s)) < 0) {
  1632.       output("\n ■ Unable to create \"%s\"", s);
  1633.       do_exit(EXIT_FAILURE);
  1634.     }
  1635.     sprintf(s, "%sINBOUND", net_data);
  1636.     if ((make_path(s)) < 0) {
  1637.       output("\n ■ Unable to create \"%s\"", s);
  1638.       do_exit(EXIT_FAILURE);
  1639.     }
  1640.     sprintf(s, "%sSENT", net_data);
  1641.     if ((make_path(s)) < 0) {
  1642.       output("\n ■ Unable to create \"%s\"", s);
  1643.       do_exit(EXIT_FAILURE);
  1644.     }
  1645.     if (PURGE) {
  1646.       if ((KEEPSENT) && (sy != 32767)) {
  1647.         output("\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1648.                 KEEPSENT == 1 ? "" : "s");
  1649.         i = purge_sent();
  1650.         output(" %d packet%s deleted.", i, i == 1 ? "" : "s");
  1651.       }
  1652.     }
  1653.     sprintf(s, "%sCHECKNET", net_data);
  1654.     if ((make_path(s)) < 0) {
  1655.       output("\n ■ Unable to create \"%s\"", s);
  1656.       do_exit(EXIT_FAILURE);
  1657.     }
  1658.     send = 1;
  1659.  
  1660.     cd_to(maindir);
  1661.     sprintf(s, "%s\\EXP.EXE", maindir);
  1662.     if (!exist(s)) {
  1663.       output("\n ■ Export module EXP.EXE not found!");
  1664.     } else {
  1665.       sprintf(s, "%sS32767.NET", net_data);
  1666.       sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
  1667.       if ((exist(s)) || (exist(s1))) {
  1668.         sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1669.                 net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1670.         if (do_spawn(s))
  1671.           output("\n ■ Unknown error during export.");
  1672.       } else
  1673.         output("\n ■ No Internet mail or newsgroup articles to export.");
  1674.     }
  1675.  
  1676.     cd_to(maindir);
  1677.     if ((sy != 32767) || (ONECALL)) {
  1678.       output("\n ■ Preparing outbound mail for transmission...");
  1679.       if (!uu_packets()) {
  1680.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1681.         if (findfirst(s, &ff, 0) == 0) {
  1682.           output(" outbound packets in MQUEUE.");
  1683.         } else {
  1684.           output(" no mail or packets to send.");
  1685.           send = 0;
  1686.         }
  1687.       } else {
  1688.         backline();
  1689.         output("\r ■ All packets prepared for transmission.");
  1690.       }
  1691.     }
  1692.     sprintf(s, "%sNET%d.CFG", net_data, instance);
  1693.     if (exist(s)) {
  1694.       sprintf(s1, "%s\\NET.CFG", maindir);
  1695.       unlink(s1);
  1696.       if (!copyfile(s, s1))
  1697.         output("\n ■ Unable to copy %s to %s", s, s1);
  1698.     }
  1699.  
  1700.     starttime = clock();
  1701.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1702.  
  1703.     cd_to(maindir);
  1704.  
  1705.     klos_ppp();
  1706.  
  1707.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1708.  
  1709.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1710.       totf = 0;
  1711.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1712.       f1 = findfirst(temp, &ff, FA_ARCH);
  1713.       if (f1 == 0)
  1714.         output("\n");
  1715.       while (f1 == 0) {
  1716.         sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
  1717.         sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
  1718.         backline();
  1719.         output("\r ■ SND : %s ", ff.ff_name);
  1720.         if (do_spawn(s) == EXIT_SUCCESS) {
  1721.           unlink(s1);
  1722.           sentbytes += ff.ff_fsize;
  1723.           ++totf;
  1724.         } else
  1725.           output("\n ■ Unsuccessful!  %s remains in MQUEUE.", ff.ff_name);
  1726.         f1 = findnext(&ff);
  1727.       }
  1728.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1729.       f1 = findfirst(temp, &ff, FA_ARCH);
  1730.       while (f1 == 0) {
  1731.         sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
  1732.         sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
  1733.         backline();
  1734.         output("\r ■ SND : %s ", ff.ff_name);
  1735.         if (do_spawn(s) == EXIT_SUCCESS) {
  1736.           unlink(s1);
  1737.           sentbytes += ff.ff_fsize;
  1738.           ++totf;
  1739.         } else
  1740.           output("\n ■ Unsuccessful!  %s remains in MQUEUE.", ff.ff_name);
  1741.         f1 = findnext(&ff);
  1742.       }
  1743.       backline();
  1744.       output("\r ■ Outbound mail transfer completed - %d file%s (%ldK).",
  1745.               totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1746.       send = 0;
  1747.     }
  1748.     if ((sy != 32767) || (ONECALL)) {
  1749.       sprintf(s, "%s\\POP -receive %s %s %s %s %d %s %d", maindir, POPHOST, POPNAME, POPPASS,
  1750.               temp_dir, ALLMAIL, DOMAIN, MOREINFO);
  1751.       output("\n ■ Checking %s for inbound mail - ", POPHOST);
  1752.       sprintf(s1, "%s*.*", temp_dir);
  1753.       if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
  1754.         sprintf(temp, "%s*.*", temp_dir);
  1755.         f1 = findfirst(temp, &ff, FA_ARCH);
  1756.         i = 0;
  1757.         send = 0;
  1758.         while (f1 == 0) {
  1759.           if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (ff.ff_fsize)) {
  1760.             recdbytes += ff.ff_fsize;
  1761.             sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1762.             sprintf(temp, "%s\\UU -decode %s %s %s", maindir, ff.ff_name,
  1763.                     temp_dir, net_data);
  1764.             if (!do_spawn(temp)) {
  1765.               send = 1;
  1766.               unlink(s1);
  1767.             }
  1768.           }
  1769.           f1 = findnext(&ff);
  1770.         }
  1771.       } else
  1772.         output("\n ■ No network packets to process");
  1773.  
  1774.       if ((send) && (CLEANUP)) {
  1775.         output("\n ■ Running FLINK/Linker on received packets... please wait.");
  1776.         process_mail();
  1777.         set_net_num(netnum);
  1778.         process_bbsdata();
  1779.       }
  1780.     }
  1781.     sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1782.     if (exist(s)) {
  1783.       sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1784.               net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1785.       if (do_spawn(s))
  1786.         output("\n ■ Unknown error during export");
  1787.     }
  1788.     mailtime = clock() - starttime;
  1789.     if ((sy == 32767) || (ONECALL)) {
  1790.       starttime = clock();
  1791.       set_net_num(netnum);
  1792.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1793.       f1 = findfirst(temp, &ff, FA_ARCH);
  1794.       while (f1 == 0) {
  1795.         snewsbytes += ff.ff_fsize;
  1796.         f1 = findnext(&ff);
  1797.       }
  1798.       cd_to(maindir);
  1799.       strcpy(s1, net_data);
  1800.       if (LAST(s1) == '\\')
  1801.         LAST(s1) = 0;
  1802.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1803.       ok = 1;
  1804.       if (do_spawn(s) != EXIT_SUCCESS)
  1805.         output("\n ■ Unsuccessful news retrieval session...");
  1806.       set_net_num(netnum);
  1807.       sprintf(temp, "%sP0*.*", net_data);
  1808.       f1 = findfirst(temp, &ff, 0);
  1809.       while (f1 == 0) {
  1810.         rnewsbytes += ff.ff_fsize;
  1811.         f1 = findnext(&ff);
  1812.       }
  1813.     }
  1814.   } else {
  1815.     output("\n");
  1816.     set_net_num(netnum);
  1817.     strcpy(s, "NETWORK0.EXE");
  1818.     for (i = 1; i < argc; i++) {
  1819.       strcat(s, " ");
  1820.       strcat(s, argv[i]);
  1821.     }
  1822.     s[strlen(s) + 1] = '\0';
  1823.     do_it(s);
  1824.     exit(EXIT_SUCCESS);
  1825.   }
  1826.  
  1827.   unload_klos();
  1828.  
  1829.   newstime = clock() - starttime;
  1830.   output("\n ■ Updating network connection records...");
  1831.   if (ONECALL) {
  1832.     recdbytes = ((recdbytes + 1023) / 1024);
  1833.     sentbytes = ((sentbytes + 1023) / 1024);
  1834.     if (mailtime)
  1835.       sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1836.     else
  1837.       strcpy(ttotal, "0.1");
  1838.     if (update_contacts(sy, sentbytes, recdbytes))
  1839.       output("\n ■ Unable to access CONTACT.NET!");
  1840.     if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1841.       output("\n ■ Unable to access NET.LOG!");
  1842.     if (newstime)
  1843.       sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1844.     else
  1845.       strcpy(ttotal, "0.1");
  1846.     rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1847.     snewsbytes = ((snewsbytes + 1023) / 1024);
  1848.     if (update_contact(32767, snewsbytes, rnewsbytes))
  1849.       output("\n ■ Unable to access CONTACT.NET!");
  1850.     if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1851.       output("\n ■ Unable to access NET.LOG!");
  1852.   } else {
  1853.     if (news) {
  1854.       if (newstime)
  1855.         sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
  1856.       else
  1857.         strcpy(ttotal, "0.1");
  1858.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1859.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1860.       if (update_contact(32767, snewsbytes, rnewsbytes))
  1861.         output("\n ■ Unable to access CONTACT.NET!");
  1862.       if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1863.         output("\n ■ Unable to access NET.LOG!");
  1864.     } else {
  1865.       recdbytes = ((recdbytes + 1023) / 1024);
  1866.       sentbytes = ((sentbytes + 1023) / 1024);
  1867.       if (mailtime)
  1868.         sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
  1869.       else
  1870.         strcpy(ttotal, "0.1");
  1871.       if (update_contacts(sy, sentbytes, recdbytes))
  1872.         output("\n ■ Unable to access CONTACT.NET!");
  1873.       if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1874.         output("\n ■ Unable to access NET.LOG!");
  1875.     }
  1876.   }
  1877.   cd_to(maindir);
  1878.   set_net_num(netnum);
  1879.   output("\n ■ %s completed!\n\n", version);
  1880.   return 0;
  1881. }
  1882.