You need to byte swap the fields into network byte order. Windows offers RtlUshortByteSwap, and the compiler offers _byteswap_ushort.
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, February 24, 2011 3:03 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Packet Dissection
The problem is the converstion from IP to the TCP as the values are incorrect (SPORT and DPORT)
I am using the following Structures for converstion (Based on the Extended PassThrough Driver)
typedef struct _IP_V4
{
#if BYTE_ORDER == LITTLE_ENDIAN
UCHAR IP_hl:4, IP_v:4;
#endif
#if BYTE_ORDER == BIG_ENDIAN
UCHAR IP_v:4, IP_hl:4;
#endif
UCHAR IP_tos;
USHORT IP_len;
USHORT IP_id;
USHORT IP_off;
#define IP_RF 0x8000
#define IP_DF 0x4000
#define IP_MF 0x2000
#define IP_OFFMASK 0x1fff
UCHAR IP_ttl;
UCHAR IP_p;
USHORT IP_sum;
IPV4_ADDRESS IP_src,IP_dst;
} IP_V4, *PIP_V4;
–
typedef struct TCP_HEADER
{
USHORT TCP_SPort;
USHORT TCP_DPort;
ULONG TCP_Seq;
ULONG TCP_Ack;
#if BYTE_ORDER == LITTLE_ENDIAN
UINT TCP_X2:4, //(unused)
TCP_Off:4; // data offset
#endif
#if BYTE_ORDER == BIG_ENDIAN
UINT TCP_Off:4, //data offset
TCP_X2:4; // (unused)
#endif
UCHAR TCP_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
#define TH_ECE 0x40
#define TH_CWR 0x80
#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
USHORT TCP_Win; // window
USHORT TCP_Sum; // checksum
USHORT TCP_Urp; // urgent pointer
} TCP_HDR, *PTCP_HDR;
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer