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