ReactOS  0.4.15-dev-344-g6808e40
icmp.h File Reference
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for icmp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ICMP_HEADER
 

Macros

#define ICMP_TYPE_ECHO_REPLY   0 /* Echo reply */
 
#define ICMP_TYPE_DEST_UNREACH   3 /* Destination unreachable */
 
#define ICMP_TYPE_SOURCE_QUENCH   4 /* Source quench */
 
#define ICMP_TYPE_REDIRECT   5 /* Redirect */
 
#define ICMP_TYPE_ECHO_REQUEST   8 /* Echo request */
 
#define ICMP_TYPE_TIME_EXCEEDED   11 /* Time exceeded */
 
#define ICMP_TYPE_PARAMETER   12 /* Parameter problem */
 
#define ICMP_TYPE_TIMESTAMP_REQUEST   13 /* Timestamp request */
 
#define ICMP_TYPE_TIMESTAMP_REPLY   14 /* Timestamp reply */
 
#define ICMP_TYPE_INFO_REQUEST   15 /* Information request */
 
#define ICMP_TYPE_INFO_REPLY   16 /* Information reply */
 
#define ICMP_CODE_DU_NET_UNREACH   0 /* Network unreachable */
 
#define ICMP_CODE_DU_HOST_UNREACH   1 /* Host unreachable */
 
#define ICMP_CODE_DU_PROTOCOL_UNREACH   2 /* Protocol unreachable */
 
#define ICMP_CODE_DU_PORT_UNREACH   3 /* Port unreachable */
 
#define ICMP_CODE_DU_FRAG_DF_SET   4 /* Fragmentation needed and DF set */
 
#define ICMP_CODE_DU_SOURCE_ROUTE_FAILED   5 /* Source route failed */
 
#define ICMP_CODE_RD_NET   0 /* Redirect datagrams for the network */
 
#define ICMP_CODE_RD_HOST   1 /* Redirect datagrams for the host */
 
#define ICMP_CODE_RD_TOS_NET   2 /* Redirect datagrams for the Type of Service and network */
 
#define ICMP_CODE_RD_TOS_HOST   3 /* Redirect datagrams for the Type of Service and host */
 
#define ICMP_CODE_TE_TTL   0 /* Time to live exceeded in transit */
 
#define ICMP_CODE_TE_REASSEMBLY   1 /* Fragment reassembly time exceeded */
 
#define ICMP_CODE_TP_POINTER   1 /* Pointer indicates the error */
 

Typedefs

typedef struct ICMP_HEADER ICMP_HEADER
 
typedef struct ICMP_HEADERPICMP_HEADER
 

Functions

NTSTATUS DispEchoRequest (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS ICMPSendDatagram (PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR BufferData, ULONG DataSize, PULONG DataUsed)
 
NTSTATUS ICMPStartup (VOID)
 
NTSTATUS ICMPShutdown (VOID)
 
VOID ICMPReceive (PIP_INTERFACE Interface, PIP_PACKET IPPacket)
 
VOID ICMPReply (PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
 

Macro Definition Documentation

◆ ICMP_CODE_DU_FRAG_DF_SET

#define ICMP_CODE_DU_FRAG_DF_SET   4 /* Fragmentation needed and DF set */

Definition at line 38 of file icmp.h.

◆ ICMP_CODE_DU_HOST_UNREACH

#define ICMP_CODE_DU_HOST_UNREACH   1 /* Host unreachable */

Definition at line 35 of file icmp.h.

◆ ICMP_CODE_DU_NET_UNREACH

#define ICMP_CODE_DU_NET_UNREACH   0 /* Network unreachable */

Definition at line 34 of file icmp.h.

◆ ICMP_CODE_DU_PORT_UNREACH

#define ICMP_CODE_DU_PORT_UNREACH   3 /* Port unreachable */

Definition at line 37 of file icmp.h.

◆ ICMP_CODE_DU_PROTOCOL_UNREACH

#define ICMP_CODE_DU_PROTOCOL_UNREACH   2 /* Protocol unreachable */

Definition at line 36 of file icmp.h.

◆ ICMP_CODE_DU_SOURCE_ROUTE_FAILED

#define ICMP_CODE_DU_SOURCE_ROUTE_FAILED   5 /* Source route failed */

Definition at line 39 of file icmp.h.

◆ ICMP_CODE_RD_HOST

#define ICMP_CODE_RD_HOST   1 /* Redirect datagrams for the host */

Definition at line 43 of file icmp.h.

◆ ICMP_CODE_RD_NET

#define ICMP_CODE_RD_NET   0 /* Redirect datagrams for the network */

Definition at line 42 of file icmp.h.

◆ ICMP_CODE_RD_TOS_HOST

#define ICMP_CODE_RD_TOS_HOST   3 /* Redirect datagrams for the Type of Service and host */

Definition at line 45 of file icmp.h.

◆ ICMP_CODE_RD_TOS_NET

#define ICMP_CODE_RD_TOS_NET   2 /* Redirect datagrams for the Type of Service and network */

Definition at line 44 of file icmp.h.

◆ ICMP_CODE_TE_REASSEMBLY

#define ICMP_CODE_TE_REASSEMBLY   1 /* Fragment reassembly time exceeded */

Definition at line 49 of file icmp.h.

◆ ICMP_CODE_TE_TTL

#define ICMP_CODE_TE_TTL   0 /* Time to live exceeded in transit */

Definition at line 48 of file icmp.h.

◆ ICMP_CODE_TP_POINTER

#define ICMP_CODE_TP_POINTER   1 /* Pointer indicates the error */

Definition at line 52 of file icmp.h.

◆ ICMP_TYPE_DEST_UNREACH

#define ICMP_TYPE_DEST_UNREACH   3 /* Destination unreachable */

Definition at line 22 of file icmp.h.

◆ ICMP_TYPE_ECHO_REPLY

#define ICMP_TYPE_ECHO_REPLY   0 /* Echo reply */

Definition at line 21 of file icmp.h.

◆ ICMP_TYPE_ECHO_REQUEST

#define ICMP_TYPE_ECHO_REQUEST   8 /* Echo request */

Definition at line 25 of file icmp.h.

◆ ICMP_TYPE_INFO_REPLY

#define ICMP_TYPE_INFO_REPLY   16 /* Information reply */

Definition at line 31 of file icmp.h.

◆ ICMP_TYPE_INFO_REQUEST

#define ICMP_TYPE_INFO_REQUEST   15 /* Information request */

Definition at line 30 of file icmp.h.

◆ ICMP_TYPE_PARAMETER

#define ICMP_TYPE_PARAMETER   12 /* Parameter problem */

Definition at line 27 of file icmp.h.

◆ ICMP_TYPE_REDIRECT

#define ICMP_TYPE_REDIRECT   5 /* Redirect */

Definition at line 24 of file icmp.h.

◆ ICMP_TYPE_SOURCE_QUENCH

#define ICMP_TYPE_SOURCE_QUENCH   4 /* Source quench */

Definition at line 23 of file icmp.h.

◆ ICMP_TYPE_TIME_EXCEEDED

#define ICMP_TYPE_TIME_EXCEEDED   11 /* Time exceeded */

Definition at line 26 of file icmp.h.

◆ ICMP_TYPE_TIMESTAMP_REPLY

#define ICMP_TYPE_TIMESTAMP_REPLY   14 /* Timestamp reply */

Definition at line 29 of file icmp.h.

◆ ICMP_TYPE_TIMESTAMP_REQUEST

#define ICMP_TYPE_TIMESTAMP_REQUEST   13 /* Timestamp request */

Definition at line 28 of file icmp.h.

Typedef Documentation

◆ ICMP_HEADER

◆ PICMP_HEADER

Function Documentation

◆ DispEchoRequest()

NTSTATUS DispEchoRequest ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Referenced by TiDispatch().

◆ ICMPReceive()

VOID ICMPReceive ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket 
)

Definition at line 53 of file icmp.c.

62 {
63  PICMP_HEADER ICMPHeader = (PICMP_HEADER)IPPacket->Data;
64  UINT32 DataSize = IPPacket->TotalSize - IPPacket->HeaderSize;
65 
66  TI_DbgPrint(DEBUG_ICMP, ("ICMPReceive: Size (%d) HeaderSize (%d) Type (%d) Code (%d) Checksum (0x%x)\n",
67  IPPacket->TotalSize, IPPacket->HeaderSize, ICMPHeader->Type, ICMPHeader->Code, ICMPHeader->Checksum));
68 
69  /* Discard too short packets */
70  if (DataSize < sizeof(ICMP_HEADER))
71  {
72  TI_DbgPrint(DEBUG_ICMP, ("Packet doesn't fit ICMP header. Discarded\n"));
73  return;
74  }
75 
76  /* Discard packets with bad checksum */
77  if (!IPv4CorrectChecksum(IPPacket->Data, DataSize))
78  {
79  TI_DbgPrint(DEBUG_ICMP, ("Bad ICMP checksum. Packet discarded\n"));
80  return;
81  }
82 
83  RawIpReceive(Interface, IPPacket);
84 
85  if (ICMPHeader->Type == ICMP_TYPE_ECHO_REQUEST)
86  {
88  }
89 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
UINT8 Type
Definition: icmp.h:12
VOID ICMPReply(PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
Definition: icmp.c:91
PVOID Data
Definition: ip.h:85
unsigned int UINT32
#define DEBUG_ICMP
Definition: debug.h:29
#define ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:25
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
UINT16 Checksum
Definition: icmp.h:14
#define ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:21
UINT TotalSize
Definition: ip.h:86
UINT8 Code
Definition: icmp.h:13
UINT HeaderSize
Definition: ip.h:84
VOID RawIpReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: rawip.c:267
struct ICMP_HEADER * PICMP_HEADER
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
#define IPv4CorrectChecksum(Data, Count)
Definition: checksum.h:38

Referenced by ICMPStartup().

◆ ICMPReply()

VOID ICMPReply ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket,
UCHAR  Type,
UCHAR  Code 
)

Definition at line 91 of file icmp.c.

109 {
110  UINT DataSize;
111  IP_PACKET NewPacket;
112  ADDRESS_FILE FakeAddrFile;
114 
115  TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code));
116 
117  DataSize = IPPacket->TotalSize - IPPacket->HeaderSize;
118 
119  /* First check if we have a route to sender */
120  NCE = RouteGetRouteToDestination(&IPPacket->SrcAddr);
121  if (!NCE)
122  {
123  return;
124  }
125 
126  /* This is the only data needed to generate a packet */
127  FakeAddrFile.Protocol = IPPROTO_ICMP;
128  FakeAddrFile.TTL = 128;
129 
131  &FakeAddrFile, &NewPacket, &IPPacket->SrcAddr, 0, &Interface->Unicast, 0, IPPacket->Data, DataSize)))
132  {
133  return;
134  }
135 
136  ((PICMP_HEADER)NewPacket.Data)->Type = Type;
137  ((PICMP_HEADER)NewPacket.Data)->Code = Code;
138  ((PICMP_HEADER)NewPacket.Data)->Checksum = 0;
139  ((PICMP_HEADER)NewPacket.Data)->Checksum = (USHORT)IPv4Checksum(NewPacket.Data, DataSize, 0);
140 
141  IPSendDatagram(&NewPacket, NCE);
142 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
Type
Definition: Type.h:6
UCHAR TTL
Definition: titypes.h:141
Definition: neighbor.h:28
IP_ADDRESS SrcAddr
Definition: ip.h:89
USHORT Protocol
Definition: titypes.h:138
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
PVOID Data
Definition: ip.h:85
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
#define IPv4Checksum(Data, Count, Seed)
Definition: checksum.h:30
#define DEBUG_ICMP
Definition: debug.h:29
#define Code
Definition: deflate.h:80
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UINT TotalSize
Definition: ip.h:86
NTSTATUS BuildRawIpPacket(PADDRESS_FILE AddrFile, PIP_PACKET Packet, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PCHAR DataBuffer, UINT DataLen)
Definition: rawip.c:86
UINT HeaderSize
Definition: ip.h:84
unsigned short USHORT
Definition: pedump.c:61
unsigned int UINT
Definition: ndis.h:50
struct ICMP_HEADER * PICMP_HEADER
Definition: ip.h:77
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by ICMPReceive().

◆ ICMPSendDatagram()

NTSTATUS ICMPSendDatagram ( PADDRESS_FILE  AddrFile,
PTDI_CONNECTION_INFORMATION  ConnInfo,
PCHAR  BufferData,
ULONG  DataSize,
PULONG  DataUsed 
)

Definition at line 29 of file icmp.c.

45 {
46  TI_DbgPrint(DEBUG_ICMP, ("Sending ICMP datagram (0x%x)\n", AddrFile));
47 
48  /* just forward the call to RawIP handler */
49  return RawIPSendDatagram(AddrFile, ConnInfo, BufferData, DataSize, DataUsed);
50 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define DEBUG_ICMP
Definition: debug.h:29
NTSTATUS RawIPSendDatagram(PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR Buffer, ULONG DataSize, PULONG DataUsed)
Definition: rawip.c:171
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by FileOpenAddress().

◆ ICMPShutdown()

NTSTATUS ICMPShutdown ( VOID  )

Referenced by TiUnload().

◆ ICMPStartup()

NTSTATUS ICMPStartup ( VOID  )

Referenced by DriverEntry().