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