📄 protocol.h
字号:
/**************************************************************************/
/* TCP protocol
* define both headers required and create a data type for a typical
* outgoing TCP packet (with IP header)
*
* Note: So far, there is no way to handle IP options fields
* which are associated with a TCP packet. They are mutually exclusive
* for both receiving and sending. Support may be added later.
*
* The tcph and iph structures can be included in many different types of
* arbitrary data structures and will be the basis for generic send and
* receive subroutines later. For now, the packet structures are optimized
* for packets with no options fields. (seems to be almost all of them from
* what I've observed.
*/
typedef struct tcph
{
uint16 source,dest; /* TCP port numbers, all byte-swapped */
uint32 seq,ack; /* sequence, ACK numbers */
uint8 hlen, /* length of TCP header in 4 byte words */
flags; /* flag fields */
uint16 window, /* advertised window, byte-swapped */
check, /* TCP checksum of whole packet */
urgent; /* urgent pointer, when flag is set */
} TCPLAYER;
/*
* used for computing checksums in TCP
*/
struct pseudotcp
{
uint8 source[4],dest[4], /* IP #'s for source,dest */
z,proto; /* zero and protocol number */
uint16 tcplen; /* byte-swapped length field */
};
typedef struct tcp
{
uint16 padding;
DLAYER d;
IPLAYER i;
TCPLAYER t;
union
{
uint8 options[40]; /* not very likely, except on SYN */
uint8 data[1]; /* largest TCP data we will use */
} x;
} TCPKT;
/*
* flag field definitions, first two bits undefined
*/
#define TURG 0x20
#define TACK 0x10
#define TPUSH 0x08
#define TRESET 0x04
#define TSYN 0x02
#define TFIN 0x01
/*******************************************************************/
/* raw packet queue
*/
#ifndef POINT_TO_POINT
struct pqueue
{
struct pqueue HUGE *next;
struct pqueue HUGE *previous;
uchar HUGE *data_ptr;
int32 seqnum;
uint16 data_len;
uint16 option_len;
int16 retransmits;
uchar packet[MTU];
uint16 pad;
};
#else /* POINT_TO_POINT */
struct pqueue
{
struct pqueue HUGE *next;
struct pqueue HUGE *previous;
uchar HUGE *data_ptr;
int32 seqnum;
uint16 data_len;
uint16 option_len;
int16 retransmits;
uint16 pad;
uchar packet[MTU];
};
#endif /* POINT_TO_POINT */
typedef struct pqueue HUGE BUFFER;
struct pqueue_hdr
{
BUFFER *head;
BUFFER *tail;
};
/* The PQ_HEADER_SIZE is used only for finding the pointer to the beginnig
of a pqueue structure when a pointer to the packet field is the only
information available. */
#define PQ_HEADER_SIZE 22
struct window
{
uint32 nxt, /* sequence number, not byte-swapped */
ack; /* what the other machine acked */
int32 lasttime; /* (signed) used for timeout checking */
struct pqueue_hdr packet_list;
BUFFER *nextPacket;
struct pqueue_hdr ooo_list; /* Contains out of order packets. */
uint16 num_packets;
uint16 size, /* size of window advertised */
port, /* port numbers from one host or another */
contain; /* how many bytes in queue? */
uint8 push; /* flag for TCP push */
uint8 pad[3]; /* correcl alignment for 32 bits CPU */
};
typedef struct window WINDOW;
struct port
{
struct window in, out;
TCPKT tcpout; /* pre-initialized as much as possible */
struct pseudotcp tcps; /* pseudo-tcp for checksumming */
uint32 maxSendWin; /* Max send window. */
#ifdef PLUS
NU_TASK *RXTask, /* receive task waiting on an event -
added during ATI mods - 10/16/92, bgh */
*TXTask; /* transmit task waiting on an event -
added during ATI mods - 10/16/92, bgh */
#else
int16 RXTask, /* receive task waiting on an event -
added during ATI mods - 10/16/92, bgh */
TXTask; /* transmit task waiting on an event -
added during ATI mods - 10/16/92, bgh */
#endif
uint16 credit; /* choked-down window for fast hosts */
uint16 sendsize; /* MTU value for this connection */
uint16 rto; /* retrans timeout */
int16 suspended_for; /* The reason for the task suspending, i.e., no
buffers available, waiting for data, etc., */
uint16 pindex; /* added by Randy */
uint16 portFlags;
struct TASK_TABLE_STRUCT *task_entry;
int16 task_num;
uint8 state; /* connection state */
int8 odh_flag; /* used as a flag for saying that the port
is being used for Optimized Data Handling.
No buffer copying at low level, all handled
by the user. NU_ODH_NONE, NU_ODH_RECEIVE,
NU_ODH_TRANSMIT. - 05/11/93, CLM */
int8 xmitFlag; /* Used to indicate an timer event has been
created to transmit a partial packet. */
int8 probeFlag; /* This flag will be set when a window probe
is required. */
int8 closeFlag; /* This flag is set when a connection is
closing. */
int8 selectFlag; /* This flag is set whenever a call to
NU_Select results in a task timing out. */
};
typedef struct port PORT;
/***************************************************************************/
/* Port Flags */
/* */
#define ACK_TIMER_SET 0x0001
#define SELECT_SET 0x0002
/*************************************************************************/
/* TCP states
* each connection has an associated state in the connection flow.
* the order of the states now matters, those less than a certain
* number are the "inactive" states.
*/
#define SCLOSED 1
#define SLISTEN 2
#define SSYNS 3
#define SSYNR 4
#define SEST 5
#define SFW1 6
#define SFW2 7
#define SCWAIT 8
#define SLAST 9
#define SCLOSING 10
#define STWAIT 11
/*************************************************************************/
/* UDP
* User Datagram Protocol
* Each packet is an independent datagram, no sequencing information
*
* UDP uses the identical checksum to TCP
*/
typedef struct udph
{
uint16 source,
dest; /* port numbers, all byte-swapped */
uint16 length, /* length of packet, including hdr */
check; /* TCP checksum of whole packet */
} UDPLAYER;
typedef struct udp
{
DLAYER d;
IPLAYER i;
UDPLAYER u;
uint8 data[1]; /* largest UDP data we will use */
uint16 pad; /* correct alignment for 32 bits CPU */
} UDPKT;
struct uport
{
UDPKT in, out;
struct pseudotcp tcps; /* pseudo-tcp for
checksumming */
struct pqueue_hdr dgram_list; /* Header for a linked list
of received datagrams. */
#ifdef PLUS
NU_TASK *RXTask; /* receive task waiting on an
event */
NU_TASK *TXTask; /* transmit task waiting on an
event */
#else
int16 RXTask; /* receive task waiting on an
event */
int16 TXTask; /* transmit task waiting on an
event */
#endif
uint32 uportFlags; /* What type of events are
currently pending. */
uint16 listen; /* what port should this one
listen to? */
uint16 length; /* how much data arrived in
last packet? */
uint16 in_dgrams; /* The number of data grams
currently buffered */
uint8 out_stale; /* have we read this packet
yet? */
uint8 pad; /* correct alignment for 32
bits CPU */
};
/*
* events which can occur and be placed into the event queue
*/
#define NEVENTS 50
/* classes defined in netevent.h */
/************************* Transmit Queue defines. *************/
struct transq
{
struct transq *next;
struct transq *previous;
struct pqueue HUGE *buffer;
uchar *pkt;
uchar status;
uchar pkt_type;
uint16 length;
};
struct transq_hdr
{
struct transq *head;
struct transq *tail;
};
#define OTHER_PKT 0
#define TCP_DATA_PKT 1
#endif /* PROTOCOL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -