[comp.windows.x] DECnet support for SunOS in Xlib

db@sunbim.be (Danny Backx) (10/18/90)

I managed to add DECnet support for Sun's (Sunlink DNI) to Xlib.

Here's what I sent to xbugs :

			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu


VERSION:
    R4

CLIENT MACHINE and OPERATING SYSTEM:
    Sun (All)

DISPLAY TYPE:
    All

WINDOW MANAGER:
    All

AREA:
    Xlib

SYNOPSIS:
    There is no support for X over DECnet for Sun's. This used to be impossible
    due to Sunlink DNI bugs. I have a working version now...

DESCRIPTION:
    You need Sunlink DNI 6.0 + the 'DNI 6.0 Jumbo Patch'.
    (Patch ID 100107-01, dated 17-Aug-90).

    I came up with a hacked up version of XConnDis.c and Xlibos.h.
    There are two problems with the implementation :
	1. There seems to be no way to find out how many bytes are ready for
	   being read on a DNI socket. So I used select with a randomly chosen
	   timeout, and told the rest of Xlib that there was one packet of data
	   ready to be read.

	2. The Sunlink DNI implementation is non-standard about setting
	   non-blocking I/O. So I had to remove the original syscall, and
	   insert the appropriate one.

    Due to the wonders of shared libraries, this does allow you to use any
    program that uses a shared Xlib with the DECnet protocols...

SAMPLE FIX:

*** XConnDis.c.orig	Thu Oct 18 11:02:37 1990
--- XConnDis.c	Thu Oct 18 13:10:31 1990
***************
*** 1,3 ****
--- 1,4 ----
+ #define NEED_REPLIES
  /*
   * $XConsortium: XConnDis.c,v 11.65 89/12/09 19:10:20 rws Exp $
   *
***************
*** 33,40 ****
  #include <X11/Xauth.h>
  #include <ctype.h>
  #ifdef DNETCONN
! #include <netdnet/dn.h>
! #include <netdnet/dnetdb.h>
  #endif
  
  #ifndef X_CONNECTION_RETRIES		/* number retries on ECONNREFUSED */
--- 34,45 ----
  #include <X11/Xauth.h>
  #include <ctype.h>
  #ifdef DNETCONN
! # ifndef sun
! #  include <netdnet/dn.h>
! #  include <netdnet/dnetdb.h>
! # else /* SUN */
! #  include <netdni/dni.h>
! # endif
  #endif
  
  #ifndef X_CONNECTION_RETRIES		/* number retries on ECONNREFUSED */
***************
*** 278,283 ****
--- 283,291 ----
  	ioctl (fd, FIOSNBIO, &arg);
      }
  #else
+ #if defined(DNETCONN) && defined(sun)
+     if (! dnet)
+ #endif
  	(void) fcntl (fd, F_SETFL, FNDELAY);
  #endif /* FIOSNBIO */
  
***************
*** 360,365 ****
--- 368,374 ----
  
  
  #ifdef DNETCONN
+ #ifndef sun
  static int MakeDECnetConnection (phostname, idisplay, retries,
  				 familyp, saddrlenp, saddrp)
      char *phostname;
***************
*** 411,416 ****
--- 420,489 ----
      bcopy ((char *)&dnaddr, *saddrp, *saddrlenp);
      return fd;
  }
+ #else /* SUN */
+ /*
+ ** This is an attempt to make Xlib work with SunLink DNI 6.0 (+Jumbo patch)
+ **
+ ** Danny Backx, BIM, 17/10/1990
+ */
+ static int MakeDECnetConnection (phostname, idisplay, retries,
+ 				 familyp, saddrlenp, saddrp)
+     char *phostname;
+     int idisplay;
+     int retries;
+     int *familyp;			/* RETURN */
+     int *saddrlenp;			/* RETURN */
+     char **saddrp;			/* RETURN */
+ {
+     int			fd;
+     char		objname[20];
+     OpenBlock		opblk;
+     struct ses_io_type	sesopts;
+ 
+     if (!phostname) phostname = "0";
+ 
+     /*
+      * build the target object name.
+      */
+     sprintf (objname, "X$X%d", idisplay);
+ 
+     /*
+      * Attempt to open the DECnet connection, return -1 if fails; ought to
+      * do some retries here....
+      */
+     if ((fd = open("/dev/dni", O_RDWR)) < 0)
+ 	return -1;
+     if (ioctl(fd, SES_GET_LINK, 0) < 0) {
+ 	close(fd);
+ 	return -1;
+     }
+ 
+     *familyp = FamilyDECnet;
+     strcpy(opblk.op_node_name, phostname);
+     strcpy(opblk.op_task_name, objname);
+     opblk.op_userid[0] = '\0';
+     opblk.op_object_nbr = 0;
+     opblk.op_account[0] = '\0';
+     opblk.op_password[0] = '\0';
+     opblk.op_opt_data.im_length = 0;
+ 
+     if (ioctl(fd, SES_LINK_ACCESS, &opblk)) {
+ 	close(fd);
+ 	return -1;
+     }
+ 
+     *saddrlenp = 4;
+     *saddrp = phostname;
+ 
+ /* This may not belong here... */
+     sesopts.io_flags = SES_IO_NBIO;
+     if (ioctl(fd, SES_IO_TYPE,  &sesopts)) {
+ 	close(fd);
+ 	return -1;
+     }
+     return fd;
+ }
+ #endif /* SUN */
  #endif /* DNETCONN */
  
  
***************
*** 795,797 ****
--- 868,893 ----
      (void) WritevToServer (dpy->fd, iovarray, niov);
      return;
  }
+ 
+ #if defined(DNETCONN) && defined(sun)
+ 
+ int _dni_bytes_readable(fd, ptr)
+ 	int	fd, *ptr;
+ {
+ 	fd_set	rfs;
+ 	int	r;
+ 	struct timeval	to;
+ 
+ 	FD_ZERO(&rfs);
+ 	FD_SET(fd, &rfs);
+ 	to.tv_sec = 0;
+ 	to.tv_usec = 100;	/* Arbitrary, but not too long (1/10 sec) */
+ 
+ 	if (select(32, &rfs, 0, 0, &to) > 0)
+ 		*ptr = sizeof(xReply);	/* Tell Xlib there is 1 packet */
+ 	else
+ 		*ptr = 0;
+ 
+ 	return 0;
+ }
+ #endif

*** Xlibos.h.orig	Thu Oct 18 12:52:02 1990
--- Xlibos.h	Wed Oct 17 16:27:50 1990
***************
*** 26,32 ****
  #include <sys/uio.h>	/* needed for XlibInt.c */
  #include <sys/param.h> /* needed for XConnDis.c */
  
! #define BytesReadable(fd, ptr) ioctl ((fd), FIONREAD, (ptr))
  #define MSKCNT ((NOFILE + 31) / 32)	/* size of bit array */
  #endif /* att else bsdish */
  
--- 26,36 ----
  #include <sys/uio.h>	/* needed for XlibInt.c */
  #include <sys/param.h> /* needed for XConnDis.c */
  
! #if defined(DNETCONN) && defined(sun)
! # define BytesReadable(fd, ptr) _dni_bytes_readable((fd), (ptr))
! #else
! # define BytesReadable(fd, ptr) ioctl ((fd), FIONREAD, (ptr))
! #endif
  #define MSKCNT ((NOFILE + 31) / 32)	/* size of bit array */
  #endif /* att else bsdish */


  
	Danny Backx
	BIM Networks System Engineer

E-Mail: db@sunbim.be    (or uunet!mcsun!ub4b!sunbim!db)

Telephone: +32(2)759.59.25	Fax : +32(2)759.47.95

Postal Mail :
	Danny Backx
	BIM
	Kwikstraat 4
	3078 Everberg
	Belgium