ReactOS 0.4.15-dev-8419-g7f0e8a3
lantest.cpp File Reference
#include <windows.h>
#include <net/lan.h>
#include <iostream>
#include <string>
#include <ddk/ntddk.h>
#include <rosrtl/string.h>
Include dependency graph for lantest.cpp:

Go to the source code of this file.

Macros

#define ETYPE_IPv4   WH2N(0x0800)
 
#define ETYPE_IPv6   WH2N(0x86DD)
 
#define ETYPE_ARP   WH2N(0x0806)
 

Functions

void display_row (char *data, int off, int len)
 
void display_buffer (char *Packet, int ReadLen)
 
int byte_till_end (char *Packet, int PktLen)
 
NTSTATUS NTAPI NtCreateFile (PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, PLARGE_INTEGER AllocationSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ ETYPE_ARP

#define ETYPE_ARP   WH2N(0x0806)

Definition at line 59 of file lantest.cpp.

◆ ETYPE_IPv4

#define ETYPE_IPv4   WH2N(0x0800)

Definition at line 57 of file lantest.cpp.

◆ ETYPE_IPv6

#define ETYPE_IPv6   WH2N(0x86DD)

Definition at line 58 of file lantest.cpp.

Function Documentation

◆ byte_till_end()

int byte_till_end ( char Packet,
int  PktLen 
)

Definition at line 40 of file lantest.cpp.

40 {
41 int byte;
42 std::string word;
43
44 cin >> word;
45 while( word != "end" ) {
46 byte = strtoul( (string("0x") + word).c_str(), 0, 0 );
47 fprintf( stderr, "Byte[%d]: %x\n", PktLen, byte & 0xff );
48 Packet[PktLen++] = byte;
49 cin >> word;
50 }
51
52 return PktLen;
53}
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define byte(x, n)
Definition: tomcrypt.h:118
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define cin
Definition: iostream.cpp:37
const WCHAR * word
Definition: lex.c:36
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549

Referenced by main().

◆ display_buffer()

void display_buffer ( char Packet,
int  ReadLen 
)

Definition at line 34 of file lantest.cpp.

34 {
35 UINT PktLen;
36 for( PktLen = 0; PktLen < ReadLen; PktLen += 16 )
37 display_row( Packet, PktLen, ReadLen );
38}
void display_row(char *data, int off, int len)
Definition: lantest.cpp:14
unsigned int UINT
Definition: ndis.h:50

Referenced by main().

◆ display_row()

void display_row ( char data,
int  off,
int  len 
)

Definition at line 14 of file lantest.cpp.

14 {
15 int i;
16
17 printf( "%08x:", off );
18 for( i = off; i < len && i < off + 16; i++ ) {
19 printf( " %02x", data[i] & 0xff );
20 }
21
22 for( ; i < off + 16; i++ )
23 printf(" ");
24
25 printf( " -- " );
26
27 for( i = off; i < len && i < off + 16; i++ ) {
28 printf( "%c", (data[i] >= ' ' && data[i] <= '~') ? data[i] : '.' );
29 }
30
31 printf( "\n" );
32}
#define printf
Definition: freeldr.h:97
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by display_buffer().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 75 of file lantest.cpp.

75 {
76 string word;
77 HANDLE LanFile;
79 UNICODE_STRING LanDevice;
84 DWORD On = 1, PktLen;
85 CHAR Packet[1600];
88 USHORT TypesToListen[] = { ETYPE_IPv4, ETYPE_IPv6, ETYPE_ARP };
89 UINT EaLength = LAN_EA_INFO_SIZE(sizeof(TypesToListen)/sizeof(USHORT));
90
93 NULL,
94 0,
95 0 );
96
97 RtlInitUnicodeString( &LanDevice, L"\\Device\\Lan" );
98
100 &LanDevice,
102 NULL,
103 NULL );
104
106 LAN_FILL_EA_INFO(EaBuffer,sizeof(TypesToListen)/sizeof(USHORT),
107 TypesToListen);
108
109 Status = ZwCreateFile( &LanFile,
112 &Attributes,
113 &Iosb,
114 NULL,
119 EaBuffer,
120 EaLength );
121
122 if( !NT_SUCCESS(Status) ) {
123 cerr << "Could not open lan device " << Status << "\n";
124 return 1;
125 }
126
127 Status = DeviceIoControl( LanFile,
129 &On,
130 sizeof(On),
131 0,
132 0,
133 &PktLen,
134 NULL );
135
136 if( !Status ) {
137 cerr << "Could not turn on buffered mode " << Status << "\n";
138 return 1;
139 }
140
141 while( cin >> word ) {
142 if( word == "end" ) {
143 NtClose( LanFile );
144 return 0;
145 } else if( word == "enum" ) {
146 Status = DeviceIoControl( LanFile,
148 NULL,
149 0,
150 Packet,
151 sizeof(Packet),
152 &PktLen,
153 NULL );
154
155 cout << "EnumAdapters: " << Status << "\n";
156 if( Status )
157 display_buffer( Packet, PktLen );
158 } else if( word == "query" ) {
159 cin >> PktLen;
160
161 Status = DeviceIoControl( LanFile,
163 &PktLen,
164 sizeof(PktLen),
165 Packet,
166 sizeof(Packet),
167 &PktLen,
168 NULL );
169
170 cout << "QueryAdapterInfo: " << Status << "\n";
171 if( Status )
172 display_buffer( Packet, PktLen );
173 } else if( word == "send" ) {
174 cin >> Hdr->Fixed.Adapter
175 >> Hdr->Fixed.AddressType
176 >> Hdr->Fixed.AddressLen
177 >> Hdr->Fixed.PacketType;
178 Hdr->Fixed.Mdl = NULL;
179 PktLen = byte_till_end( Packet, Hdr->Address - (PCHAR)Hdr );
180 Status = NtWriteFile( LanFile,
181 NULL,
182 NULL,
183 NULL,
184 &Iosb,
185 Packet,
186 PktLen,
187 NULL,
188 NULL );
189
190 cout << "NtWriteFile: " << Status << "\n";
191 } else if( word == "recv" ) {
192 ULONG ReadLen;
193 Status = NtReadFile( LanFile,
194 Event,
195 NULL,
196 NULL,
197 &Iosb,
198 Packet,
199 sizeof(Packet),
200 NULL,
201 NULL );
202 cout << "NtReadFile: " << Status << "\n";
203 if( Status == STATUS_PENDING ) {
204 LARGE_INTEGER Timeout = { 0 };
206 }
207
208 ReadLen = Iosb.Information;
209
210 if( Status == STATUS_SUCCESS ) {
211 cout << "Read " << ReadLen << " bytes\n";
212 display_buffer( Packet, ReadLen );
213 }
214 }
215 }
216
217 return 0;
218}
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
return Iosb
Definition: create.c:4402
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:878
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_OPEN_IF
Definition: from_kernel.h:56
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define cout
Definition: iostream.cpp:38
#define cerr
Definition: iostream.cpp:39
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define ETYPE_IPv4
Definition: lantest.cpp:57
void display_buffer(char *Packet, int ReadLen)
Definition: lantest.cpp:34
int byte_till_end(char *Packet, int PktLen)
Definition: lantest.cpp:40
#define ETYPE_ARP
Definition: lantest.cpp:59
#define ETYPE_IPv6
Definition: lantest.cpp:58
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define IOCTL_IF_ADAPTER_INFO
Definition: net_lan.h:17
#define IOCTL_IF_ENUM_ADAPTERS
Definition: net_lan.h:13
struct _LAN_ADDRESS * PLAN_ADDRESS
#define LAN_FILL_EA_INFO(Ea, NumTypes, Types)
Definition: net_lan.h:69
#define IOCTL_IF_BUFFERED_MODE
Definition: net_lan.h:15
struct _LAN_PACKET_HEADER * PLAN_PACKET_HEADER
#define LAN_EA_INFO_SIZE(NumTypes)
Definition: net_lan.h:67
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
#define GENERIC_WRITE
Definition: nt_native.h:90
#define GENERIC_EXECUTE
Definition: nt_native.h:91
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
#define STATUS_PENDING
Definition: ntstatus.h:82
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
static ULONG Timeout
Definition: ping.c:61
#define calloc
Definition: rosglue.h:14
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
CHAR Address[1]
Definition: net_lan.h:30
LAN_PACKET_HEADER_T Fixed
Definition: net_lan.h:29
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:845
char CHAR
Definition: xmlstorage.h:175

◆ NtCreateFile()

NTSTATUS NTAPI NtCreateFile ( PHANDLE  FileHandle,
ACCESS_MASK  DesiredAccess,
POBJECT_ATTRIBUTES  ObjectAttributes,
PIO_STATUS_BLOCK  IoStatusBlock,
PLARGE_INTEGER  AllocationSize,
ULONG  FileAttributes,
ULONG  ShareAccess,
ULONG  CreateDisposition,
ULONG  CreateOptions,
PVOID  EaBuffer,
ULONG  EaLength 
)

Definition at line 3758 of file file.c.

3769{
3770 /* Call the I/O Function */
3771 return IoCreateFile(FileHandle,
3775 AllocateSize,
3780 EaBuffer,
3781 EaLength,
3783 NULL,
3784 0);
3785}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4147
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3010
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:120
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
@ CreateFileTypeNone
Definition: iotypes.h:535