home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / c-niftp.zip / unix-niftp-5.6 / lib / x25b / netopen.c < prev    next >
C/C++ Source or Header  |  1991-06-07  |  5KB  |  179 lines

  1. #ifndef    lint            /* unix-niftp lib/x25b/netopen.c */
  2. static char RCSid[]="$Header: /Nfs/heaton/glob/src/usr.lib/niftp/unix-niftp-5.6/lib/x25b/netopen.c,v 5.6 1991/06/07 17:02:25 pb Exp $";
  3. #endif    lint
  4.  
  5. /*
  6.  * file
  7.  *             netopen.c
  8.  *
  9.  * Piete Brooks <pb@cl.cam.ac.uk>
  10.  *
  11.  * $Log: netopen.c,v $
  12.  * Revision 5.6  1991/06/07  17:02:25  pb
  13.  * Distribution of Oct90deslib+PPaids: Include des/lib/ and a few aids for PP sites
  14.  *
  15.  * Revision 5.5  90/08/01  13:39:19  pb
  16.  * Distribution of Aug90RealPP+sequent: Full PP release and support for Sequent X.25 board
  17.  * 
  18.  * Revision 5.3  89/07/16  12:03:57  pb
  19.  * Distribution of Jul89PPsupport: Support PP spooled P and Q and unspooled Q
  20.  * 
  21.  * Revision 5.1  88/10/07  17:21:40  pb
  22.  * Distribution of Oct88MultipleP: Support multiple P processes + window/pkt sizes + YBTS + banned
  23.  * 
  24.  * Revision 5.0.1.6  88/02/11  06:35:29  pb
  25.  * Distribution of Jan88ReleaseMod2: More documentation + x25b + sendmail fixes + sun fixes
  26.  * 
  27.  * Revision 5.0.1.4  88/01/28  06:35:15  pb
  28.  * Distribution of Jan88Release: Sun fixes plus adding x25b code
  29.  * 
  30.  * Revision 5.0  88/01/28  06:23:32  pb
  31.  * Distribution of Jan88Release: Sun fixes plus adding x25b code
  32.  * 
  33.  * 
  34.  * This file contains routines to interface to the x25bridge libraries.
  35.  * They make the network seem like a normal file. Makes the interface nicer
  36.  */
  37.  
  38. #include "x25b.h"
  39. #include "nrs.h"
  40. #include "ftp.h"
  41. #include "infusr.h"
  42. #include <stdio.h>
  43. #include <errno.h>
  44. #include <sys/ioctl.h>
  45.  
  46. #define    MAXFS_BYTES    16
  47. #define    CONNECT    0x10
  48. #define    ACCEPT    0x11
  49.  
  50. extern fid;
  51. extern    def_pktsize;
  52. extern    def_wndsize;
  53. char *index();
  54.  
  55. char ybts_hdr[] = { 0x7f, 0xff, 0xff, 0xff };
  56.  
  57. extern    Nopts;    /* Network options */
  58. extern    Npkt_size;
  59. extern    Nwnd_size;
  60.  
  61. con_open(str)
  62. char    *str;
  63. {
  64.     register nodep nptr = &net_io;
  65.     struct facilities facil;
  66.     register i;
  67.     int    s;
  68.     char    fromdte[ENOUGH];
  69.     char    dte[ENOUGH];
  70.     char    *ybts;
  71.     char    *calling;
  72.     char    *ybtsp;
  73.     char    *port;
  74.     char    *top[2];
  75.  
  76.     facil.x4_fflags = 0;
  77.  
  78.     if(net_open) L_WARN_0(L_10, 0, "con_open called with net_open\n");
  79.  
  80.     top[0] = fromdte;
  81.     top[1] = t_addr;
  82.     if(i=adr_trans(str, network, top) ){
  83.         /* translate to get network too */
  84.         L_WARN_1(L_GENERAL, 0, "Address trans error %d\n",i);
  85.         return(-1);
  86.     }
  87.  
  88.     L_LOG_2(L_FULL_ADDR, 0, "Full address:- %s (from %s)\n",
  89.         hide_pss_pw(t_addr), fromdte);
  90.  
  91.     strcpy(dte, t_addr);
  92.     if (ybts = index(dte, '/')) *ybts++ = '\0';
  93.     if (calling = index(fromdte, '/')) *calling++ = '\0';
  94.     else    calling="<unknown>";
  95.  
  96.     if (port=index(fromdte, ';')) *port++ = '\0';
  97.  
  98. #ifdef    __STDC__
  99. #define    set(x, y, z) { facil.x4_ ## x = z; facil.x4_fflags |= htons(FACIL_F_ ## y); }
  100. #else    /* __STDC__ */
  101. #define    set(x, y, z) { facil.x4_/**/x = z; facil.x4_fflags |= htons(FACIL_F_/**/y); }
  102. #endif    /* __STDC__ */
  103. #define htobcd(x) ((x == 100) ? 0 : ( ((x / 10) << 4) | (x % 10)))
  104.  
  105.     if (tab.t_flags & REVERSE_CHARGING)
  106.               set(reverse_charge,REVERSE_CHARGE, 1);
  107.     if (trans_revc)      set(reverse_charge,REVERSE_CHARGE, 1);
  108.  
  109.     if (def_pktsize)  set(recvpktsize,RECVPKTSIZE, htons(def_pktsize));
  110.     if (def_pktsize)  set(sendpktsize,RECVPKTSIZE, htons(def_pktsize));
  111.     if (Npkt_size)    set(recvpktsize,RECVPKTSIZE, htons(Npkt_size));
  112.     if (Npkt_size)    set(sendpktsize,RECVPKTSIZE, htons(Npkt_size));
  113.     if (trans_pkts)      set(recvpktsize,RECVPKTSIZE, htons(8 << trans_pkts));
  114.     if (trans_pkts)      set(sendpktsize,RECVPKTSIZE, htons(8 << trans_pkts));
  115.  
  116.     if (def_wndsize)  set(recvwndsize,RECVWNDSIZE, def_wndsize);
  117.     if (def_wndsize)  set(sendwndsize,RECVWNDSIZE, def_wndsize);
  118.     if (trans_wind)      set(recvwndsize,RECVWNDSIZE, trans_wind);
  119.     if (trans_wind)      set(sendwndsize,RECVWNDSIZE, trans_wind);
  120.  
  121. /*-    if (thruput..)    set(recvthruput, , ??); -*/
  122. /*-    if (thruput..)    set(sendthruput, , ??); -*/
  123.     if (trans_cug)    set(cug_index,CUG_INDEX, htobcd(trans_cug));
  124.     if (Nopts & N_NFCS)
  125.             set(fast_select,FAST_SELECT, FACIL_NO)
  126.     else if (Nopts & N_FCS)
  127.             set(fast_select,FAST_SELECT, FACIL_YES)
  128.     else        set(fast_select,FAST_SELECT, FACIL_YES)
  129. /*-    if (rpoa ...)    facil.rpoa_req=1, facil.rpoa, , ??; -*/
  130.  
  131.     _x25b_print_facil(&facil);
  132.  
  133.     nptr->read_count = 0;
  134.     starttimer(2*60);        /* start the timeout system */
  135.     alarm(2*60);        /* TEMP HACK til start timer is fixed */
  136.  
  137.     fid = x25b_open_ybts(dte, ybts, calling, fromdte, port, &facil, 0);
  138.  
  139.     suck_userdata();
  140.     /* Now await the accept */
  141.     {    char    temp[256];
  142.         int    nbytes;
  143.         int i;
  144.  
  145.         nbytes = x25b_read_data(fid, temp, temp+1, sizeof(temp)-1);
  146.         L_DEBUG_2(L_LOG_OPEN, 0, "Accept: %d: %02x: ", nbytes, temp[0] & 0xff);
  147.         for(i=1; i<= nbytes;i++)
  148.             L_DEBUG_1(L_LOG_OPEN, L_CONTINUE, "%02x", temp[i] & 0xff);
  149.         L_DEBUG_0(L_LOG_OPEN, L_CONTINUE, "\n");
  150.         if(nbytes < 1) 
  151.         {    L_WARN_2(L_GENERAL, 0, "recv acc failed %d (%d)\n",
  152.                     nbytes, errno);
  153.             return (-1);
  154.         }
  155.         nbytes++;
  156.         if (temp[1] != ACCEPT /*|| !(temp[0] & (1<<Q_BIT))*/)
  157.         {
  158.             L_WARN_3(L_GENERAL, 0, "invalid ac %d: %02x %02x\n",
  159.                 nbytes, temp[0] & 0xff, temp[1] & 0xff);
  160.             if ((ftp_print & 0x7f) != 0x7f) return (-1);
  161.             L_LOG_0(L_GENERAL, 0, " +++ continuing anyway!\n");
  162.         }
  163.     }
  164.     /* WHEW !!!! */
  165.  
  166.     starttimer(11*60);        /* give it a chance now .... */
  167.     nptr->write_count = BLOCKSIZ;
  168.     nptr->read_buffer = net_read_buffer;
  169.     nptr->write_buffer = net_write_buffer;
  170.     net_open = 1;                   /* say we are open */
  171.     return(0);
  172. }
  173.  
  174. /* discard user data .... */
  175.  
  176. suck_userdata()
  177. {    
  178. }
  179.