* InternetCT.h
 *
 * 920513 DRH	Added udp definitions.
 * 920703 DRH	Added rx_timeout to RQ_UDP_ALL
 *
 * Basic InternetCT requests and Ercs.
 *

ifndef HEADER_INETCT

define HEADER_INETCT			1

extern unsigned		rq_base_tcp( );
extern unsigned		rq_base_tcp2( );

define REQUEST_BASE			rq_base_tcp( )

define HOSTNAME_TO_IP_ADDRESS	rq_base_tcp( ) + 0x00
define IP_ADDRESS_TO_HOSTNAME	rq_base_tcp( ) + 0x01
define OPEN_TCP_CONNECTION		rq_base_tcp( ) + 0x02
define OPEN_TCP_CONNECTION_NO_WAIT rq_base_tcp( ) + 0x03
define GET_TCB					rq_base_tcp( ) + 0x04
define SEND_TCP_MESSAGE		rq_base_tcp( ) + 0x05
define RECEIVE_TCP_MESSAGE		rq_base_tcp( ) + 0x06
define CLOSE_TCP_CONNECTION	rq_base_tcp( ) + 0x07
define ABORT_TCP_CONNECTION	rq_base_tcp( ) + 0x08
define GET_SETUP				rq_base_tcp( ) + 0x09
define QUERY_STATISTICS		rq_base_tcp( ) + 0x11
define REQUEST_LAST			rq_base_tcp( ) + 0x15

define REQUEST_BASE_2			rq_base_tcp2( )
define UDP_ALL					rq_base_tcp2( ) + 0x03

define ORC_HOSTNAME_TO_IP_ADDRESS	0x00
define ORC_IP_ADDRESS_TO_HOSTNAME	0x01
define ORC_OPEN_TCP_CONNECTION		0x02
define ORC_OPEN_TCP_CONNECTION_NO_WAIT 0x03
define ORC_GET_TCB					0x04
define ORC_SEND_TCP_MESSAGE		0x05
define ORC_RECEIVE_TCP_MESSAGE		0x06
define ORC_CLOSE_TCP_CONNECTION	0x07
define ORC_ABORT_TCP_CONNECTION	0x08
define ORC_GET_SETUP				0x09
define ORC_QUERY_STATISTICS		0x11

if( SET_REQUEST)
typedef struct requesttype{
	unsigned char		scntinfo;
	unsigned char		rtcode;
	unsigned char		nreqpbcb;
	unsigned char		nresppbcb;
	unsigned int		usernum;
	unsigned int		exchresp;
	unsigned int		ercret;
	unsigned int		rqcode;
} REQUEST;
define NULLREQUEST		(REQUEST *)0

typedef struct {
		REQUEST			rq;
} RQ_ABORT_USER, RQ_SWAP_USER;
define ERC_CTOS_SWAP_RQ	37

typedef struct {
		REQUEST			rq;
		unsigned int	oldusernum;
} RQ_CHANGE_USER_NUMBER;
endif

if( SET_RQ_HOSTNAME_TO_IP_ADDRESS)
typedef struct {
		REQUEST					rq;
		char					* name;
		unsigned int			sname;
		long					* address;		* returned *
		unsigned int			saddress;
} RQ_HOSTNAME_TO_IP_ADDRESS;
endif

if( SET_RQ_IP_ADDRESS_TO_HOSTNAME)
typedef struct {
		REQUEST					rq;
		unsigned long int		address;
		char					* name;			* returned *
		unsigned int			snamemax;
		unsigned int			* sname;		* returned *
		unsigned int			ssname;			
} RQ_IP_ADDRESS_TO_HOSTNAME;
endif

if( SET_RQ_OPEN_TCP_CONNECTION || SET_RQ_OPEN_TCP_CONNECTION_NO_WAIT)
typedef struct {
		REQUEST					rq;
		unsigned int			index;
		unsigned int			localport;		* 0 means use the first	*
												* free port >= 1024		*

		unsigned int			remoteport;		* not needed if not Active	*
												* open						*

		unsigned int			timeout;		* 0 means default value	*
		unsigned int			precedence;		* 0 means default value	*
		unsigned int			security;		* 0 means default value	*

		unsigned char			active;
		unsigned char			reserved;

		char					* remotehost;	* not needed if not Active	*
												* open						*
												* if the first char is @	*
												* then the next 4 chars	*
												* are a binary ip address	*
		unsigned int			sremotehost;

		char					* options;		* only maximum segment	 	*
												* size is supported		*
		unsigned int			soptions;

		unsigned int			* handle;		* returned *
		unsigned int			shandle;
} RQ_OPEN_TCP_CONNECTION, RQ_OPEN_TCP_CONNECTION_NO_WAIT;
endif

if( SET_RQ_CLOSE_TCP_CONNECTION || SET_RQ_ABORT_TCP_CONNECTION)
typedef struct {
		REQUEST					rq;
		unsigned int			index;
		unsigned int			handle;
} RQ_CLOSE_TCP_CONNECTION, RQ_ABORT_TCP_CONNECTION;
endif

if( SET_RQ_SEND_TCP_MESSAGE)
typedef struct {
		REQUEST					rq;
		unsigned int			index;
		unsigned int			handle;
		unsigned char			push;
		unsigned char			urgent;
		char					* message;
		unsigned int			smessage;
} RQ_SEND_TCP_MESSAGE;
endif

if( SET_RQ_RECEIVE_TCP_MESSAGE)
typedef struct {
		REQUEST					rq;
		unsigned int			index;
		unsigned int			handle;
		unsigned char			* push;				* returned *
		unsigned int			spush;
		unsigned char			* urgent;			* returned *
		unsigned int			surgent;
		char					* message;			* returned *
		unsigned int			smessagemax;
		unsigned int			* smessage;			* returned *
		unsigned int			ssmessage;
} RQ_RECEIVE_TCP_MESSAGE;
endif

if( SET_RQ_GET_SETUP)
typedef struct {
		REQUEST					rq;
		unsigned long int		* address;		* returned *	
		unsigned int			saddress;
		unsigned int			* mss;			* returned *	
		unsigned int			smss;
		unsigned int			* window;		* returned *	
		unsigned int			swindow;
		unsigned int			* ttl;			* returned *	
		unsigned int			sttl;
		char					* name;			* returned *	
		unsigned int			snamemax;
		unsigned int			* sname;		* returned *	
		unsigned int			ssname;
} RQ_GET_SETUP;
endif

	* Socket structure *
ifndef SCOCKET
typedef struct sockettype {
	unsigned long int	address;		* IP address *
	unsigned int		port;			* port number *
} SOCKET;
define	NULLSOCK	(SOCKET *)0
endif

	* Connection structure (two sockets) *
ifndef CONNECTION
typedef struct connectiontype {
	SOCKET				local;
	SOCKET				remote;
} CONNECTION;
endif

if( SET_TCB_RETURNED || SET_RQ_GET_TCB)
define GET_TCB_STATE_OFFSET	16

typedef struct tcbrettype {
	unsigned int				notice_type;
define NOTICE_STATE			1
define NOTICE_RECEIVE			2
define NOTICE_SEND				3
	unsigned int				notice_param; * count or old state *
	CONNECTION					conn;
	char						state;		* Connection state *
define	CLOSED			0
define	LISTEN			1
define	SYN_SENT		2
define	SYN_RECEIVED	3
define	ESTABLISHED		4
define	FINWAIT1		5
define	FINWAIT2		6
define	CLOSE_WAIT		7
define	CLOSING			8
define	LAST_ACK		9
define	TIME_WAIT		10
	char						reason;		* Reason for closing *
	char						type;		* icmp message type *
	char						code;		* icmp message code *
	unsigned int				window;		* window and queue limit *
	unsigned int				rcvcnt;		* number bytes queued *
	unsigned int				sndcnt;		* number unack'ed queued *
} TCB_RETURNED;

define NULLTCB_RETURNED		( TCB_RETURNED *)0

endif

if( SET_RQ_GET_TCB)
typedef struct {
		REQUEST					rq;
		unsigned int			index;
		unsigned int			handle;
		TCB_RETURNED			* tcb;
		unsigned int			stcbmax;
		unsigned int			* stcb;
		unsigned int			sstcb;
} RQ_GET_TCB;
endif

if( SET_RQ_UDP_ALL)

typedef struct {									* Size  Offsets *
	CONNECTION			conn;						*  12    0    0 *
	unsigned char		msg[1];						*   1   12   0C *
} UDP_MSG;											* Total 13   0D *
define SUDP_MSG	sizeof(UDP_MSG)

typedef struct rq_udp_all_type {					* Size  Offsets *
	REQUEST					rq;						*  12    0    0 *
	unsigned int			type;					*   2   12   0C *
define UDP_TYPE_OPEN		1
define UDP_TYPE_SEND		2
define UDP_TYPE_RECEIVE	3
define UDP_TYPE_CLOSE		4
	unsigned int			rx_timeout;
	UDP_MSG					* udp_in;				*   4   14   0E *
	unsigned int			sudp_in;				*   2   18   12 *
	UDP_MSG					* udp_out;				*   4   20   14 *
	unsigned int			sudp_outmax;			*   2   24   18 *
	unsigned int			* sudp_out;				*   4   26   1A *
	unsigned int			ssudp_out;				*   2   30   1E *
} RQ_UDP_ALL;										*  32  TOTAL    *
define SRQ_UDP_ALL		sizeof(RQ_UDP_ALL)

endif

if( SET_RQ_QUERY_STATISTICS)
*
inetctstatistics( node, snode, type, in, size_in, out, size_out);
*

typedef struct {
	REQUEST						rq;
	unsigned					type;
	unsigned char				* node;
	unsigned					snode;
	unsigned char				* stats_in;
	unsigned					sstats_in;
	unsigned char				* stats_out;	* returned *
	unsigned					sstats_out;
} RQ_QUERY_STATISTICS;
endif


define ERC_BASE						0xf000
define ERC_MEMORY						0x0000
define ERC_TIMER						0x0005
define ERC_CONFIG						0x0030
define ERC_APP							0x0040
define ERC_CLOSE						0x0060

define ERC_MEMORY_UNAVAILABLE			ERC_BASE + ERC_MEMORY + 0
define ERC_MEMORY_FAILURE				ERC_BASE + ERC_MEMORY + 1
define ERC_MEMORY_FREE_GARBAGE			ERC_BASE + ERC_MEMORY + 2

define ERC_TIMER_LOOP					ERC_BASE + ERC_TIMER + 0

define ERC_CON_CANT_ATTACH				ERC_BASE + ERC_CONFIG + 0
define ERC_CON_NO_IFACE_EXISTS			ERC_BASE + ERC_CONFIG + 1
define ERC_CON_IFACE_EXISTS			ERC_BASE + ERC_CONFIG + 2
define ERC_CON_NO_ROUTE_EXISTS			ERC_BASE + ERC_CONFIG + 3
define ERC_CON_ROUTE_EXISTS			ERC_BASE + ERC_CONFIG + 4
define ERC_CON_NO_ADDRESS_EXISTS		ERC_BASE + ERC_CONFIG + 5
define ERC_CON_ADDRESS_EXISTS			ERC_BASE + ERC_CONFIG + 6
define ERC_CON_ADDRESS_MISMATCH		ERC_BASE + ERC_CONFIG + 7
define ERC_CON_NO_HOST_EXISTS			ERC_BASE + ERC_CONFIG + 8
define ERC_CON_HOST_EXISTS				ERC_BASE + ERC_CONFIG + 9

define ERC_APP_WRONG_USER				ERC_BASE + ERC_APP + 1
define ERC_APP_CONN_EXISTS				ERC_BASE + ERC_APP + 2
define ERC_APP_NO_CONN_EXISTS			ERC_BASE + ERC_APP + 3
define ERC_APP_CONN_CLOSING			ERC_BASE + ERC_APP + 4
define ERC_APP_CONN_CLOSED				ERC_BASE + ERC_APP + 5
define ERC_APP_WOULD_BLOCK				ERC_BASE + ERC_APP + 6
define ERC_APP_INVALID_ARGS			ERC_BASE + ERC_APP + 7
define ERC_APP_BAD_HANDLE				ERC_BASE + ERC_APP + 8
define ERC_APP_RQ_WAITING				ERC_BASE + ERC_APP + 9
define ERC_APP_RQ_ABORTED				ERC_BASE + ERC_APP + 10
define ERC_APP_USER_NO_MATCH			ERC_BASE + ERC_APP + 11
define ERC_APP_GET_TCB_SMALL			ERC_BASE + ERC_APP + 12
define ERC_APP_READ_TOO_BIG			ERC_BASE + ERC_APP + 13
define ERC_APP_WRITE_TOO_BIG			ERC_BASE + ERC_APP + 14

define ERC_CLOSE_FIRST_ERC				ERC_BASE + ERC_CLOSE + 0
define ERC_CLOSE_UNKNOWN				ERC_BASE + ERC_CLOSE + 0
define ERC_CLOSE_RESET					ERC_BASE + ERC_CLOSE + 1
define ERC_CLOSE_TIMEOUT				ERC_BASE + ERC_CLOSE + 2
define ERC_CLOSE_NET_UNREACH			ERC_BASE + ERC_CLOSE + 3
define ERC_CLOSE_HOST_UNREACH			ERC_BASE + ERC_CLOSE + 4
define ERC_CLOSE_PROT_UNREACH			ERC_BASE + ERC_CLOSE + 5
define ERC_CLOSE_PORT_UNREACH			ERC_BASE + ERC_CLOSE + 6
define ERC_CLOSE_FRAG_NEEDED			ERC_BASE + ERC_CLOSE + 7
define ERC_CLOSE_ROUTE_FAIL			ERC_BASE + ERC_CLOSE + 8
define ERC_CLOSE_DEST_UNREACH			ERC_BASE + ERC_CLOSE + 9
define ERC_CLOSE_TTL_EXCEED			ERC_BASE + ERC_CLOSE + 10
define ERC_CLOSE_FRAG_EXCEED			ERC_BASE + ERC_CLOSE + 11
define ERC_CLOSE_TIME_EXCEED			ERC_BASE + ERC_CLOSE + 12
define ERC_CLOSE_NETWORK				ERC_BASE + ERC_CLOSE + 13
define ERC_CLOSE_LAST_ERC				ERC_BASE + ERC_CLOSE + 13

endif

	SOCKET				remote;
} CONNECTION;
endif

if(