NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
PacketHeader.h
1/************************************************************************************
2 * Copyright (C) 2023 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi kant suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#ifndef _PACKET_HEADER_H_
15#define _PACKET_HEADER_H_
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifndef _WIN32
21#include <sys/socket.h>
22#include <netinet/in.h>
23#include <netinet/tcp.h>
24
25#define ERROR_INVALID_PARAMETER EINVAL
26#else
27
28#define INT8 char
29#define UINT8 unsigned char
30#define INT16 short
31#define UINT16 unsigned short
32#define INT32 int
33#define UINT32 unsigned int
34#define INT64 long long int
35#define UINT64 unsigned long long int
36#define UINT unsigned int
37
38#endif
39
40
41
42/*
43 * Flags for DivertHelperCalcChecksums()
44 */
45#define WINDIVERT_HELPER_NO_IP_CHECKSUM 1
46#define WINDIVERT_HELPER_NO_ICMP_CHECKSUM 2
47#define WINDIVERT_HELPER_NO_ICMPV6_CHECKSUM 4
48#define WINDIVERT_HELPER_NO_TCP_CHECKSUM 8
49#define WINDIVERT_HELPER_NO_UDP_CHECKSUM 16
50
51
52#ifndef _WIN32
53//****** From ipmib.h from windows ******/
54// ICMP4_TYPE
55//
56// There are no RFC-specified defines for ICMPv4 message types, so we try to
57// use the ICMP6 values from RFC 2292 modified to be prefixed with ICMP4.
58//
59typedef enum {
60 ICMP4_ECHO_REPLY = 0, // Echo Reply.
61 ICMP4_DST_UNREACH = 3, // Destination Unreachable.
62 ICMP4_SOURCE_QUENCH = 4, // Source Quench.
63 ICMP4_REDIRECT = 5, // Redirect.
64 ICMP4_ECHO_REQUEST = 8, // Echo Request.
65 ICMP4_ROUTER_ADVERT = 9, // Router Advertisement.
66 ICMP4_ROUTER_SOLICIT = 10, // Router Solicitation.
67 ICMP4_TIME_EXCEEDED = 11, // Time Exceeded.
68 ICMP4_PARAM_PROB = 12, // Parameter Problem.
69 ICMP4_TIMESTAMP_REQUEST = 13, // Timestamp Request.
70 ICMP4_TIMESTAMP_REPLY = 14, // Timestamp Reply.
71 ICMP4_MASK_REQUEST = 17, // Address Mask Request.
72 ICMP4_MASK_REPLY = 18, // Address Mask Reply.
73} ICMP4_TYPE, *PICMP4_TYPE;
74
75#endif
76/*
77 * IPv4/IPv6/ICMP/ICMPv6/TCP/UDP header definitions.
78 */
79typedef struct
80{
81 UINT8 HdrLength:4;
82 UINT8 Version:4;
83 UINT8 TOS;
84 UINT16 Length;
85 UINT16 Id;
86 UINT16 FragOff0;
87 UINT8 TTL;
88 UINT8 Protocol;
89 UINT16 Checksum;
90 UINT32 SrcAddr;
91 UINT32 DstAddr;
92} WINDIVERT_IPHDR, *PWINDIVERT_IPHDR;
93
94
95
96typedef struct
97{
98 UINT8 TrafficClass0:4;
99 UINT8 Version:4;
100 UINT8 FlowLabel0:4;
101 UINT8 TrafficClass1:4;
102 UINT16 FlowLabel1;
103 UINT16 Length;
104 UINT8 NextHdr;
105 UINT8 HopLimit;
106 UINT32 SrcAddr[4];
107 UINT32 DstAddr[4];
108} WINDIVERT_IPV6HDR, *PWINDIVERT_IPV6HDR;
109
110#define IPV6_HDR_SIZE 40 //Bytes
111
112typedef struct
113{
114 UINT8 Type;
115 UINT8 Code;
116 UINT16 Checksum;
117 UINT32 Body;
118} WINDIVERT_ICMPHDR, *PWINDIVERT_ICMPHDR;
119
120typedef struct
121{
122 UINT8 Type;
123 UINT8 Code;
124 UINT16 Checksum;
125 UINT32 Body;
126} WINDIVERT_ICMPV6HDR, *PWINDIVERT_ICMPV6HDR;
127
128typedef struct
129{
130 UINT16 SrcPort;
131 UINT16 DstPort;
132 UINT32 SeqNum;
133 UINT32 AckNum;
134 UINT16 Reserved1:4;
135 UINT16 HdrLength:4;
136 UINT16 Fin:1;
137 UINT16 Syn:1;
138 UINT16 Rst:1;
139 UINT16 Psh:1;
140 UINT16 Ack:1;
141 UINT16 Urg:1;
142 UINT16 Reserved2:2;
143 UINT16 Window;
144 UINT16 Checksum;
145 UINT16 UrgPtr;
146} WINDIVERT_TCPHDR, *PWINDIVERT_TCPHDR;
147
148typedef struct
149{
150 UINT16 SrcPort;
151 UINT16 DstPort;
152 UINT16 Length;
153 UINT16 Checksum;
154} WINDIVERT_UDPHDR, *PWINDIVERT_UDPHDR;
155
156
157BOOL WinDivertHelperParsePacket(PVOID pPacket, UINT packetLen,
158 PWINDIVERT_IPHDR *ppIpHdr, PWINDIVERT_IPV6HDR *ppIpv6Hdr,
159 PWINDIVERT_ICMPHDR *ppIcmpHdr, PWINDIVERT_ICMPV6HDR *ppIcmpv6Hdr,
160 PWINDIVERT_TCPHDR *ppTcpHdr, PWINDIVERT_UDPHDR *ppUdpHdr, PVOID *ppData,
161 UINT *pDataLen);
162
163UINT WinDivertHelperCalcChecksums(PVOID pPacket, UINT packetLen,
164 UINT64 flags);
165BOOL WinDivertHelperParseIPv4Address(const char *str, UINT32 *addr_ptr);
166BOOL WinDivertHelperParseIPv6Address(const char *str, UINT32 *addr_ptr);
167
168#ifdef __cplusplus
169}
170#endif
171#endif //_PACKET_HEADER_H_
172