📄 protocol.h
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1993 - 1996 by Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*
*
*Portions of this program were written by: */
/***************************************************************************
* *
* part of: *
* TCP/IP kernel for NCSA Telnet *
* by Tim Krauskopf *
* *
* National Center for Supercomputing Applications *
* 152 Computing Applications Building *
* 605 E. Springfield Ave. *
* Champaign, IL 61820 *
* *
* *
****************************************************************************
*
*
*/
/******************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* PROTOCOL.H NET 3.2 */
/* */
/* DESCRIPTION */
/* */
/* This file contains the structure definitions for each type of */
/* protocol that this program wishes to handle. A companion file, */
/* 'protinit.c' initializes sample versions of each type of header, */
/* improving the efficiency of sending packets with constants in most */
/* of the fields. */
/* */
/* AUTHOR */
/* */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Glen Johnson 04/30/96 Made some changes based on */
/* recommendations of K. Goto */
/* of Hitachi. */
/******************************************************************************/
#ifndef PROTOCOL_H
#define PROTOCOL_H
#ifdef PLUS
#include "nucleus.h"
#else
#include "nu_defs.h"
#include "nu_extr.h"
#endif
#include "target.h"
#ifdef NU_PPP
#include "ppp_defs.h"
#endif
#ifndef PLUS
#define VOID void
typedef int STATUS;
typedef unsigned long UNSIGNED;
#endif
/*
* Defines which have to do with Ethernet addressing.
* Ethernet has 6 bytes of hardware address.
*/
#define DADDLEN 6 /* Length of Ethernet header in bytes */
#define IPADDLEN 4 /* Length of IP address in bytes */
#define ICMPMAX 300 /* Maximum ICMP message size */
/*
* The MTU value depends on the hardware. Ethernet has a maximum MTU of
* 1500 bytes.
*/
#define ETHERNET_MTU 1500
#define MTU ETHERNET_MTU
/*
* The Maximum amount of data that can be sent in a TCP segment is some what
* less than the MTU. This is because a header is added to the packet
* at each layer (TCP layer, IP layer, and Hardware layer).
* So the max amount of data that can be sent in a segment
* is MTU - (sizeof all headers);
*/
/* Maximum TCP message size */
#ifndef NU_PPP
#define MAX_SEGMENT_LEN (MTU - (sizeof(DLAYER) + sizeof(IPLAYER) + sizeof(TCPLAYER)))
#else
#define MAX_SEGMENT_LEN (MTU - (sizeof (PPP_HEADER) + sizeof(IPLAYER) + sizeof(TCPLAYER)))
#endif
/* Maximum UDP message size */
#ifndef NU_PPP
#define UMAXLEN (MTU - (sizeof(DLAYER) + sizeof(IPLAYER) + sizeof(UDPLAYER)))
#else
#define UMAXLEN (MTU - (sizeof (PPP_HEADER) + sizeof(IPLAYER) + sizeof(UDPLAYER)))
#endif
/************************************************************************/
/* Ethernet frames
* All Ethernet transmissions should use this Ethernet header which
* denotes what type of packet is being sent.
*
* The header is 14 bytes. The first 6 bytes are the target's hardware
* Ethernet address, the second 6 are the sender's hardware address and
* the last two bytes are the packet type. Some packet type definitions
* are included here.
*
* the two-byte packet type is byte-swapped, PC is lo-hi, Ether is hi-lo
*/
#define EXNS 0x0600 /* probably need swapping */
#define EIP 0x0800
#define EARP 0x0806
#define ERARP 0x8035 /* I guess this is RARP */
#define ECHAOS 0x0804
typedef struct ether
{
uint8 dest[DADDLEN]; /* where the packet is going */
uint8 me[DADDLEN]; /* who am i to send this packet */
uint16 type; /* Ethernet packet type */
} DLAYER;
/*************************************************************************/
/* Dave Plummer's Address Resolution Protocol (ARP) (RFC-826) and
* Finlayson, Mann, Mogul and Theimer's Reverse ARP packets.
*
* Note that the 2 byte ints are byte-swapped. The protocols calls for
* in-order bytes, and the PC is lo-hi ordered.
*
*/
#define RARPR 0x0004 /* RARP reply, from host, needs swap */
#define RARPQ 0x0003 /* RARP request, needs swapping */
#define ARPREP 0x0002 /* reply, byte swapped when used */
#define ARPREQ 0x0001 /* request, byte-swapped when used */
#define ARPPRO 0x0800 /* IP protocol, needs swapping */
/********************* Hardware Type Defines ***************************/
#define ETHER 0x0001 /* Ethernet hardware type, needs swapping */
#define HARDWARE_TYPE ETHER
struct tqhdr
{
struct tqe *flink, *blink;
};
/* Define a timer queue element for TCP and IP timer events */
struct tqe
{
struct tqe *flink,
*blink;
struct tqhdr duplist;
UNSIGNED tqe_class,
tqe_event,
tqe_data;
#ifdef PLUS
UNSIGNED duetime;
#else /* PLUS */
int16 duetime;
int16 pad;
#endif /* PLUS */
void (*tqe_callback)();
int32 tqe_ext_data;
};
typedef struct tqe tqe_t;
typedef struct plummer
{
DLAYER d; /* data link layer packet header */
uint16 hrd; /* hardware type, Ethernet = 1 */
uint16 pro; /* protocol type to resolve for */
uint8 hln; /* byte length of hardware addr = 6 for ETNET */
uint8 pln; /* byte length of protocol = 4 for IP */
uint16 op; /* opcode, request = 1, reply = 2, RARP = 3,4 */
uint8 sha[DADDLEN];
uint8 spa[4];
uint8 tha[DADDLEN];
uint8 tpa[4];
/*
* the final four fields (contained in 'rest') are:
* sender hardware address: sha hln bytes
* sender protocol address: spa pln bytes
* target hardware address: tha hln bytes
* target protocol address: tpa pln bytes
*/
} ARPKT;
/***********************************************************************/
/* ARP cache
* Data structure for saving low-level information until needed
*/
struct acache
{
uint8 hrd[DADDLEN], /* hardware address for this IP address */
ip[4], /* the IP # in question */
gate, /* is this a gateway? */
valid_entry; /* Is this a valid entry. For gateways an */
/* entry is created before the HW addr is */
/* known. This flag indicates when the HW */
/* is resolved. */
int32 tm; /* time information */
};
/***********************************************************************/
/* Internet protocol
*
*/
typedef struct iph
{
uint8 versionandhdrlen;
/* I prefer to OR them myself */
/* each half is four bits */
uint8 service; /* type of service for IP */
uint16 tlen, /* total length of IP packet */
ident, /* these are all BYTE-SWAPPED! */
frags; /* combination of flags and value */
uint8 ttl, /* time to live */
protocol; /* higher level protocol type */
uint16 check; /* header checksum, byte-swapped */
uint8 ipsource[4], /* IP addresses */
ipdest[4];
} IPLAYER;
/*
* full IP packet, with data and ip header
*/
typedef struct ip
{
DLAYER d;
IPLAYER i;
union
{
uint8 data[536]; /* largest recommended, may include options */
uint8 options[40];
} x;
} IPKT;
#define PROTUDP 17
#define PROTTCP 6 /* standard protocol types for IP */
#define PROTICMP 1
/************************************************************************/
/* ICMP packet
* all of them are of a similar form, some generic fields are spec'd here.
*/
typedef struct icmph
{
uint8 type, /* ICMP type field */
code; /* ICMP code field */
uint16 check, /* checksum */
part1,part2; /* depends on type and code */
} ICMPLAYER;
typedef struct icmp
{
DLAYER d;
IPLAYER i;
ICMPLAYER c;
uint8 data[ICMPMAX];
} ICMPKT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -