TCP/IP Programming Manual
BEGIN
INT count_read := 0;
INT error := 0;
 IF (error:=CRE_LOG_MESSAGE_(input_buffer:0,,buffer_length,count_read))
 THEN BEGIN
 CALL DEBUG;
 END;
 input_buffer[count_read] := 0; -- Null Termination.
 RETURN count_read;
END;
PROC echo_main MAIN;
BEGIN
 INT(32) bytes_from_term := 0;
 INT(32) total_received := 0;
 INT(32) nrcvd := 0;
 INT(32) sock := -1;
 INT(32) bytes_returned := 0;
 STRING .EXT startup_msg[0:50];
 STRING .EXT buf[0:1024];
 INT .EXT param_msg = buf;
 STRING .EXT host_name;
 STRUCT .EXT sin(sockaddr_in);
 STRUCT .EXT hp(hostent);
 STRUCT .EXT se(servent);
 -- All of the following strings are NULL terminated, this is the
 -- convention in C and many of the Socket routines depend on null
 -- terminated strings.
 STRING echo_service = 'P' := ["echo",0];
 STRING TCP_PROTOCOL = 'P' := ["tcp",0];
 STRING socket_error = 'P' := ["Socket error",0];
 STRING send_error = 'P' := ["Send error",0];
 STRING recv_error = 'P' := ["Recv error",0];
 STRING connect_error = 'P' := ["Connect error",0];
 STRING string_portion = 'P' := ["STRING",0];
 STRING usage = 'P' := ["usage: echo machine",0];
 STRING no_echo_serv = 'P'
 := ["Echo Service not defined, check SERVICES file.",0];
 STRING con_close = 'P'
 := ["Connection unexpectedly closed by host.",0];
 STRING ALL = 'P' := ["*ALL*",0];
 INT count := 0;
 -- Initialization uses the facilities of the CRE to
 -- facilitate the possibility of a mixed language environment.
 CALL tal_cre_initializer_(CRE^Save^all^messages);
 -- Use SMU routines to read the startup message.
 count := SMU_Startup_GetText_(
 string_portion:$INT(RTL_STRLENX_(string_portion))
 ,startup_msg:$OCCURS(startup_msg));
 startup_msg[count] := 0; -- Null Termination.
 -- Display the usage of this program if there was no startup text.
 IF NOT count
 THEN BEGIN
 CALL term_msg(usage);
 CALL CRE_TERMINATOR_(CRE^Completion^normal);
 END;
 -- Use SMU to get ENTIRE parameter message and if there is one
 -- call the paramcapture routine. The paramcapture routine is
 -- necessary to save parameters such as TCPIP^PROCESS^NAME in
 -- socket library data structures.
 IF (SMU_Param_GetText_( ALL:$INT(RTL_STRLENX_(ALL))
 ,buf:$INT($OCCURS(buf)))) > 0
Programs Using AF_INET Sockets 233










