www.pudn.com > AcquireEthernetCode.rar > protocol.h


#include "ntddndis.h" 
 
#define UNICODE 1 
 
#define __LITTLE_ENDIAN_BITFIELD 
 
#pragma pack(push) 
#pragma pack(1) 
 
typedef unsigned char __u8; 
typedef unsigned short __u16; 
typedef unsigned int __u32; 
 
/************************************************/ 
/*  PROTOCOL DATA STRUCTURE                     */ 
/************************************************/ 
 
/* Frame type field must be "8" 
|   6 Bytes         |    6 Bytes       |  2 Bytes  | 
--------------------------------------------------------------- 
|Destination address|  Source address  |Frame type | Frame data 
--------------------------------------------------------------- 
*/ 
 
/* 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]       Ethernet destination address (first 32 bits)            ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ] Ethernet dest (last 16 bits)  ]Ethernet source (first 16 bits)] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]       Ethernet source address (last 32 bits)                  ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]        Type code              ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]  IP header, then TCP header, then your data                   ] 
    ]                                                               ] 
        ... 
    ]                                                               ] 
    ]   end of your data                                            ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]                       Ethernet Checksum                       ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
*/ 
typedef struct _ETH_HEADER 
{ 
    unsigned char   h_dest[6]; 
    unsigned char   h_source[6]; 
    unsigned short  h_proto; 
}ETH_HEADER; 
 
/* 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]Version]  IHL  ]Type of Service]          Total Length         ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]         Identification        ]Flags]      Fragment Offset    ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]  Time to Live ]    Protocol   ]         Header Checksum       ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]                       Source Address                          ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]                    Destination Address                        ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]  TCP header, then your data ......                            ] 
    ]                                                               ] 
*/ 
typedef struct _IP_HEADER 
{ 
#if defined(__LITTLE_ENDIAN_BITFIELD) 
	__u8	        ihl:4, 
		            version:4; 
#elif defined (__BIG_ENDIAN_BITFIELD) 
	__u8	        version:4, 
  		            ihl:4; 
#endif 
    __u8            tos; 
    __u16           tot_len; 
    __u16           id; 
    __u16           frag_off; 
    __u8            ttl; 
    __u8            protocol; 
    __u16           check; 
    __u32           saddr; 
    __u32           daddr; 
}               IP_HEADER; 
 
/* 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]          Source Port          ]       Destination Port        ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]                        Sequence Number                        ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]                    Acknowledgment Number                      ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]  Data ]           ]U]A]P]R]S]F]                               ] 
    ] Offset] Reserved  ]R]C]S]S]Y]I]            Window             ] 
    ]       ]           ]G]K]H]T]N]N]                               ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]           Checksum            ]         Urgent Pointer        ] 
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    ]   your data ... next 500 octets                               ] 
    ]   ......                                                      ] 
*/ 
typedef struct _TCP_HEADER 
{ 
    __u16           source; 
    __u16           dest; 
    __u32           seq; 
    __u32           ack_seq; 
#if defined(__LITTLE_ENDIAN_BITFIELD) 
	__u16	        res1:4, 
		            doff:4, 
		            fin:1, 
		            syn:1, 
		            rst:1, 
		            psh:1, 
		            ack:1, 
		            urg:1, 
		            res2:2; 
#elif defined(__BIG_ENDIAN_BITFIELD) 
	__u16	        doff:4, 
		            res1:4, 
		            res2:2, 
		            urg:1, 
		            ack:1, 
		            psh:1, 
		            rst:1, 
		            syn:1, 
		            fin:1; 
#endif	 
    __u16           window; 
    __u16           check; 
    __u16           urg_ptr; 
}               TCP_HEADER; 
 
typedef struct _ETHER_PACKET 
{ 
    ETH_HEADER      ETH; 
    IP_HEADER       IP; 
    TCP_HEADER      TCP; 
}ETHER_PACKET; 
 
 
typedef struct _CONTROL_BLOCK 
{ 
    PVOID       hFile; 
    HANDLE      hEvent; 
    TCHAR       AdapterName[128]; 
 
    HANDLE      hMem; 
    LPBYTE      lpMem; 
 
    ULONG       PacketLength; 
    ULONG       LastReadSize; 
    UINT        BufferSize; 
}CONTROL_BLOCK, *PCONTROL_BLOCK; 
 
#pragma pack(pop) 
/* 
#define   MAX_LINK_NAME_LENGTH   64 
typedef struct _ADAPTER { 
    HANDLE     hFile; 
    TCHAR      SymbolicLink[MAX_LINK_NAME_LENGTH]; 
}ADAPTER, *LPADAPTER; 
typedef struct _PACKET { 
    HANDLE       hEvent; 
    OVERLAPPED   OverLapped; 
    PVOID        Buffer; 
    UINT         Length; 
} PACKET, *LPPACKET; 
 
extern "C" 
{ 
	ULONG PacketGetAdapterNames(PTSTR   pStr,PULONG  BufferSize); 
	PVOID PacketOpenAdapter(LPTSTR   AdapterName); 
	VOID  PacketCloseAdapter(LPADAPTER   lpAdapter); 
	BOOLEAN PacketSetFilter(LPADAPTER  AdapterObject,ULONG      Filter); 
	PVOID PacketAllocatePacket(LPADAPTER   AdapterObject); 
	VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length); 
	VOID PacketFreePacket( LPPACKET    lpPacket  ); 
#ifdef WINNT 
	BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync,PULONG BytesReceived); 
#else 
	BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync,PULONG BytesReceived,int shitbuski); 
#endif 
}*/ 
#include "./packet32/packet32.h"