File: ckvioc.c

package info (click to toggle)
ckermit 193-3
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 6,180 kB
  • ctags: 8,803
  • sloc: ansic: 118,504; makefile: 2,474; sh: 52
file content (120 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
  NOTE: DEC C on OpenVMS AXP does not like an empty header file,
  so we include the following header file unconditionally.
*/
#include "ckcdeb.h"			/* Kermit universals */

#ifdef DEC_TCPIP
#ifdef VMS
/*
  ioctl() similation for DEC TCP/IP, based on DEC example.
  Used only for DEC TCP/IP (nee UCX).
*/
#include "ckvioc.h"			/* IOCTL-specific definitions */

#define ISOK(s) (s & 01)		/* For checking $QIOW return value */
/*
  Select proper library function for getting socket device channel.
*/
#if defined (__DECC)
# define GET_SDC decc$get_sdc
#elif (defined (VAXC) || defined (__VAXC) || defined(__GNUC__))
# define GET_SDC vaxc$get_sdc
#else
# error unknown compiler, not DECC and not VAXC
#endif /* __DECC */

#ifdef __DECC
#include <starlet.h>
#include <lib$routines.h>
#include <socket.h>
#endif /* __DECC */

int
ioctl(d, request, argp)
    int d, request;
#ifdef __DECC
    void
#else
    char
#endif /* __DECC */
    *argp;
{

    int eflagnum;			/* Event Flag Number */
    int sdc;				/* Socket Device Channel */
    int status;				/* QIOW return code */
    unsigned short fn;			/* QIOW function code  */
    unsigned short iosb[4];		/* IO Status Block */

    struct comm {
	int command;
	char *addr;
    } ioctl_comm;			/* QIOW ioctl commands. */

    struct it2 {
	unsigned short len;
	unsigned short opt;
	struct comm *addr;
    } ioctl_desc;			/* QIOW IOCTL commands descriptor */

#ifdef CK_GETEFN
/*
  It should not be necessary to ask the system for an EFN because:

    (a) the $QIOW will do a $SYNC
    (b) there is an explicit IOSB (needed for correct multiprocessor operation)
    (c) we are not threaded
    (d) both the $QIOW return status and the IOSB status are checked
*/
    status = lib$get_ef(&eflagnum);	/* Get an event flag number. */
    if (!ISOK(status))			/* Did we? */
      eflagnum = 0;			/* No event flag available, use 0. */
#else
    eflagnum = 0;			/* Use event flag number 0 */
#endif /* CK_GETEFN */

    sdc = GET_SDC(d);			/* Get socket device channel number. */
    if (sdc == 0) {
	errno = EBADF;			/* Not an open socket descriptor. */
	return -1;
    }
    ioctl_desc.opt = UCX$C_IOCTL;	/*  Fill in ioctl descriptor. */
    ioctl_desc.len = sizeof(struct comm);
    ioctl_desc.addr = &ioctl_comm;

/* Decide QIOW function code and In / Out parameter. */

    ioctl_comm.command = request;
    ioctl_comm.addr = argp;
    if (request & IOC_OUT) {
	fn = IO$_SENSEMODE;
	status = sys$qiow(eflagnum,
			  sdc, fn, iosb, 0, 0, 0, 0, 0, 0, 0, &ioctl_desc);
    } else {
	fn = IO$_SETMODE;
	status = sys$qiow(eflagnum,
			  sdc, fn, iosb, 0, 0, 0, 0, 0, 0, &ioctl_desc, 0);
    }
    if (!ISOK(status)) {
	debug(F101,"ioctl failed: status","",status);
	errno = status;
	return -1;
    }
    if (!ISOK(iosb[0])) {
#ifdef DEBUG
	char tmpbuf[80];
	sprintf(tmpbuf,"ioctl failed: status = %x, %x, %x%x\n",
		iosb[0], iosb[1], iosb[3], iosb[2]);
	debug(F100,(char *)tmpbuf,"",0);
#endif /* DEBUG */
	errno = (long int) iosb[0];
	return -1;
    }
#ifdef CK_GETEFN
    status = lib$free_ef(&eflagnum);
#endif /* CK_GETEFN */
    return 0;
}
#endif /* VMS */
#endif /* DEC_TCPIP */