ReactOS 0.4.15-dev-6656-gbbb33a6
wshtcpip.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <wsahelp.h>
#include <tdiinfo.h>
#include <tcpioctl.h>
#include <tdilib.h>
#include <ws2tcpip.h>
#include <rtlfuncs.h>
Include dependency graph for wshtcpip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _QUEUED_REQUEST
 
struct  _SOCKET_CONTEXT
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define EXPORT   WINAPI
 
#define DD_TCP_DEVICE_NAME   L"\\Device\\Tcp"
 
#define DD_UDP_DEVICE_NAME   L"\\Device\\Udp"
 
#define DD_RAW_IP_DEVICE_NAME   L"\\Device\\RawIp"
 

Typedefs

typedef enum _SOCKET_STATE SOCKET_STATE
 
typedef enum _SOCKET_STATEPSOCKET_STATE
 
typedef struct _QUEUED_REQUEST QUEUED_REQUEST
 
typedef struct _QUEUED_REQUESTPQUEUED_REQUEST
 
typedef struct _SOCKET_CONTEXT SOCKET_CONTEXT
 
typedef struct _SOCKET_CONTEXTPSOCKET_CONTEXT
 

Enumerations

enum  _SOCKET_STATE {
  SocketOpen , SocketBound , SocketBoundUdp , SocketConnected ,
  SocketClosed , SocketStateCreated , SocketStateBound , SocketStateListening ,
  SocketStateConnected , SocketUndefined = -1 , SocketOpen , SocketBound ,
  SocketBoundUdp , SocketConnected , SocketClosed
}
 

Functions

INT WSHIoctl_GetInterfaceList (IN LPVOID OutputBuffer, IN DWORD OutputBufferLength, OUT LPDWORD NumberOfBytesReturned, OUT LPBOOL NeedsCompletion)
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 11 of file wshtcpip.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 12 of file wshtcpip.h.

◆ DD_RAW_IP_DEVICE_NAME

#define DD_RAW_IP_DEVICE_NAME   L"\\Device\\RawIp"

Definition at line 29 of file wshtcpip.h.

◆ DD_TCP_DEVICE_NAME

#define DD_TCP_DEVICE_NAME   L"\\Device\\Tcp"

Definition at line 27 of file wshtcpip.h.

◆ DD_UDP_DEVICE_NAME

#define DD_UDP_DEVICE_NAME   L"\\Device\\Udp"

Definition at line 28 of file wshtcpip.h.

◆ EXPORT

Definition at line 25 of file wshtcpip.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file wshtcpip.h.

Typedef Documentation

◆ PQUEUED_REQUEST

◆ PSOCKET_CONTEXT

◆ PSOCKET_STATE

◆ QUEUED_REQUEST

◆ SOCKET_CONTEXT

◆ SOCKET_STATE

Enumeration Type Documentation

◆ _SOCKET_STATE

Enumerator
SocketOpen 
SocketBound 
SocketBoundUdp 
SocketConnected 
SocketClosed 
SocketStateCreated 
SocketStateBound 
SocketStateListening 
SocketStateConnected 
SocketUndefined 
SocketOpen 
SocketBound 
SocketBoundUdp 
SocketConnected 
SocketClosed 

Definition at line 31 of file wshtcpip.h.

31 {
enum _SOCKET_STATE SOCKET_STATE
enum _SOCKET_STATE * PSOCKET_STATE
@ SocketStateBound
Definition: wshtcpip.h:33
@ SocketStateCreated
Definition: wshtcpip.h:32
@ SocketStateConnected
Definition: wshtcpip.h:35
@ SocketStateListening
Definition: wshtcpip.h:34

Function Documentation

◆ WSHIoctl_GetInterfaceList()

INT WSHIoctl_GetInterfaceList ( IN LPVOID  OutputBuffer,
IN DWORD  OutputBufferLength,
OUT LPDWORD  NumberOfBytesReturned,
OUT LPBOOL  NeedsCompletion 
)

Definition at line 216 of file iflist.c.

221{
222 IntfIDItem *IntfIDList;
223 IntfIDItem *pIntfIDItem, *pIntfIDNext;
225 TDIEntityID *outEntityID, *pEntityID;
226 IPSNMPInfo outIPSNMPInfo;
227 IPAddrEntry *pIPAddrEntry;
228 IFEntry *pIFEntry = NULL;
229 LPINTERFACE_INFO pIntfInfo;
230 DWORD outIDCount, i1, iAddr;
231 DWORD bCastAddr, outNumberOfBytes;
232 ULONG BufLenNeeded, BufLen, IFEntryLen, TdiType;
233 HANDLE TcpFile = 0;
234 HANDLE hHeap = GetProcessHeap();
235 DWORD LastErr;
236 INT res = -1;
237
238 /* Init Interface-ID-List */
239 IntfIDList = HeapAlloc(hHeap, 0, sizeof(*IntfIDList));
240 list_init(&IntfIDList->entry);
241
242 /* open tcp-driver */
243 LastErr = openTcpFile(&TcpFile, FILE_READ_DATA | FILE_WRITE_DATA);
244 if (!NT_SUCCESS(LastErr))
245 {
246 res = (INT)LastErr;
247 goto cleanup;
248 }
249
250 DPRINT("TcpFile %p\n", TcpFile);
251
252 if (!AllocAndGetEntityArray(TcpFile,hHeap,&outEntityID,&outIDCount))
253 {
254 DPRINT("ERROR in AllocAndGetEntityArray: out of memory!\n");
256 goto cleanup;
257 }
258
259 IFEntryLen = sizeof(IFEntry) + MAX_ADAPTER_DESCRIPTION_LENGTH + 1;
260 pIFEntry = HeapAlloc(hHeap, 0, IFEntryLen);
261 if (pIFEntry == 0)
262 {
263 DPRINT("ERROR\n");
265 goto cleanup;
266 }
267
268 /* get addresses */
269 pEntityID = outEntityID;
270 for (i1 = 0; i1 < outIDCount; i1++)
271 {
272 /* we are only interessted in network layers */
273 if ( (pEntityID->tei_entity != CL_NL_ENTITY) &&
274 (pEntityID->tei_entity != CO_NL_ENTITY) )
275 {
276 pEntityID++;
277 continue;
278 }
279 /* Get IPSNMPInfo */
280 res = GetIPSNMPInfo(TcpFile, pEntityID, &outIPSNMPInfo);
281 if (res != NO_ERROR)
282 goto cleanup;
283
284 /* add to array */
285 pIntfIDItem = (IntfIDItem*)HeapAlloc(hHeap, 0, sizeof(IntfIDItem));
286 list_add_head(&IntfIDList->entry, &pIntfIDItem->entry);
287 pIntfIDItem->id = *pEntityID;
288 pIntfIDItem->numaddr = outIPSNMPInfo.ipsi_numaddr;
289 /* filled later */
290 pIntfIDItem->pIPAddrEntry0 = NULL;
291
292 pEntityID++;
293 }
294
295 /* Calculate needed size */
296 outNumberOfBytes = 0;
297 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
298 {
299 outNumberOfBytes += (pIntfIDItem->numaddr * sizeof(INTERFACE_INFO));
300 }
301 DPRINT("Buffer size needed: %lu\n", outNumberOfBytes);
302 if (outNumberOfBytes > OutputBufferLength)
303 {
304 /* Buffer to small */
305 if (NumberOfBytesReturned)
306 *NumberOfBytesReturned = 0;
307 res = WSAEFAULT;
308 goto cleanup;
309 }
310
311 /* Get address info */
312 RtlZeroMemory(&inTcpReq1,sizeof(inTcpReq1));
313 inTcpReq1.ID.toi_class = INFO_CLASS_PROTOCOL;
314 inTcpReq1.ID.toi_type = INFO_TYPE_PROVIDER;
316 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
317 {
318 inTcpReq1.ID.toi_entity = pIntfIDItem->id;
319
320 BufLen = sizeof(IPAddrEntry) * pIntfIDItem->numaddr;
321 pIntfIDItem->pIPAddrEntry0 = HeapAlloc(hHeap, 0, BufLen);
322
323 if (!DeviceIoControl(
324 TcpFile,
326 &inTcpReq1,
327 sizeof(inTcpReq1),
328 pIntfIDItem->pIPAddrEntry0,
329 BufLen,
330 &BufLenNeeded,
331 NULL))
332 {
333 LastErr = GetLastError();
334 DPRINT("DeviceIoControl failed, Status %li!\n", LastErr);
335 res = WSAEFAULT;
336 goto cleanup;
337 }
338 }
339
340 /* build result */
341 pIntfInfo = (LPINTERFACE_INFO)OutputBuffer;
342 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
343 {
344 DPRINT("Number of addresses %d\n", pIntfIDItem->numaddr);
345
346 pIPAddrEntry = pIntfIDItem->pIPAddrEntry0;
347 for (iAddr = 0; iAddr < pIntfIDItem->numaddr; iAddr++)
348 {
349 DPRINT("BufLen %lu\n",BufLenNeeded);
350 DPRINT("pIPAddrEntry->iae_addr %lx\n",pIPAddrEntry->iae_addr);
351 DPRINT("pIPAddrEntry->iae_bcastaddr %lx\n",pIPAddrEntry->iae_bcastaddr);
352 DPRINT("pIPAddrEntry->iae_mask %lx\n",pIPAddrEntry->iae_mask);
353 DPRINT("pIPAddrEntry->iae_reasmsize %lx\n",pIPAddrEntry->iae_reasmsize);
354
355 pIntfInfo->iiAddress.AddressIn.sin_family = AF_INET;
356 pIntfInfo->iiAddress.AddressIn.sin_port = 0;
357 pIntfInfo->iiAddress.AddressIn.sin_addr.s_addr = pIPAddrEntry->iae_addr;
358
359 pIntfInfo->iiBroadcastAddress.AddressIn.sin_family = AF_INET;
360 pIntfInfo->iiBroadcastAddress.AddressIn.sin_port = 0;
361 bCastAddr = (pIPAddrEntry->iae_bcastaddr == 0) ? 0 : 0xffffffff;
362 pIntfInfo->iiBroadcastAddress.AddressIn.sin_addr.s_addr = bCastAddr;
363
364 pIntfInfo->iiNetmask.AddressIn.sin_family = AF_INET;
365 pIntfInfo->iiNetmask.AddressIn.sin_port = 0;
366 pIntfInfo->iiNetmask.AddressIn.sin_addr.s_addr = pIPAddrEntry->iae_mask;
367
368 pIntfInfo->iiFlags = IFF_BROADCAST | IFF_MULTICAST;
369 if (pIPAddrEntry->iae_addr == ntohl(INADDR_LOOPBACK))
370 pIntfInfo->iiFlags |= IFF_LOOPBACK;
371
372 pIPAddrEntry++;
373 pIntfInfo++;
374 }
375 res = NO_ERROR;
376 }
377
378 /* Get Interface up/down-state and patch pIntfInfo->iiFlags */
379 pEntityID = outEntityID;
380 for (i1 = 0; i1 < outIDCount; i1++)
381 {
382 res = GetTdiEntityType(TcpFile, pEntityID, &TdiType);
383 if (res != NO_ERROR)
384 goto cleanup;
385
386 if (TdiType != IF_MIB)
387 {
388 pEntityID++;
389 continue;
390 }
391
392 res = GetIFEntry(TcpFile, pEntityID, pIFEntry, IFEntryLen);
393 if (res != NO_ERROR)
394 goto cleanup;
395
396 /* if network isn't up -> no patch needed */
398 {
399 pEntityID++;
400 continue;
401 }
402
403 /* patching ... if interface-index matches */
404 pIntfInfo = (LPINTERFACE_INFO)OutputBuffer;
405 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
406 {
407 pIPAddrEntry = pIntfIDItem->pIPAddrEntry0;
408 for (iAddr = 0; iAddr < pIntfIDItem->numaddr; iAddr++)
409 {
410 if (pIPAddrEntry->iae_index == pIFEntry->if_index)
411 pIntfInfo->iiFlags |= IFF_UP;
412
413 pIPAddrEntry++;
414 pIntfInfo++;
415 }
416 }
417
418 pEntityID++;
419 }
420
421 if (NumberOfBytesReturned)
422 *NumberOfBytesReturned = outNumberOfBytes;
423 if (NeedsCompletion != NULL)
424 *NeedsCompletion = FALSE;
425
426 res = NO_ERROR;
427cleanup:
428 DPRINT("WSHIoctl_GetInterfaceList - CLEANUP\n");
429 if (TcpFile != 0)
430 NtClose(TcpFile);
431 if (pIFEntry != NULL)
432 HeapFree(hHeap, 0, pIFEntry);
433 LIST_FOR_EACH_ENTRY_SAFE_REV(pIntfIDItem, pIntfIDNext,
434 &IntfIDList->entry, struct _IntfIDItem, entry)
435 {
436 if (pIntfIDItem->pIPAddrEntry0 != NULL)
437 HeapFree(hHeap, 0, pIntfIDItem->pIPAddrEntry0);
438 list_remove(&pIntfIDItem->entry);
439 HeapFree(hHeap, 0, pIntfIDItem);
440 }
441 HeapFree(hHeap, 0, IntfIDList);
442 return res;
443}
#define IP_MIB_ADDRTABLE_ENTRY_ID
Definition: afd.h:36
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
static void list_init(struct list_entry *head)
Definition: list.h:51
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
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 FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static void cleanup(void)
Definition: main.c:1335
#define AF_INET
Definition: tcpip.h:117
#define BufLen
Definition: fatfs.h:167
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
INT GetIPSNMPInfo(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT IPSNMPInfo *outIPSNMPInfo)
Definition: iflist.c:114
INT GetIFEntry(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT IFEntry *pIFEntry, IN ULONG IFEntryLen)
Definition: iflist.c:174
BOOL AllocAndGetEntityArray(IN HANDLE TcpFile, IN HANDLE hHeap, OUT TDIEntityID **ppEntities, OUT PDWORD idCount)
Definition: iflist.c:21
INT GetTdiEntityType(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT PULONG pType)
Definition: iflist.c:144
#define MAX_ADAPTER_DESCRIPTION_LENGTH
Definition: iinfo.c:16
@ IF_OPER_STATUS_CONNECTING
Definition: ipifcons.h:241
#define INADDR_LOOPBACK
Definition: inet.h:51
uint32_t entry
Definition: isohybrid.c:63
#define ntohl(x)
Definition: module.h:205
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define INT
Definition: polytest.cpp:20
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define LIST_FOR_EACH_ENTRY_SAFE_REV(cursor, cursor2, list, type, field)
Definition: list.h:228
NTSTATUS openTcpFile(PHANDLE tcpFile, ACCESS_MASK DesiredAccess)
Definition: handle.c:12
#define DPRINT
Definition: sndvol32.h:71
ULONG if_operstatus
Definition: tcpioctl.h:115
ULONG if_index
Definition: tcpioctl.h:108
ULONG iae_mask
Definition: tcpioctl.h:164
ULONG iae_index
Definition: tcpioctl.h:163
ULONG iae_addr
Definition: tcpioctl.h:162
ULONG iae_bcastaddr
Definition: tcpioctl.h:165
ULONG iae_reasmsize
Definition: tcpioctl.h:166
ULONG ipsi_numaddr
Definition: tcpioctl.h:156
sockaddr_gen iiBroadcastAddress
Definition: ws2ipdef.h:167
sockaddr_gen iiNetmask
Definition: ws2ipdef.h:168
sockaddr_gen iiAddress
Definition: ws2ipdef.h:166
struct list entry
Definition: iflist.c:207
int numaddr
Definition: iflist.c:210
IPAddrEntry * pIPAddrEntry0
Definition: iflist.c:212
TDIEntityID id
Definition: iflist.c:208
ULONG tei_entity
Definition: tdiinfo.h:31
ULONG toi_id
Definition: tdiinfo.h:77
ULONG toi_type
Definition: tdiinfo.h:76
ULONG toi_class
Definition: tdiinfo.h:75
TDIEntityID toi_entity
Definition: tdiinfo.h:74
#define CO_NL_ENTITY
Definition: tdiinfo.h:44
#define INFO_CLASS_PROTOCOL
Definition: tdiinfo.h:65
#define INFO_TYPE_PROVIDER
Definition: tdiinfo.h:69
#define CL_NL_ENTITY
Definition: tdiinfo.h:42
#define IF_MIB
Definition: tdiinfo.h:61
#define IOCTL_TCP_QUERY_INFORMATION_EX
Definition: tditest.h:110
int32_t INT
Definition: typedefs.h:58
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
struct sockaddr_in AddressIn
Definition: ws2ipdef.h:160
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WSAEFAULT
Definition: winerror.h:1945
#define IFF_MULTICAST
Definition: ws2ipdef.h:25
#define IFF_BROADCAST
Definition: ws2ipdef.h:22
struct _INTERFACE_INFO INTERFACE_INFO
#define IFF_LOOPBACK
Definition: ws2ipdef.h:23
struct _INTERFACE_INFO * LPINTERFACE_INFO
#define IFF_UP
Definition: ws2ipdef.h:21

Referenced by WSHIoctl().