home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / dnet / dnet2.3.2 / amiga / lib / dopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.6 KB  |  71 lines

  1.  
  2. /*
  3.  *  DOpen.C
  4.  */
  5.  
  6. #include "lib.h"
  7.  
  8. PORT *
  9. DOpen(host, portnum, txpri, rxpri)
  10. char *host;
  11. int txpri, rxpri;
  12. uword portnum;
  13. {
  14.     IOSTD ior;
  15.     CHANN *chan;
  16.  
  17.     if (rxpri > 126)
  18.     rxpri = 126;
  19.     if (rxpri < -127)
  20.     rxpri = -127;
  21.     if (txpri > 126)
  22.     txpri = 126;
  23.     if (txpri < -127)
  24.     txpri = -127;
  25.     if (host == NULL)
  26.     host = "0";
  27.  
  28.     /* not sure this is necessary, safe, or even useful, but... */
  29.     ior.io_Unit =  (struct Unit *)((ulong)portnum); 
  30.     /* sets channel's io_Unit in MakeCannel */
  31.  
  32.     chan = (CHANN *)MakeChannel(&ior, host);  
  33.     /* create the channel for the DNet communications */
  34.  
  35.     /* 
  36.     ** connect up to the DNet 'server', tell it to open a connection
  37.     ** to the other end 'server' 
  38.     */
  39.  
  40.     if ( chan && chan->dnetport) {
  41.     ior.io_Command = DNCMD_OPEN;      /* we're opening a connection */
  42.     ior.io_Unit = (struct Unit *)((ulong)portnum);  /* on this port */
  43.     ior.io_Offset = (ulong)chan;     /* talk to this channel? */
  44.     ior.io_Message.mn_ReplyPort = (PORT *)chan;  
  45.                     /* send replies to this channel */
  46.     /* set priorities */
  47.     ior.io_Message.mn_Node.ln_Pri = txpri;
  48.     ior.io_Message.mn_Node.ln_Name= (char *)rxpri;
  49.  
  50.     /* send the message to the local DNet server's port */
  51.     PutMsg(chan->dnetport, (MSG *)&ior);
  52.  
  53.     /* wait for its reply */
  54.     WaitMsg(&ior);
  55.  
  56.     if (ior.io_Error == 0) {
  57.         chan->chan = (ulong)ior.io_Unit;
  58.         FixSignal(chan);
  59.         return((PORT *)chan);
  60.     }
  61.     } else {
  62.        if(chan)  /* chan->dnetport == NULL */ 
  63.                printf("DNetport for host \"%s\" not found!\n");
  64.        IFDEBUG( printf("ACK! MakeChannel() failed!\n"); sleep(1);)
  65.     }
  66.  
  67.     DeleteChannel(chan);
  68.     return(NULL);
  69. }
  70.  
  71.