ReactOS  0.4.14-dev-49-gfb4591c
routines.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS TCP/IP protocol driver
4  * FILE: tcpip/routines.c
5  * PURPOSE: Common routines
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * REVISIONS:
8  * CSH 01/08-2000 Created
9  */
10 
11 #include "precomp.h"
12 
13 static UINT RandomNumber = 0x12345678;
14 
15 
17  VOID)
18 /*
19  * FUNCTION: Returns a pseudo random number
20  * RETURNS:
21  * Pseudo random number
22  */
23 {
24  RandomNumber ^= 0x78563412;
25 
26  return RandomNumber;
27 }
28 
29 #if DBG
30 static VOID DisplayIPHeader(
31  PCHAR Header,
32  UINT Length)
33 {
34  /* FIXME: IPv4 only */
35  PIPv4_HEADER IPHeader = (PIPv4_HEADER)Header;
36 
37  DbgPrint("IPv4 header:\n");
38  DbgPrint("VerIHL: 0x%x (version 0x%x, length %d 32-bit words)\n",
39  IPHeader->VerIHL, (IPHeader->VerIHL & 0xF0) >> 4, IPHeader->VerIHL & 0x0F);
40  DbgPrint(" Tos: %d\n", IPHeader->Tos);
41  DbgPrint(" TotalLength: %d\n", WN2H(IPHeader->TotalLength));
42  DbgPrint(" Id: %d\n", WN2H(IPHeader->Id));
43  DbgPrint(" FlagsFragOfs: 0x%x (offset 0x%x)\n", WN2H(IPHeader->FlagsFragOfs), WN2H(IPHeader->FlagsFragOfs) & IPv4_FRAGOFS_MASK);
44  if ((WN2H(IPHeader->FlagsFragOfs) & IPv4_DF_MASK) > 0) DbgPrint(" IPv4_DF - Don't fragment\n");
45  if ((WN2H(IPHeader->FlagsFragOfs) & IPv4_MF_MASK) > 0) DbgPrint(" IPv4_MF - More fragments\n");
46  DbgPrint(" Ttl: %d\n", IPHeader->Ttl);
47  DbgPrint(" Protocol: %d\n", IPHeader->Protocol);
48  DbgPrint(" Checksum: 0x%x\n", WN2H(IPHeader->Checksum));
49  DbgPrint(" SrcAddr: %d.%d.%d.%d\n",
50  ((IPHeader->SrcAddr >> 0) & 0xFF), ((IPHeader->SrcAddr >> 8) & 0xFF),
51  ((IPHeader->SrcAddr >> 16) & 0xFF), ((IPHeader->SrcAddr >> 24) & 0xFF));
52  DbgPrint(" DstAddr: %d.%d.%d.%d\n",
53  ((IPHeader->DstAddr >> 0) & 0xFF), ((IPHeader->DstAddr >> 8) & 0xFF),
54  ((IPHeader->DstAddr >> 16) & 0xFF), ((IPHeader->DstAddr >> 24) & 0xFF));
55 }
56 
57 #endif
58 
60  PIP_PACKET IPPacket)
61 {
62 #if DBG
63  UINT Length;
64  PCHAR CharBuffer;
65 
66  /* DbgQueryDebugFilterState returns (NTSTATUS)TRUE, (NTSTATUS)FALSE or a failure status code */
69  return;
70  }
71 
72  if (!IPPacket) {
73  TI_DbgPrint(MIN_TRACE, ("Cannot display null packet.\n"));
74  return;
75  }
76 
77  TI_DbgPrint(MIN_TRACE, ("IPPacket is at (0x%X).\n", IPPacket));
78  TI_DbgPrint(MIN_TRACE, ("Header buffer is at (0x%X).\n", IPPacket->Header));
79  TI_DbgPrint(MIN_TRACE, ("Header size is (%d).\n", IPPacket->HeaderSize));
80  TI_DbgPrint(MIN_TRACE, ("TotalSize (%d).\n", IPPacket->TotalSize));
81  TI_DbgPrint(MIN_TRACE, ("NdisPacket (0x%X).\n", IPPacket->NdisPacket));
82 
83  CharBuffer = IPPacket->Header;
84  Length = IPPacket->HeaderSize;
85  DisplayIPHeader(CharBuffer, Length);
86 #endif
87 }
88 
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
UINT Random(VOID)
Definition: routines.c:16
#define TRUE
Definition: types.h:120
UCHAR Tos
Definition: ip.h:39
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
#define DPFLTR_MASK
Definition: kdtypes.h:34
USHORT TotalLength
Definition: ip.h:40
static UINT RandomNumber
Definition: routines.c:13
#define IPv4_DF_MASK
Definition: ip.h:67
USHORT FlagsFragOfs
Definition: ip.h:42
Definition: Header.h:8
UCHAR VerIHL
Definition: ip.h:38
PVOID Header
Definition: ip.h:83
UCHAR Ttl
Definition: ip.h:43
#define DEBUG_IP
Definition: debug.h:26
#define IPv4_MF_MASK
Definition: ip.h:66
UINT TotalSize
Definition: ip.h:86
IPv4_RAW_ADDRESS DstAddr
Definition: ip.h:47
#define WN2H(w)
Definition: addrconv.c:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
UCHAR Protocol
Definition: ip.h:44
#define DEBUG_PBUFFER
Definition: debug.h:20
UINT HeaderSize
Definition: ip.h:84
USHORT Checksum
Definition: ip.h:45
#define IPv4_FRAGOFS_MASK
Definition: ip.h:65
IPv4_RAW_ADDRESS SrcAddr
Definition: ip.h:46
unsigned int UINT
Definition: ndis.h:50
PNDIS_PACKET NdisPacket
Definition: ip.h:88
Definition: ip.h:37
#define MIN_TRACE
Definition: debug.h:14
Definition: ip.h:77
USHORT Id
Definition: ip.h:41
struct IPv4_HEADER * PIPv4_HEADER
VOID DisplayIPPacket(PIP_PACKET IPPacket)
Definition: routines.c:59
NTSYSAPI NTSTATUS NTAPI DbgQueryDebugFilterState(_In_ ULONG ComponentId, _In_ ULONG Level)