# ifndef NO_WHAT
/*
 *      SCCS file type - Emulator Include File
 *
 *      What identification string:
 */
static char *_S_htcpfamily = "@(#)tcpfamily.h	1.1";
# endif
#ifdef NETWORK

#define  net_wait_event   27

/*
** Shared structures for TCP networking
*/

/*
** The Channel table
*/
#define  Channel_Entry   NetChe
#define  channel_table   NetCht
#define  Channel_Index   char

typedef struct {
	SHARED
	seid	chan_sseid;
	seid	chan_dseid;
	int	chan_use;
} Channel_Entry;



#define  Connection   char

#define  Protocol   char
#define  TCP_IP  		0

/*
** type Tcp_State = (LISTEN, SYN_SENT, .... CLOSED)
*/
#define  Tcp_State   char
#define  CLOSED           0
#define  LISTEN           1
#define  SYN_SENT         2
#define  SYN_RECEIVED     3
#define  ESTABLISHED      4
#define  FIN_WAIT_1       5
#define  FIN_WAIT_2       6
#define  TIME_WAIT        7
#define  CLOSE_WAIT       8
#define  CLOSING          9

/*
** Define TCB structure
*/
#define  tcb_master  		TcbMst
#define  tcb_users  		TcbUsr
#define  tcb_user_sends         TcbUsn
#define  tcb_user_rcves  	TcbUrc
#define  tcb_user_state  	TcbUst
#define  tcb_channel  		TcbCha
#define  tcb_name  		TcbNam
#define  tcb_state  		TcbSta
#define  tcb_local_socket  	TcbLsk
#define  tcb_foreign_socket  	TcbFsk
#define  tcb_initial_port  	TcbInp
#define  tcb_flags  		TcbFlg
#define  tcb_timeout  		TcbTmo
#define  tcb_snd_una  		TcbSun
#define  tcb_snd_nxt  		TcbSnx
#define  tcb_snd_wnd  		TcbSwn
#define  tcb_snd_bs  		TcbSbs
#define  tcb_snd_up  		TcbSup
#define  tcb_snd_wl  		TcbSwl
#define  tcb_snd_lbb  		TcbSlb
#define  tcb_iss  		TcbIss
#define  tcb_snd_inx  		TcbSin
#define  tcb_rcv_nxt  		TcbRnx
#define  tcb_rcv_wnd  		TcbRwn
#define  tcb_rcv_bs  		TcbRbs
#define  tcb_rcv_up  		TcbRup
#define  tcb_rcv_lbb  		TcbRlb
#define  tcb_irs  		TcbIrs
#define  tcb_snd  		TcbSnd
#define  tcb_rcv  		TcbRcv
#define  tcb_rcv_segq  		TcbRsq
#define  tcb_rcv_dataq  	TcbRdq
#define  tcb_snd_seg            TcbSsg
#define  TcpRequest  		TcpReq
#define  TcpRequestQueue  	TcpRqq

typedef struct {
	seid		req_requester;
	Connection	req_conn;
	char		req_type;
	virt_loc	req_buff;
	unsigned	req_length;
	int		req_flags;
	Seqno		req_seq;
	unsigned	req_phantom;
} TcpRequest;

typedef struct {
	int		RQ_head;
	int		RQ_tail;
	int		RQ_size;
	TcpRequest	RQ[ NTCPREQUESTS ];
} TcpRequestQueue;

typedef struct {
	/* top half connection data */
	SHARED
	int		tcb_users;
	int		tcb_user_state;
	int		tcb_user_sends;
	int		tcb_user_rcves;
	seid		tcb_master;

	/* Bottom half connection data */
	Channel_Index	tcb_channel;
	Connection	tcb_name;
	Protocol	tcb_protocol;
	Tcp_State	tcb_state;
	Socket		tcb_local_socket;
	Socket		tcb_foreign_socket;
	Port		tcb_initial_port;
	int		tcb_flags;
	unsigned	tcb_timeout;

	/* Send Sequence Variables */
	Seqno		tcb_snd_una;
	Seqno		tcb_snd_nxt;
	Seqno		tcb_snd_wnd;
	unsigned	tcb_snd_bs;
	Seqno		tcb_snd_up;
	Seqno		tcb_snd_wl;
	Seqno		tcb_snd_lbb;
	Seqno		tcb_iss;
	Seqno		tcb_snd_inx;	/* shadow snd_nxt */

	/* Receive Sequence Variables */
	Seqno		tcb_rcv_nxt;
	unsigned	tcb_rcv_wnd;
	unsigned	tcb_rcv_bs;
	Seqno		tcb_rcv_up;
	Seqno		tcb_rcv_lbb;
	Seqno		tcb_irs;

	/* User Request queues */
	TcpRequestQueue	tcb_snd;
	TcpRequestQueue	tcb_rcv;

	/* send control variables */
	BuffIndex	tcb_snd_seg;

	/* receive control variables */
	BuffIndex	tcb_rcv_segq;
	BuffIndex	tcb_rcv_dataq;
} Control_Block;

/*
 * Tcb flags word definitions
 */
#define  TCB_PASSIVE  	001
#define  TCB_URGENT  	002
#define  TCB_CLOSING  	004


/*
 * Definition for format of shared network structures.
 * These go on the family segment
 */
typedef struct {
	Control_Block TCB[ NCONNECTIONS ];
	Channel_Entry channel_table[ NCHANNELS ];
} FNETstruct;


extern FNETstruct FNET;



/* These should undoubtedly be somewhere else.. */
#define  min(x,y)  ((x)<(y)?(x):(y))
#define  max(x,y)  ((x)>(y)?(x):(y))
#endif
