comsub



NAME

  comsub - s2 routines for network communications

DESCRIPTION

   comsub.doc
	   K.Furukawa, Oct.2.1992, Jun.10.1993, Aug.9.1994, Jul.10.2004.

   @(#)comsubs2.doc v1.3.1 K.Furukawa, Oct.1992-Jul.2004

   Files comsub.c, comsubt.c, comsubu.c and comsubs.c containes
   s2_xxx functions for network communications.	 These routines are
   based on recho programs (see ~furukawa/tcpip/recho.tar.Z or
   olive:~ftp/pub/unix/recho.tar.Z).
   This package is available at ~furukawa/tcpip/s2-ansi.tar.gz,
   http://www-linac.kek.jp/cont/src/s2-ansi.tar.gz, or
   ftp://olive.kek.jp/pub/unix/s2.tar.Z.

   It supports TCP and UDP communication between clients and a server.
   On the TCP server side it supports both single and multiple threads.
   (It means that the server process can fork a child to handle each
   connection, in order to accept multiple connections at a time.)
   As the UDP server is connection-less, it receives a message and send
   a message back to the original client.  On the UDP client side
   it supports both normal and broadcast communication.
   It also supports timeout handling for open, send and receive routines.

   The file comsub.c defines s2_open, s2_bopen, s2_scopen, s2_close,
   s2_send, s2_receive, s2_bsend, s2_currtime routines for clients.
   The file comsubt.c defines s2_topen, s2_tsend, s2_treceive,
   s2_tusend, s2_tureceive routines for timeout handling.
   The file comsubu.c defines s2_uopen and s2_scuopen routines
   for connection-less udp clients.
   And the file comsubs.c defines s2_sopen, s2_accept, s2_sclose,
   s2_ureceive, s2_usend, s2_peerinfo, s2_upeername, s2_upeerport
   routines for servers.

   These routines run on DecStation/Ultrix, VAX/Ultrix, Sun/SunOS,
   Sony/News, NeXT, Hp-ux, NEC/SXA, SGI/Irix, IBM/AIX, Apple/AUX,
   LynxOS, Mitsubishi/Umx, Tru64unix, BSD-OS, FreeBSD, Linux,
   VAX/VMS/Win, VAX/VMS/Multinet, VAX/VMS/UCX, OS9/68K, MSDOS/PCTCP,
   Cygwin, Win32, VxWorks and MacOS/MacTCP.

   On VMS, OS9 and MSDOS systems multiple thread tcp servers are not
   supported.  On VMS broadcasting is not supported.

   BASIC USAGE:
    The basic usage for above four modes are shown below.

    TCP single thread client-server [scheme 1]
	   [client side]		   [server side]
					    sl = s2_sopen(ps,ss,"tcp",...);
	   sd = s2_open(pc,sc,"tcp",...);  loop: sd = s2_accept(sl,0,...);
	   s2_send(sd,...);		    s2_receive(sd,...);
	   s2_receive(sd,...);		    s2_send(sd,...);
	   ...				    ...
	   s2_close(sd);		    s2_sclose(sd);
					    goto loop;

    TCP multiple thread client-server [scheme 2]
	   [client side]		   [server side]
					    sl = s2_sopen(ps,ss,"tcp",...);
	   sd = s2_open(pc,sc,"tcp",...);  loop: sd = s2_accept(sl,1,...);
					    if (sd==0) goto loop;
	   s2_send(sd,...);		    s2_receive(sd,...);
	   s2_receive(sd,...);		    s2_send(sd,...);
	   ...				    ...
	   s2_close(sd);		    s2_sclose(sd);
					    exit();

    UDP client-server [scheme 3]
	   [client side]		   [server side]
					    sd = s2_sopen(ps,ss,"udp",...);
	   sd = s2_open(pc,sc,"udp",...);
	   s2_send(sd,...);		   loop: s2_ureceive(sd,...);
	   s2_receive(sd,...);		    s2_usend(sd,...);
	   ...				    ...
	   s2_close(sd);		    goto loop;

    UDP broadcast client-server [scheme 4]
	   [client side]		   [server side(s)]
					    sd = s2_sopen(ps,ss,"udp",...);
	   sd = s2_bopen(pc,sc,"udp",...);
	   s2_bsend(sd,...);		   loop: s2_ureceive(sd,...);
	   s2_tureceive(sd,...);	    s2_usend(sd,...);
	   s2_tureceive(sd,...);
	   s2_tureceive(sd,...);
	   ...				    ...
	   s2_close(sd);		    goto loop;

   EXAMPLE PROGRAMS:
    s2_recho and s2_rechod pair -- scheme 1, 2 or 3 (tcp or udp)
    s2_xfer and s2_xferd pair -- scheme 1, 3 or 4 (tcp or udp)
    s2_becho and s2_rechod pair -- scheme 4 (udp)
    s2_techo and s2_rechod pair -- scheme 1, 2 or 3 (tcp or udp) (timeout)
    s2_oecho and s2_rechod pair -- scheme 1, 2 or 3 (tcp or udp)
				    (open/close socket for every message)
    s2_in2soc and s2_soc2out pair -- scheme 1 or 3 (tcp or udp)
				    (connectionless) (separate package)

   BUGS:
    On VMS, OS9 and MSDOS systems multiple thread server is not supported.

    On VMS broadcasting is not supported.

    On OS9 s2_receive() (recv()) returns a error for the closed socket,
    while on unix it returns zero.  (Maybe it's implementation
    difference.)

   REFERENCE MANUAL:
    Reference manual below was generated from source files with the
    command  "comment comsub.c comsubs.c comsubt.c comsubu.c".

   /**
    *	   comsub  --  communication subroutines
    *		   Copyright (C) Kazuro Furukawa, 1988-2004
    *		   Kazuro Furukawa, KEK, Japan <kazuro.furukawa@kek.jp>
    *		   (if you modified this code, please inform furukawa)
    *
    *	   K.Furukawa  Nov.9.1988.  (rwrite)
    *	   K.F	Apr.13.1989.  converted from rwrite (recho)
    *	   K.F	Mar.19.1991.  recho v3.4.2
    *	   K.F	Mar.24.1992.(2)	 comsub
    *	   K.F	Sep.14.1992.  add option 3 (bit 2)
    *	   Modifications
    *	   K.F	Nov.26.1992.  close failed socket correctly
    *	   K.F	Mar.2.1993.   move error code definition to comsub.h
    *	   K.F	Jun.10.1993.  add s2_bopen() for broadcasting
    *	   K.F	Feb.21.1994.  add s2_preopen() and s2_postopen
    *	   K.F	Mar.3.1994.   add s2_scopen()
    *	   K.F	Feb.21.1996.  ansi C
    *	   K.F	Jun.29.1996.  fix bug in s2_currtime
    *	   K.F	Dec.11.1996.  add s2_currtime1()
    *	   K.F	Aug.26.1997.  fix bug in s2_preopen at host address
    *	   K.F	May.11.1999.  with NONETDB mainly for vxworks
    *	   K.F	May.19.1999.  sleep functions
    *	   K.F	Jul.21.1999.  check hostname argument in s2_preopen
    *	   K.F	Apr.2.2000.   support for windows/winsock
    *	   K.F	Aug.17.2003.  change usage of gettimeofday for new standards
    *
    *	   This module is a re-writing of zechosub.
    *	   This module defines basic rouines for socket communication.
    *	    int s2_open( portnum, service, protocol, hostname, option )
    *	    int s2_scopen( destination, protocol, option )
    *	    int s2_close( sd, option )
    *	    int s2_send( sd, buffer, buflen, option )
    *	    int s2_receive( sd, buffer, buflen, option )
    *	   This module also defines rouines for broadcast communication.
    *	    int s2_bopen( portnum, service, protocol, hostname, option )
    *	    int s2_bsend( sd, buffer, buflen, option )
    *	   And miscelaneous routines
    *	    char *  s2_currtime( )
    *	    int s2_usleep( microsecond )
    *	    int s2_sleep( second )
    *
    *	   If option is 1, error message is printed on to stderr
    *	   when error occured.
    *	   If option is 3, error and information message is printed on to stderr
    *	   when error occured.
    *	   Error code errno returned from the system subroutines are preserved
    *	   on return to the caller.
    *	   For usage, see comsubs2.doc or example programs such as
    *	   s2_recho, s2_becho, s2_oecho, s2_xfer, etc.
    */

   static char comsub_what[] =
   "@(#)comsub.c v1.12.1 tcp|udp client routines, K.Furukawa, Nov.1988-Jan.2004"; /*
   **/

   /**
    *  s2_open
    *	   s2_open prepares communication socket
    *
    *	 int s2_open( portnum, service, protocol, hostname, option )
    *
    *	   if portnum is positive, it tries to open a socket to hostname
    *	   with the portnum and protocol,
    *	   then tries to open with service (service name or port number string)
    *	   then if portnum is negative, tries to open with -portnum
    *	   protocol is "tcp" or "udp"
    *	   hostname is a host name or ip address in dotted notation
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than tcp/udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure
    *		   -7 S2_CONNERR   socket connect failure
    */
   int	s2_open(
     int portnum,		   /* positive: port no, negative: default port */
     char *service,		   /* service name, or null */
     char *protocol,		   /* "tcp" or "udp" */
     char *hostname,		   /* host name or ip-address */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_bopen
    *	   s2_bopen prepares udp communication socket for broadcasting
    *
    *	 int s2_bopen( portnum, service, protocol, hostname, option )
    *
    *	   if portnum is positive, it tries to open a socket to hostname
    *	   with the portnum
    *	   then tries to open with service (service name or port number string)
    *	   then if portnum is negative, tries to open with -portnum
    *	   only "udp" protocol is meaningful for broadcast
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *	   if protocol is not "udp", S2_NOPROT is returned
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure/ broadcast assigning failure
    *		   -7 S2_CONNERR   socket connect failure
    */
   int	s2_bopen(
     int portnum,		   /* positive: port no, negative: default port */
     char *service,		   /* service name, or null */
     char *protocol,		   /* "udp" */
     char *hostname,		   /* host name or ip-address */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_scopen
    *	   s2_scopen prepares communication socket (sc_open compatible)
    *
    *	 int s2_scopen( destination, protocol, option )
    *
    *	   destination is a string, one of these forms
    *	    "service_name", "port_number",
    *	    "service_name@host_name", "port_number@host_name"
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than tcp/udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure
    *		   -7 S2_CONNERR   socket connect failure
    */
   int	s2_scopen(
     char *destination,		   /* service and host */
     char *protocol,		   /* "tcp" or "udp" */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_close
    *	   s2_close close communication port
    *
    *	 int  s2_close( sd, option )
    *
    *	 return:   always zero
    */
   int	s2_close(
     int sd,			   /* socket descriptor returned from s2_open */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_send
    *	   s2_send sends message to communication port
    *	   calls send(2) system call.
    *
    *	 int  s2_send( sd, buffer, buflen, option )
    *
    *	 return:   -21 S2_SENDERR  send failure
    *		   positive	   byte count which has been sent
    */
   int	s2_send(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to send */
     int buflen,		   /* buffer length */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_receive
    *	   s2_receive receives message from communication port
    *	   calls recv(2) system call.
    *
    *	 int  s2_receive( sd, buffer, buflen, option )
    *
    *	 return:   -22 S2_RECVERR  receive failure
    *		   positive	   byte count which has been received
    */
   int	s2_receive(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to receive */
     int buflen,		   /* buffer length */
     int option			   /* option 1: error/information message */
   )
   /*
   **/

   /**
    *  s2_bsend
    *	   s2_bsend sends message to broadcast address
    *	   calls sendto(2) system call.	 we need separate send routine
    *	   for bi-directional broadcast-and-reply communication
    *	   this routine should be used after s2_bopen
    *
    *	 int  s2_bsend( sd, buffer, buflen, option )
    *
    *	 return:   -21 S2_SENDERR  send failure
    *		   positive	   byte count which has been sent
    */
   int	s2_bsend(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to send */
     int buflen,		   /* buffer length */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_currtime1
    *	   returns current time in second and micro-second
    */
   int s2_currtime1(
     time_t *second,		   /* current time "second" part */
     int *micro			   /* current time "microsecond" part */
   )
   /*
   **/

   /**
    *  s2_currtime
    *	   returns string of current time
    *	   24 characters like "day mmm dd hh:mm:ss yyyy"
    *	   or 27 characters like "day mmm dd hh:mm:ss.sss yyyy"
    */
   char *s2_currtime( void )
   /*
   **/

   /**
    *  s2_usleep
    *	   s2_usleep is equivalent to usleep on many unix systems.
    *	   it was mainly prepared for ultrix compatibility.
    *
    *	 int  s2_usleep(micro)
    *
    *	 return:   -23 S2_SLCTERR  select failure
    *		   0		   byte count which has been sent
    */
   int	s2_usleep(
     int micro			   /* micro second to sleep */
   )
   /*
   **/

   /**
    *  s2_sleep
    *	   s2_sleep is equivalent to sleep on many unix systems.
    *	   it was mainly prepared for vxworks compatibility.
    *
    *	 int  s2_sleep(second)
    *
    *	 return:   -23 S2_SLCTERR  select failure
    *		   0		   byte count which has been sent
    */
   int	s2_sleep(
     int second			   /* second to sleep */
   )
   /*
   **/

   /**
    *	   comsubs  --	communication subroutines for server side
    *		   Copyright (C) Kazuro Furukawa, 1988-2004
    *		   Kazuro Furukawa, KEK, Japan <kazuro.furukawa@kek.jp>
    *		   (if you modified this code, please inform furukawa)
    *
    *	   K.Furukawa  Nov.9.1988. (rwrited)
    *	   K.F	Apr.13.1989.  converted from rwrited (rechod)
    *	   K.F	Jun.17.1992.  rechod v3.4.2
    *	   K.F	Jul.20.1992.(x)	 comsubs
    *	   Modifications
    *	   K.F	Sep.14.1992.	add option 3 (bit 2)
    *	   K.F	Oct.25.1992.(2) add reuseaddr in s2_sopen
    *	   K.F	Nov.26.1992.	close failed socket correctly
    *	   K.F	Mar.2.1993.	move error code definition to comsub.h
    *	   K.F	Jun.15.1993.	add s2_upeername
    *	   K.F	Aug.9.1994.	add s2_upeerport
    *	   K.F	Feb.21.1996.	ansi C
    *	   K.F	Dec.22.1997.	use sigaction() & waitpid(), SIGACTION
    *	   K.F	Feb.15.1998.	add s2_peerinfo
    *	   K.F	May.11.1999.	for NONETDB
    *
    *	   This module is a re-writing of zechosub.
    *	   This module defines open(server), accept and close rouines
    *	   for socket communication at server side.
    *	    int s2_sopen( portnum, service, protocol, option )
    *	    int s2_accept( sl, flag, option )
    *	    int s2_sclose( sd, option )
    *	   Routines s2_receive and s2_send in comsub.c will be used for
    *	   "tcp" data transfer.
    *	   For "udp" server,  use routines s2_ureceive and s2_usend
    *	   in this file, instead of s2_receive and s2_send.
    *	    int s2_ureceive( sl, buffer, buflen, option )
    *	    int s2_usend( sl, buffer, buflen, option )
    *	    char * s2_upeername( sl, option )
    *	    int s2_upeerport( sl, option )
    *
    *	   If option is 1, error message is printed on to stderr
    *	   when error occured.
    *	   If option is 3, error and information message is printed on to
    *	   stderr when error occured.
    *	   Error codes errno returned from the system subroutines are
    *	   preserved on return to the caller.
    *
    *	   Bugs:
    *	   As global data will be used between s2_ureceive and s2_usend
    *	   in order to keep client's address, these routines must be paired
    *	   to distinguish the clients.
    *	   If the file descriptor 0 is closed between s2_sopen and s2_accept,
    *	   s2_accept may return 0 for the connection file descriptor.
    */

   static char	   comsubs_what[] =
   "@(#)comsubs.c v1.7.2 tcp|udp server subroutines K.Furukawa Nov.1988-Sep.2000"; /*
   **/

   /**
    *  s2_sopen
    *	   s2_sopen prepares communication server socket to accept a
    *	   a connection from a client.
    *
    *	 int s2_sopen( portnum, service, protocol, option )
    *
    *	   if portnum is positive, try to open a server socket with protocol
    *	   then try to open with service name
    *	   then if portnum is negative, try to open with -portnum
    *	   if option is 1 error message is sent to stderr
    *	   if option is 3 error/information message is sent to stderr
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than tcp/udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_BINDERR   socket bind failure
    *		   -7 S2_CONNERR   socket connect failure
    *		   -8 S2_LISNERR   socket listen failure
    */
   int	s2_sopen(
     int portnum,		   /* positive: port no, negative: default port */
     char *service,		   /* service name, or null */
     char *protocol,		   /* "tcp" or "udp" */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_accept
    *	   s2_accept accepts a request from a client on the socket created
    *	   by s2_sopen call and establishes a connection.  If multiple
    *	   thread is specified, it will fork child.
    *
    *	 int s2_accept( sl, flag, option )
    *
    *	   sl is socket descriptor returned from s2_sopen.
    *	   if flag is 1 multiple thread will be generated and child process
    *	   accepts a connection.  otherwise only one connection at a time
    *	   will be generated.
    *	   (on os9/msdos/vms flag has no effect, always single thread.)
    *	   if option is 1 error message is sent to stderr
    *	   if option is 3 error/information message is sent to stderr
    *
    *	 return:   0	   success, parent process return
    *		   positive	   success, socket descriptor (for child process)
    *		   -9  S2_ACCPERR  socket accept failure
    *		   -10 S2_FORKERR  child fork failure
    */
   int	s2_accept(
     int sl,			   /* socket descriptor for listen */
     int flag,			   /* flag 1: multi-thread, 0: single thread */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_sclose
    *	   s2_sclose close communication port of server side
    *
    *	 int  s2_sclose( sd, option )
    *
    *	 return:   nothing
    */
   int	s2_sclose(
     int sd,			   /* socket descriptor returned from s2_open */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_ureceive
    *	   s2_ureceive receives message from "udp" communication port
    *	   calls recvfrom(2) system call.
    *
    *	 int  s2_ureceive(sl, buffer, buflen, option)
    *
    *	 return:   -22 S2_RECVERR  receive failure
    *		   positive	   byte count which has been received
    */
   int	s2_ureceive(
     int sl,			   /* socket descriptor returned from s2_sopen */
     char *buffer,		   /* buffer to receive */
     int buflen,		   /* buffer length */
     int option			   /* option 1: error/information message */
   )
   /*
   **/

   /**
    *  s2_usend
    *	   s2_usend sends message to "udp" communication port
    *	   calls sendto(2) system call.
    *
    *	 int  s2_usend(sl, buffer, buflen, option)
    *
    *	 return:   -21 S2_SENDERR  send failure
    *		   positive	   byte count which has been sent
    */
   int	s2_usend(
     int sl,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to send */
     int buflen,		   /* buffer length */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_peerinfo
    *	   s2_peerinfo returns the remote host name and the port number
    *	   from which the "tcp" message is received.  this function should
    *	   be called after s2_accept() call and before s2_close().
    *
    *	 char *	 s2_peerinfo(sn, hostname, port, option)
    *
    *	 return:   0		   success
    *		   -2  S2_NOPORT   failure
    *	   hostname:	   pointer to host name in temporarily allocated buffer
    *			   if hostname is NULL, hostname is not returned
    *	   port:	   pointer to port number in local format
    *
    *	   if option is S2_OINFO, it prints remote information.
    */
   int s2_peerinfo(
     int sn,			   /* socket descriptor, not used */
     char **hostname,		   /* pointer to host name to be returned */
     int *port,			   /* port number to be returned */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_upeername
    *	   s2_upeername returns the remote host name from which the "udp"
    *	   message is received.	 this function should be called just after
    *	   s2_ureceive() or s2_tureceive() call.
    *
    *	 char *	 s2_upeername(sn, option)
    *
    *	 return:   host name or host address in dotted format
    *
    *	   if option is S2_OINFO, it prints remote information.
    */
   char *  s2_upeername(
     int sn,			   /* socket descriptor, not used */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_upeerport
    *	   s2_upeerport returns the remote port number from which the "udp"
    *	   message is received.	 this function should be called just after
    *	   s2_ureceive() or s2_tureceive() call.
    *
    *	 int  s2_upeerport(sn, option)
    *
    *	 return:   remote port number in operation
    *
    *	   if option is S2_OINFO, it prints remote information.
    */
   int	s2_upeerport(
     int sn,			   /* socket descriptor, not used */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *	   comsubt  --	communication subroutines with timeout
    *		   Copyright (C) Kazuro Furukawa, 1988-2004
    *		   Kazuro Furukawa, KEK, Japan <kazuro.furukawa@kek.jp>
    *		   (if you modified this code, please inform furukawa)
    *
    *	   K.Furukawa  Nov.9.1988.  (rwrite)
    *	   K.F	Apr.13.1989.  converted from rwrite (recho)
    *	   K.F	Mar.19.1991.  recho v3.4.2
    *	   K.F	Mar.24.1992.  comsub
    *	   K.F	Jun.12.1993.  comsubt
    *	   Modifications
    *	   K.F	Jun.12.1993.  add s2_tureceive() and s2_tusend()
    *	   K.F	Aug.29.1995.  add s2_topen()
    *	   K.F	Feb.21.1996.  ansi C
    *	   K.F	May.18.1999.  move s2_usleep to comsub.c
    *
    *	   This module defines send and receive rouine for socket communi-
    *	   cation.  It can be used with timeout specification.	If you
    *	   don't need timeout function, you may use s2_open, s2_send and
    *	   s2_receive.	Timeout value is specified in milli-seconds.
    *	    int s2_topen( portnum, service, protocol, hostname, timeout,
    *			 option )
    *	    int s2_tsend( sd, buffer, buflen, timeout, option )
    *	    int s2_treceive( sd, buffer, buflen, timeout, option )
    *	   For udp server, you should use these functions instead.  If you
    *	   don't need timeout function, you may use s2_usend and s2_ureceive.
    *	    int s2_tusend( sd, buffer, buflen, timeout, option )
    *	    int s2_tureceive( sd, buffer, buflen, timeout, option )
    *	   If option is S2_OERR, error message is printed on to stderr
    *	   when error occured.
    *	   If option is S2_OALL, error and information message is printed
    *	   on to stderr when error occured.
    *	   Error codes errno returned from the system subroutines are
    *	   preserved on return to the caller.
    *
    *	   Bugs:
    *	    not all environments are supported.	 ex. MSDOS is not supported.
    */

   char	   comsubt_what[] =
   "@(#)comsubt.c v1.3.6 tcp|udp client subroutines, K.Furukawa, Feb.1996-Sep.2000"; /*
   **/

   /**
    *  s2_topen
    *	   s2_topen prepares communication socket with timeout
    *
    *	 int s2_topen(portnum, service, protocol, hostname, timeout, option)
    *
    *	   if portnum is positive, it tries to open a socket to hostname
    *	   with the portnum and protocol,
    *	   then tries to open with service (service name or port number string)
    *	   then if portnum is negative, tries to open with -portnum
    *	   protocol is "tcp" or "udp"
    *	   hostname is a host name or ip address in dotted notation
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than tcp/udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure
    *		   -7 S2_CONNERR   socket connect failure
    *		   -23 S2_SLCTERR  select or fcntl failure
    *		   -24 S2_TIMEOUT  timeout failure
    */
   int	s2_topen(
     int portnum,		   /* positive: port no, negative: default port */
     char *service,		   /* service name, or null */
     char *protocol,		   /* "tcp" or "udp" */
     char *hostname,		   /* host name or ip-address */
     int timeout,		   /* timeout in milli-second */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_tsend
    *	   s2_tsend sends message to communication port with timeout
    *	   calls send(2) system call.
    *
    *	 int  s2_tsend(sd, buffer, buflen, timeout, option)
    *
    *	 return:   -21 S2_SENDERR  send failure
    *		   -23 S2_SLCTERR  select failure
    *		   -24 S2_TIMEOUT  timeout failure
    *		   positive	   byte count which has been sent
    */
   int	s2_tsend(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to send */
     int buflen,		   /* buffer length */
     int timeout,		   /* timeout in milli-second */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_treceive
    *	   s2_treceive receives message from communication port with timeout
    *	   calls recv(2) system call.
    *
    *	 int  s2_treceive(sd, buffer, buflen, timeout, option)
    *
    *	 return:   -22 S2_RECVERR  receive failure
    *		   -23 S2_SLCTERR  select failure
    *		   -24 S2_TIMEOUT  timeout failure
    *		   positive	   byte count which has been received
    */
   int	s2_treceive(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to receive */
     int buflen,		   /* buffer length */
     int timeout,		   /* timeout in milli-second */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *  s2_tureceive
    *	   s2_tureceive receives message from "udp" communication port with
    *	   timeout,  calls recvfrom(2) system call.
    *
    *	 int  s2_tureceive(sl, buffer, buflen, timeout, option)
    *
    *	 return:   -22 S2_RECVERR  receive failure
    *		   -23 S2_SLCTERR  select failure
    *		   -24 S2_TIMEOUT  timeout failure
    *		   positive	   byte count which has been received
    */
   int	s2_tureceive(
     int sd,			   /* socket descriptor returned from s2_sopen */
     char *buffer,		   /* buffer to receive */
     int buflen,		   /* buffer length */
     int timeout,		   /* timeout in milli-second */
     int option			   /* option 1: error/information message */
   )
   /*
   **/

   /**
    *  s2_tusend
    *	   s2_tusend sends message to "udp" communication port with timeout
    *	   calls sendto(2) system call.
    *
    *	 int  s2_tusend(sl, buffer, buflen, timeout, option)
    *
    *	 return:   -21 S2_SENDERR  send failure
    *		   -23 S2_SLCTERR  select failure
    *		   -24 S2_TIMEOUT  timeout failure
    *		   positive	   byte count which has been sent
    */
   int	s2_tusend(
     int sd,			   /* socket descriptor returned from s2_open */
     char *buffer,		   /* buffer to send */
     int buflen,		   /* buffer length */
     int timeout,		   /* timeout in milli-second */
     int option			   /* option 1/2: error/information message */
   )
   /*
   **/

   /**
    *	   comsubu  --	communication subroutines for udp without connect
    *		   Copyright (C) Kazuro Furukawa, 1988-2004
    *		   Kazuro Furukawa, KEK, Japan <kazuro.furukawa@kek.jp>
    *		   (if you modified this code, please inform furukawa)
    *
    *	   K.Furukawa  Nov.9.1988.  (rwrite)
    *	   K.F	Apr.13.1989.  converted from rwrite (recho)
    *	   K.F	Mar.19.1991.  recho v3.4.2
    *	   K.F	Mar.24.1992.(2)	 comsub
    *	   K.F	Sep.14.1992.  add option 3 (bit 2)
    *	   K.F	Mar.4.1994.   udp without connection
    *	   Modifications
    *	   K.F	Feb.21.1996.  ansi C
    *
    *	   This module is a re-writing of zechosub.
    *	   This module defines basic rouines for udp socket communication.
    *	    int s2_uopen( portnum, service, protocol, hostname, option )
    *	    int s2_scuopen( destination, protocol, option )
    *
    *	   You may use only one socket with uopen routines.
    *	   s2_bsend and s2_breceive routine can be used with these routines
    *
    *	   If option is 1, error message is printed on to stderr
    *	   when error occured.
    *	   If option is 3, error and information message is printed on to stderr
    *	   when error occured.
    *	   Error code errno returned from the system subroutines are preserved
    *	   on return to the caller.
    *	   For usage, see comsubs2.doc or example programs such as
    *	   s2_in2soc, etc.
    */

   char	   comsubu_what[] =
   "@(#)comsubu.c v1.1.2 udp client subroutines, K.Furukawa, Feb.1996"; /*
   **/

   /**
    *  s2_uopen
    *	   s2_uopen prepares udp communication socket without connection
    *
    *	 int s2_uopen( portnum, service, protocol, hostname, option )
    *
    *	   this is based on s2_bopen
    *	   if portnum is positive, try to open a socket to hostname
    *	   with the portnum
    *	   then try to open with service
    *	   then if portnum is negative, try to open with -portnum
    *	   only "udp" protocol is meaningful for this routine
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *	   if protocol is not "udp", S2_NOPROT is returned
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure/ broadcast assigning failure
    *		   -7 S2_CONNERR   socket connect failure
    */
   int	s2_uopen(
     int portnum,		   /* positive: port no, negative: default port */
     char *service,		   /* service name, or null */
     char *protocol,		   /* "udp" */
     char *hostname,		   /* host name or ip-address */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/

   /**
    *  s2_scuopen
    *	   s2_scuopen prepares udp communication socket (sc_open compatible)
    *
    *	 int s2_scuopen( destination, protocol, option )
    *
    *	   destination is a string, one of these forms
    *	    "service_name", "#port_number",
    *	    "service_name@host_name", "#port_number@host_name"
    *	   if option is 1 or S2_OERR, error message is sent to stderr
    *	   if option is 3 or S2_OALL, error/info. message is sent to stderr
    *
    *	 return:   positive/0	   success, socket descriptor
    *		   -1 S2_NOSERV	   service not found
    *		   -2 S2_NOPORT	   no port/service specified
    *		   -3 S2_NOHOST	   unknown host
    *		   -4 S2_NOPROT	   protocol other than tcp/udp specified
    *		   -5 S2_OPENERR   socket open failure
    *		   -6 S2_UBNDERR   udp bind failure
    *		   -7 S2_CONNERR   socket connect failure
    */
   int	s2_scuopen(
     char *destination,		   /* service and host */
     char *protocol,		   /* "tcp" or "udp" */
     int option			   /* option 1: error, 2: info. message */
   )
   /*
   **/


Man(1) output converted with man2html