home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit5a190 / ckvioc.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  3KB  |  109 lines

  1. /*
  2.   NOTE: DEC C on OpenVMS AXP does not like an empty header file,
  3.   so we include the following header file unconditionally.
  4. */
  5. #include "ckcdeb.h"            /* Kermit universals */
  6.  
  7. #ifdef DEC_TCPIP
  8. #ifdef VMS
  9. /*
  10.   ioctl() similation for DEC TCP/IP, based on DEC example.
  11.   Used only for DEC TCP/IP (nee UCX).
  12. */
  13. #include "ckvioc.h"            /* IOCTL-specific definitions */
  14.  
  15. #define ISOK(s) (s & 01)        /* For checking $QIOW return value */
  16. /*
  17.   Select proper library function for getting socket device channel.
  18. */
  19. #if defined (__DECC)
  20. # define GET_SDC decc$get_sdc
  21. #elif (defined (VAXC) || defined (__VAXC) || defined(__GNUC__))
  22. # define GET_SDC vaxc$get_sdc
  23. #else
  24. # error unknown compiler, not DECC and not VAXC
  25. #endif /* __DECC */
  26.  
  27. int
  28. ioctl(d, request, argp) int d, request; char *argp; {
  29.  
  30.     int eflagnum;            /* Event Flag Number */
  31.     int sdc;                /* Socket Device Channel */
  32.     int status;                /* QIOW return code */
  33.     unsigned short fn;            /* QIOW function code  */
  34.     unsigned short iosb[4];        /* IO Status Block */
  35.     char *p5, *p6;            /* Arguments p5 and p6 of QIOW */
  36.  
  37.     struct comm {
  38.     int command;
  39.     char *addr;
  40.     } ioctl_comm;            /* QIOW ioctl commands. */
  41.  
  42.     struct it2 {
  43.     unsigned short len;
  44.     unsigned short opt;
  45.     struct comm *addr;
  46.     } ioctl_desc;            /* QIOW IOCTL commands descriptor */
  47.  
  48. #ifdef CK_GETEFN
  49. /*
  50.   It should not be necessary to ask the system for an EFN because:
  51.  
  52.     (a) the $QIOW will do a $SYNC
  53.     (b) there is an explicit IOSB (needed for correct multiprocessor operation)
  54.     (c) we are not threaded
  55.     (d) both the $QIOW return status and the IOSB status are checked
  56. */
  57.     status = LIB$GET_EF(&eflagnum);    /* Get an event flag number. */
  58.     if (!ISOK(status))            /* Did we? */
  59.       eflagnum = 0;            /* No event flag available, use 0. */
  60. #else
  61.     eflagnum = 0;            /* Use event flag number 0 */
  62. #endif /* CK_GETEFN */
  63.  
  64.     sdc = GET_SDC(d);            /* Get socket device channel number. */
  65.     if (sdc == 0) {
  66.     errno = EBADF;            /* Not an open socket descriptor. */
  67.     return -1;
  68.     }
  69.     ioctl_desc.opt = UCX$C_IOCTL;    /*  Fill in ioctl descriptor. */
  70.     ioctl_desc.len = sizeof(struct comm);
  71.     ioctl_desc.addr = &ioctl_comm;
  72.  
  73. /* Decide QIOW function code and In / Out parameter. */
  74.  
  75.     if (request & IOC_OUT) {
  76.     fn = IO$_SENSEMODE;
  77.     p5 = 0;
  78.     (struct it2 *)p6 = &ioctl_desc;
  79.     } else {
  80.     fn = IO$_SETMODE;
  81.     (struct it2 *)p5 = &ioctl_desc;
  82.     p6 = 0;
  83.     }
  84.     ioctl_comm.command = request;
  85.     ioctl_comm.addr = argp;
  86.     status = SYS$QIOW(eflagnum, sdc, fn, iosb, 0, 0, 0, 0, 0, 0, p5, p6);
  87.     if (!ISOK(status)) {
  88.     debug(F101,"ioctl failed: status","",status);
  89.     errno = status;
  90.     return -1;
  91.     }
  92.     if (!ISOK(iosb[0])) {
  93. #ifdef DEBUG
  94.     char tmpbuf[80];
  95.     sprintf(tmpbuf,"ioctl failed: status = %x, %x, %x%x\n",
  96.         iosb[0], iosb[1], iosb[3], iosb[2]);
  97.     debug(F100,(char *)tmpbuf,"",0);
  98. #endif /* DEBUG */
  99.     errno = (long int) iosb[0];
  100.     return -1;
  101.     }
  102. #ifdef CK_GETEFN
  103.     status = LIB$FREE_EF(&eflagnum);
  104. #endif /* CK_GETEFN */
  105.     return 0;
  106. }
  107. #endif /* VMS */
  108. #endif /* DEC_TCPIP */
  109.