ReactOS 0.4.16-dev-297-gc569aee
icmp.c File Reference
#include "precomp.h"
#include <icmp.h>
Include dependency graph for icmp.c:

Go to the source code of this file.

Functions

NTSTATUS ICMPStartup ()
 
NTSTATUS ICMPShutdown ()
 
NTSTATUS ICMPSendDatagram (PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR BufferData, ULONG DataSize, PULONG DataUsed)
 
VOID ICMPReceive (PIP_INTERFACE Interface, PIP_PACKET IPPacket)
 
VOID ICMPReply (PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
 

Function Documentation

◆ 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}
unsigned int UINT32
#define IPv4CorrectChecksum(Data, Count)
Definition: checksum.h:38
#define DEBUG_ICMP
Definition: debug.h:29
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID ICMPReply(PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
Definition: icmp.c:91
#define ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:21
#define ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:25
struct ICMP_HEADER * PICMP_HEADER
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
VOID RawIpReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: rawip.c:266
UINT8 Type
Definition: icmp.h:12
UINT16 Checksum
Definition: icmp.h:14
UINT8 Code
Definition: icmp.h:13
PVOID Data
Definition: ip.h:85
UINT HeaderSize
Definition: ip.h:84
UINT TotalSize
Definition: ip.h:86
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465

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{
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}
Type
Definition: Type.h:7
#define IPv4Checksum(Data, Count, Seed)
Definition: checksum.h:30
#define Code
Definition: deflate.h:80
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define IPPROTO_ICMP
Definition: ip.h:194
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
unsigned int UINT
Definition: ndis.h:50
unsigned short USHORT
Definition: pedump.c:61
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
Definition: neighbor.h:28
UCHAR TTL
Definition: titypes.h:122
USHORT Protocol
Definition: titypes.h:119
Definition: ip.h:77
IP_ADDRESS SrcAddr
Definition: ip.h:89
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701

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}
NTSTATUS RawIPSendDatagram(PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR Buffer, ULONG DataSize, PULONG DataUsed)
Definition: rawip.c:171

Referenced by FileOpenAddress().

◆ ICMPShutdown()

NTSTATUS ICMPShutdown ( )

Definition at line 22 of file icmp.c.

23{
25
26 return STATUS_SUCCESS;
27}
#define NULL
Definition: types.h:112
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:386
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by TiUnload().

◆ ICMPStartup()

NTSTATUS ICMPStartup ( )

Definition at line 15 of file icmp.c.

16{
18
19 return STATUS_SUCCESS;
20}
VOID ICMPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: icmp.c:53

Referenced by DriverEntry().