
/*
 *  DOpen.C
 */

#include "lib.h"

PORT *
DOpen(host, portnum, txpri, rxpri)
char *host;
int txpri, rxpri;
uword portnum;
{
    IOSTD ior;
    CHANN *chan;

    if (!host)
	host = "0";
    chan = (CHANN *)MakeChannel(&ior, host);
    if (rxpri > 126)
	rxpri = 126;
    if (rxpri < -127)
	rxpri = -127;
    if (txpri > 126)
	txpri = 126;
    if (txpri < -127)
	txpri = -127;
    if (chan->dnetport) {
	ior.io_Command = DNCMD_OPEN;
	ior.io_Unit = (void *)portnum;
	ior.io_Offset = (long)chan;
	ior.io_Message.mn_ReplyPort = (PORT *)chan;
	ior.io_Message.mn_Node.ln_Pri = txpri;
	ior.io_Message.mn_Node.ln_Name= (char *)rxpri;

	PutMsg(chan->dnetport, (MSG *)&ior);
	WaitMsg(&ior);
	if (ior.io_Error == 0) {
	    chan->chan = (long)ior.io_Unit;
	    FixSignal(chan);
	    return((PORT *)chan);
	}
    }
    DeleteChannel(chan);
    return(NULL);
}

