/*---------------------------------------------------------------------+
| Copyright (c) 1995, SAS Institute Inc. |
| Unpublished - All Rights Reserved |
| S A S / C S A M P L E |
| |
| NAME: CICTSERV |
| LANGUAGE: C |
| PURPOSE: Demonstrate a CICS TCP/IP server, that is started by |
| CICLISTN. Refer to the SAS/C Library Reference Vol 2, |
| Third Edition, Release 6.00 for additional details on |
| socket API function calls. |
| MVS - |
| COMPILE, LINK: SUBMIT prefix.SAMPLE.AUX(CICTSERV) |
| where "prefix" is the installation defined high-level- |
| qualifier for the SAS/C product. |
| EXECUTE: Refer to the SAS/C CICS User's Guide, Second Edition, |
| Release 6.00 for details on defining and starting a |
| SAS/C application in CICS. |
| NOTES: CICTSERV assumes a working TCP/IP environment on both |
| the local and remote hosts. |
| TSO - |
| COMPILE: LCCCP/LC370 CLISTs |
| NOTES: RENT is a required LC370 "option" |
| LINK: CLK370 CLIST |
| EXECUTE: N/A |
| NOTES: CICTSERV assumes a working TCP/IP environment on both |
| the local and remote hosts. |
| CMS - You may Translate, Compile and CLINK SAS/C programs under |
| CMS, but the resulting object MUST be link-edited on MVS. |
| Refer to the SAS/C Compiler and Library User's Guide, |
| Fourth Edition, Release 6.00 for additional information. |
+---------------------------------------------------------------------*/
/* #define __IBM_TCPIP 1 is only required for releases prior to 6.00 */
#define __IBM_TCPIP 1
#include <cics.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
main()
{
int cs; /* cs is the client socket returned by takesocket */
int s; /* s is the socket passed by the listener */
/* Return struct for clientid information */
struct clientid clientid;
/* Variables used to obtain the time. */
char *p;
int len;
time_t t;
/* Loop count */
int n_times;
/* Buffer for outgoing time string. */
char outbuf[128];
/*
* Map of Parms passed to program by CICS listener via
* "EXEC CICS START" and picked up by "EXEC CICS RETRIEVE"
*/
struct TCPSOCKET_PARM
{ /* Map PARMS passed to program by CICS Listener */
int give_take_socket;
char lstn_name[8];
char lstn_subname[8];
char client_in_data[36];
struct sockaddr_in sockaddr_in_parm;
} csp; /* cics_socket_parm */
short csp_len = (short) sizeof(csp);
EXEC CICS RETRIEVE INTO(&csp) LENGTH(csp_len); /* Get parms */
/*
* Build required CICS format clientid for takesocket
*/
memset(&clientid, 0, sizeof(clientid)); /* zero out client id */
clientid.domain = AF_INET;
memcpy(clientid.name, csp.lstn_name, 8);
memcpy(clientid.subtaskname, csp.lstn_subname, 8);
printf("Passed clientid info: "
"Domain = %d, Name = <%.8s>, Task = <%.8s>\n",
clientid.domain, clientid.name, clientid.subtaskname);
/* Convert IBM socket number to SAS/C socket number base */
/* FD_TO_IBM_TCPIP is only required for releases prior to 6.00 */
s = FD_FROM_IBM_TCPIP(csp.give_take_socket);
/* Take the passed client socket; takesocket will return a local */
/* socket number enabling us to write to the client */
cs = takesocket(&clientid, s);
/* Check takesocket rc */
if (cs == -1)
{
perror("takesock() call failed");
exit(EXIT_FAILURE);
}
n_times = 2;
while (n_times--)
{
/* Send the time to the client. clients */
/* expect the string to be in ASCII. */
time(&t); /* Machine readable time. */
p = ctime(&t); /* Human readable time. */
/* Convert to ASCII if necessary. */
for (len=0; p[len] && len
|