/*********************************************************************/
/* */
/* MODULE NAME: EZASOKPS - THIS IS A VERY SIMPLE IPV4 SERVER */
/* */
/* Copyright: Licensed Materials - Property of IBM */
/* */
/* "Restricted Materials of IBM" */
/* */
/* 5694-A01 */
/* */
/* (C) Copyright IBM Corp. 1994, 2005 */
/* */
/* US Government Users Restricted Rights - */
/* Use, duplication or disclosure restricted by */
/* GSA ADP Schedule Contract with IBM Corp. */
/* */
/* Status: CSV1R7 */
/* */
/*********************************************************************/
EZASOKPS: PROC OPTIONS(MAIN);
/* INCLUDE CBLOCK - common variables */
% include CBLOCK;
ID.TCPNAME = 'TCPIP'; /* Set TCP to use */
ID.ADSNAME = 'EZASOKPS'; /* and address space name */
open file(driver);
/*********************************************************************/
/* */
/* Execute INITAPI */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* Uncomment this code to set max sockets to the maximum. */
/* */
/* MAXSOC_INPUT = 65535; */
/* MAXSOC_FWD = MAXSOC_INPUT; */
/*********************************************************************/
call ezasoket(INITAPI, MAXSOC, ID, SUBTASK,
MAXSNO, ERRNO, RETCODE);
if retcode < 0 then do;
msg = 'FAIL: initapi' || errno;
write file(driver) from (msg);
goto getout;
end;
/*********************************************************************/
/* */
/* Execute SOCKET */
/* */
/*********************************************************************/
call ezasoket(SOCKET, AF_INET, TYPE_STREAM, PROTO,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: socket, stream, internet' || errno;
write file(driver) from (msg);
goto getout;
end;
else sock_stream = retcode;
/*********************************************************************/
/* */
/* Execute BIND */
/* */
/*********************************************************************/
name_id.port = 8888;
name_id.address = '01234567'BX; /* internet address */
call ezasoket(BIND, SOCK_STREAM, NAME_ID,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: bind' || errno;
write file(driver) from (msg);
goto getout;
end;
/*********************************************************************/
/* */
/* Execute GETSOCKNAME */
/* */
/*********************************************************************/
name_id.port = 8888;
name_id.address = '01234567'BX; /* internet address */
call ezasoket(GETSOCKNAME, SOCK_STREAM,
NAME_ID, ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: getsockname, stream, internet' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'getsockname = ' || name_id.address;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute LISTEN */
/* */
/*********************************************************************/
backlog = 5;
call ezasoket(LISTEN, SOCK_STREAM, BACKLOG,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: listen w/ backlog = 5' || errno;
write file(driver) from (msg);
goto getout;
end;
/*********************************************************************/
/* */
/* Execute ACCEPT */
/* */
/*********************************************************************/
name_id.port = 8888;
name_id.address = '01234567'BX; /* internet address */
call ezasoket(ACCEPT, SOCK_STREAM,
NAME_ID, ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: accept' || errno;
write file(driver) from (msg);
end;
else do;
accpsock = retcode;
msg = 'accept socket = ' || accpsock;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute READ */
/* */
/*********************************************************************/
nbyte = length(bufin);
call ezasoket(READ, ACCPSOCK,
NBYTE, BUFIN, ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: read' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'read = ' || bufin;
write file(driver) from (msg);
bufout = bufin;
nbyte = retcode;
end;
/*********************************************************************/
/* */
/* Execute WRITE */
/* */
/*********************************************************************/
call ezasoket(WRITE, ACCPSOCK, NBYTE, BUFOUT,
ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: write' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'write = ' || bufout;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute CLOSE accept socket */
/* */
/*********************************************************************/
call ezasoket(CLOSE, ACCPSOCK,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: close, accept sock' || errno;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute TERMAPI */
/* */
/*********************************************************************/
getout:
call ezasoket(TERMAPI);
close file(driver);
end ezasokps;
Figure 1. EZASOKPS PL/1 sample
server program for IPv4