This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_vms.c
193 lines (170 loc) · 4.33 KB
/
c_vms.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*************************************************************************
** c_c]vms.c Beta v2.0 (22 Aug 1988)
**
** This file is part of Internet Relay Chat v2.0
**
** Author: Jarkko Oikarinen
** Internet: [email protected]
** UUCP: ...!mcvax!tut!oulu!jto
** BITNET: toljto at finou
**
** Copyright (c) 1988 University of Oulu, Computing Center
**
** All rights reserved.
**
** See file COPYRIGHT in this package for full copyright.
**
*************************************************************************/
char c_vms_id[] = "c_vms.c v2.0 (c) 1988 University of Oulu, Computing Center";
#include "struct.h"
#if HPUX
#include <time.h>
#else
#if VMS
#include <sys/time.h>
#include iodef
#include ssdef
#include descrip
typedef struct {
short cond_value;
short count;
int info;
} io_statblk;
#else
#include <sys/time.h>
#endif
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <signal.h>
#include <file.h>
#include <curses.h>
#if BSD42 || ULTRIX || HPUX
#include "sock.h"
#endif
#include "sys.h"
#define STDINBUFSIZE (0x80)
extern aClient me;
int goodbye;
int
client_init(host, portnum)
char *host;
int portnum;
{
int sock, tryagain = 1;
static struct hostent *hp;
static struct sockaddr_in server;
gethostname(me.host,HOSTLEN);
/* FIX: [email protected] -- 3/4/89
and [email protected] -- 3/7/89 */
while (tryagain) {
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("opening stream socket");
exit(1);
}
server.sin_family = AF_INET;
/* MY FIX -- [email protected] (2/10/89) */
if ( isdigit(*host))
{
server.sin_addr.s_addr = inet_addr(host);
}
else
{
hp = gethostbyname(host);
if (hp == 0) {
fprintf(stderr, "%s: unknown host", host);
exit(2);
}
bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
}
server.sin_port = htons(portnum);
/* End Fix */
if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) {
if (!strcmp(host, me.host) && tryagain == 1) /* Is this MY host? */
{
/* if (fork() == 0) */ /* - server is SUID/SGID to ME so it's my UID */
{
/* execl(MYNAME, "ircd", (char *)0); */
printf("Sorry, I can't start a server up\n");
exit(1);
}
printf("Connection refused at your own host!\n");
printf("Rebooting IRCD Daemon and trying again....\n");
printf("Wait a moment...\n");
netclose(sock);
sleep(5);
tryagain = 2;
} else {
perror("irc");
exit(1);
}
} else
tryagain = 0;
}
return(sock);
}
/* End Fix */
client_loop(sock)
int sock;
{
int i = 0, size, pos, x;
char apubuf[STDINBUFSIZE+1], ch;
struct timeval timeout = { 0, 0 };
fd_set ready;
short chan;
int status;
io_statblk status_block;
struct {
long part1;
long part2;
} terminator = { 0, 0};
$DESCRIPTOR(terminal, "SYS$COMMAND");
if (((status = SYS$ASSIGN(&terminal, &chan, 0, 0)) & 1 ) != 1)
LIB$STOP(status);
goodbye = 0;
do {
for (x=0; x <= 64; x++) ready.fds_bits[x]=0;
ready.fds_bits[sock/32] |= 1 << (sock % 32);
move(LINES-1,i);
if (goodbye == 1) return(-1);
while (select(1, &ready, 0, 0, &timeout) > 0) {
if ((ready.fds_bits[sock/32] & (1 << (sock % 32))) != 0) {
if ((size = netread(sock, apubuf, STDINBUFSIZE)) < 0)
perror("receiving stream packet");
dopacket(&me, apubuf, size);
move(LINES-1, i);
refresh();
}
}
if (((status = SYS$QIOW(1, chan, IO$_READVBLK | IO$M_NOFILTR | IO$M_NOECHO
| IO$M_TIMED, &status_block, 0, 0, &apubuf, 1, 1, &terminator, 0, 0))
& 1 ) != 1)
LIB$STOP(status);
/*
if (((status = SYS$SYNCH( 1, &status_block)) & 1) != 1)
LIB$STOP(status);
*/
if ((status_block.cond_value != SS$_TIMEOUT) &&
(status_block.cond_value != SS$_NORMAL))
LIB$STOP(status);
if (status_block.count > 0 ) {
i=do_char(apubuf[0]);
move(LINES-1, i);
}
/*
apubuf[status_block.count] = '\0';
if (status_block.count > 0 )
for (pos = 0; pos < status_block.count; pos++) {
if (apubuf[pos] == '\r') apubuf[pos] = '\n';
i=do_char(apubuf[pos]);
move(LINES-1, i);
}
*/
} while (1);
}