| /*
* DESCRIPTION
*
* This program illustrates how an VMS system can be used as a
* PIPE to swap transports for an application protocol. A brief
* description of how the program is used is given below.
*
* USAGE
*
* gatewayd -inet desthost destservice
* gatewayd -dnet destnode destobject
*
* If the connection couldn't complete to the destsystem/destentity,
* the connection to the client is simply disconnected.
*
*/
#include <stdio.h>
#include <descrip.h>
#include <iodef.h>
#include <stsdef.h>
#include <ssdef.h>
struct io_stat_blk {
short int status ;
short int msg_len ;
int unused;
};
struct io_stat_blk ciosb;
struct io_stat_blk siosb;
struct io_stat_blk iosb;
#define STREQL(a, b) (strcmp(a, b) == 0)
#define NIL (0)
char DestProto[40]; /* Protocol family to connect by */
char DestHost[256]; /* Remote system to connect to */
char DestObj[256]; /* Remote object/service to connect to */
static int client_read();
static int server_read();
unsigned short client; /* Socket connected to client */
unsigned short server; /* Socket connected to client */
#define BUFSIZ 256
unsigned char client_read_buffer[BUFSIZ];
unsigned char client_write_buffer[BUFSIZ];
unsigned char server_read_buffer[BUFSIZ];
unsigned char server_write_buffer[BUFSIZ];
main(argc, argv)
int argc; /* # of command line arguments */
char *argv[]; /* the command line arguments */
{
int status;
char *t;
char task_list[BUFSIZ];
int i;
$DESCRIPTOR(sys_net,"SYS$NET");
struct dsc$descriptor_s task_desc =
{0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
printf("pipe\n");
/* t = getenv("SYS$NET");
for (i=0;i<80;i++)
printf("%c",t[i]);
*/
/* Check usage */
if(argc != 4){
printf("invalid number of parameters\n");
exit(0);
}
printf("ASSIGN CHANNEL\n");
status = sys$assign(&sys_net,&client,0,0);
if ((status != SS$_NORMAL ) && (status != SS$_REMOTE)) {
printf("unable to connect to SYS$NET %d\n",status);
exit(0);
}
/* Fetch connect info from command line */
strcpy(DestProto, argv[1]);
strcpy(DestHost, argv[2]);
strcpy(DestObj, argv[3]);
/* Time to attempt the connection */
if( STREQL(DestProto, "dnet") ) {
sprintf(task_list,"%s::\"task=%s\"",DestHost,DestObj);
task_desc.dsc$w_length = strlen(task_list);
task_desc.dsc$a_pointer = task_list;
status = sys$assign(&task_desc,&server,0,0);
if ((status != SS$_NORMAL ) && (status != SS$_REMOTE)) {
printf("unable to connect to %s\n",task_list);
close_link();
exit(0);
}
}
else {
printf("Error; Request to connect via an unknown protocol\n");
/* Some spawners (ie. DECnet) log children's exit codes */
close_link();
exit();
}
/* Now just go and move raw data between client and
remote system */
dowork();
/* ... NEVER RETURNS ... */
}
dowork()
{
int status;
printf("issuing read to client\n");
status = sys$qio ( 0,
client,
IO$_READVBLK,
&ciosb,
client_read, 0,
client_read_buffer,
sizeof(client_read_buffer),
0, 0, 0, 0 );
if ( status & STS$M_SUCCESS )
status = ciosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
printf("status=%d\n",status);
close_link();
exit(0);
}
printf("issue read to server\n");
status = sys$qio ( 0,
server,
IO$_READVBLK,
&siosb,
server_read, 0,
server_read_buffer,
sizeof(server_read_buffer),
0, 0, 0, 0 );
if ( status & STS$M_SUCCESS )
status = siosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
close_link();
exit(0);
}
printf("going to sleep now\n");
while (1){
status = sys$hiber();
printf("awake\n");
}
printf("awake\n");
}
int client_read()
{
int status;
/* DISABLE_AST;*/
printf("start client read\n");
printf("ciosb.msg_len=%d\n",ciosb.msg_len);
lib$movc3(&ciosb.msg_len,client_read_buffer,server_write_buffer);
status = sys$qiow ( 0,
server,
IO$_WRITEVBLK,
&iosb,
0, 0,
server_write_buffer,
ciosb.msg_len,
0, 0, 0, 0 );
printf("after qio \n");
if ( status & STS$M_SUCCESS )
status = iosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
printf("status=%d\n",status);
close_link();
exit(0);
}
printf("reissue read on client line \n");
status = sys$qio ( 0,
client,
IO$_READVBLK,
&ciosb,
client_read, 0,
client_read_buffer,
BUFSIZ,
0, 0, 0, 0 );
if ( status & STS$M_SUCCESS )
status = ciosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
printf("status=%d\n",status);
close_link();
exit(0);
}
printf("finish client read \n");
}
int server_read()
{
int status;
printf("begin server read\n");
printf("siosb.msg_len=%d\n",siosb.msg_len);
lib$movc3(&siosb.msg_len,server_read_buffer,client_write_buffer);
status = sys$qiow ( 0,
client,
IO$_WRITEVBLK,
&iosb,
0, 0,
client_write_buffer,
siosb.msg_len,
0, 0, 0, 0 );
if ( status & STS$M_SUCCESS )
status = iosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
close_link();
exit(0);
}
status = sys$qio ( 0,
server,
IO$_READVBLK,
&siosb,
server_read, 0,
server_read_buffer,
BUFSIZ,
0, 0, 0, 0 );
if ( status & STS$M_SUCCESS )
status = siosb.status;
if ((status != SS$_NORMAL) && (status != 0)){
close_link();
exit(0);
}
printf("server_read complete\n");
}
int close_link()
{
int status;
printf("close link\n");
status = sys$dassgn(server);
status = sys$dassgn(client);
return;
}
|