ReactOS 0.4.15-dev-7924-g5949c20
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 215 of file iflist.c.

220{
221 IntfIDItem *IntfIDList;
222 IntfIDItem *pIntfIDItem, *pIntfIDNext;
224 TDIEntityID *outEntityID, *pEntityID;
225 IPSNMPInfo outIPSNMPInfo;
226 IPAddrEntry *pIPAddrEntry;
227 IFEntry *pIFEntry = NULL;
228 LPINTERFACE_INFO pIntfInfo;
229 DWORD outIDCount, i1, iAddr;
230 DWORD bCastAddr, outNumberOfBytes;
231 ULONG BufLenNeeded, BufLen, IFEntryLen, TdiType;
232 HANDLE TcpFile = NULL;
233 HANDLE hHeap = GetProcessHeap();
235 INT res;
236
237 /* Init Interface-ID-List */
238 IntfIDList = HeapAlloc(hHeap, 0, sizeof(*IntfIDList));
239 list_init(&IntfIDList->entry);
240
241 /* open tcp-driver */
243 if (!NT_SUCCESS(Status))
244 {
246 goto cleanup;
247 }
248
249 DPRINT("TcpFile %p\n", TcpFile);
250
251 if (!AllocAndGetEntityArray(TcpFile,hHeap,&outEntityID,&outIDCount))
252 {
253 DPRINT("ERROR in AllocAndGetEntityArray: out of memory!\n");
255 goto cleanup;
256 }
257
258 IFEntryLen = sizeof(IFEntry) + MAX_ADAPTER_DESCRIPTION_LENGTH + 1;
259 pIFEntry = HeapAlloc(hHeap, 0, IFEntryLen);
260 if (pIFEntry == 0)
261 {
262 DPRINT("ERROR\n");
264 goto cleanup;
265 }
266
267 /* get addresses */
268 pEntityID = outEntityID;
269 for (i1 = 0; i1 < outIDCount; i1++)
270 {
271 /* we are only interessted in network layers */
272 if ( (pEntityID->tei_entity != CL_NL_ENTITY) &&
273 (pEntityID->tei_entity != CO_NL_ENTITY) )
274 {
275 pEntityID++;
276 continue;
277 }
278 /* Get IPSNMPInfo */
279 res = GetIPSNMPInfo(TcpFile, pEntityID, &outIPSNMPInfo);
280 if (res != NO_ERROR)
281 goto cleanup;
282
283 /* add to array */
284 pIntfIDItem = (IntfIDItem*)HeapAlloc(hHeap, 0, sizeof(IntfIDItem));
285 list_add_head(&IntfIDList->entry, &pIntfIDItem->entry);
286 pIntfIDItem->id = *pEntityID;
287 pIntfIDItem->numaddr = outIPSNMPInfo.ipsi_numaddr;
288 /* filled later */
289 pIntfIDItem->pIPAddrEntry0 = NULL;
290
291 pEntityID++;
292 }
293
294 /* Calculate needed size */
295 outNumberOfBytes = 0;
296 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
297 {
298 outNumberOfBytes += (pIntfIDItem->numaddr * sizeof(INTERFACE_INFO));
299 }
300 DPRINT("Buffer size needed: %lu\n", outNumberOfBytes);
301 if (outNumberOfBytes > OutputBufferLength)
302 {
303 /* Buffer to small */
304 if (NumberOfBytesReturned)
305 *NumberOfBytesReturned = 0;
306 res = WSAEFAULT;
307 goto cleanup;
308 }
309
310 /* Get address info */
311 RtlZeroMemory(&inTcpReq1,sizeof(inTcpReq1));
312 inTcpReq1.ID.toi_class = INFO_CLASS_PROTOCOL;
313 inTcpReq1.ID.toi_type = INFO_TYPE_PROVIDER;
315 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
316 {
317 inTcpReq1.ID.toi_entity = pIntfIDItem->id;
318
319 BufLen = sizeof(IPAddrEntry) * pIntfIDItem->numaddr;
320 pIntfIDItem->pIPAddrEntry0 = HeapAlloc(hHeap, 0, BufLen);
321
322 if (!DeviceIoControl(
323 TcpFile,
325 &inTcpReq1,
326 sizeof(inTcpReq1),
327 pIntfIDItem->pIPAddrEntry0,
328 BufLen,
329 &BufLenNeeded,
330 NULL))
331 {
332 DPRINT("DeviceIoControl failed, Error %ld!\n", GetLastError());
333 res = WSAEFAULT;
334 goto cleanup;
335 }
336 }
337
338 /* build result */
339 pIntfInfo = (LPINTERFACE_INFO)OutputBuffer;
340 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
341 {
342 DPRINT("Number of addresses %d\n", pIntfIDItem->numaddr);
343
344 pIPAddrEntry = pIntfIDItem->pIPAddrEntry0;
345 for (iAddr = 0; iAddr < pIntfIDItem->numaddr; iAddr++)
346 {
347 DPRINT("BufLen %lu\n",BufLenNeeded);
348 DPRINT("pIPAddrEntry->iae_addr %lx\n",pIPAddrEntry->iae_addr);
349 DPRINT("pIPAddrEntry->iae_bcastaddr %lx\n",pIPAddrEntry->iae_bcastaddr);
350 DPRINT("pIPAddrEntry->iae_mask %lx\n",pIPAddrEntry->iae_mask);
351 DPRINT("pIPAddrEntry->iae_reasmsize %lx\n",pIPAddrEntry->iae_reasmsize);
352
353 pIntfInfo->iiAddress.AddressIn.sin_family = AF_INET;
354 pIntfInfo->iiAddress.AddressIn.sin_port = 0;
355 pIntfInfo->iiAddress.AddressIn.sin_addr.s_addr = pIPAddrEntry->iae_addr;
356
357 pIntfInfo->iiBroadcastAddress.AddressIn.sin_family = AF_INET;
358 pIntfInfo->iiBroadcastAddress.AddressIn.sin_port = 0;
359 bCastAddr = (pIPAddrEntry->iae_bcastaddr == 0) ? 0 : 0xffffffff;
360 pIntfInfo->iiBroadcastAddress.AddressIn.sin_addr.s_addr = bCastAddr;
361
362 pIntfInfo->iiNetmask.AddressIn.sin_family = AF_INET;
363 pIntfInfo->iiNetmask.AddressIn.sin_port = 0;
364 pIntfInfo->iiNetmask.AddressIn.sin_addr.s_addr = pIPAddrEntry->iae_mask;
365
366 pIntfInfo->iiFlags = IFF_BROADCAST | IFF_MULTICAST;
367 if (pIPAddrEntry->iae_addr == ntohl(INADDR_LOOPBACK))
368 pIntfInfo->iiFlags |= IFF_LOOPBACK;
369
370 pIPAddrEntry++;
371 pIntfInfo++;
372 }
373 res = NO_ERROR;
374 }
375
376 /* Get Interface up/down-state and patch pIntfInfo->iiFlags */
377 pEntityID = outEntityID;
378 for (i1 = 0; i1 < outIDCount; i1++)
379 {
380 res = GetTdiEntityType(TcpFile, pEntityID, &TdiType);
381 if (res != NO_ERROR)
382 goto cleanup;
383
384 if (TdiType != IF_MIB)
385 {
386 pEntityID++;
387 continue;
388 }
389
390 res = GetIFEntry(TcpFile, pEntityID, pIFEntry, IFEntryLen);
391 if (res != NO_ERROR)
392 goto cleanup;
393
394 /* if network isn't up -> no patch needed */
396 {
397 pEntityID++;
398 continue;
399 }
400
401 /* patching ... if interface-index matches */
402 pIntfInfo = (LPINTERFACE_INFO)OutputBuffer;
403 LIST_FOR_EACH_ENTRY(pIntfIDItem, &IntfIDList->entry, struct _IntfIDItem, entry)
404 {
405 pIPAddrEntry = pIntfIDItem->pIPAddrEntry0;
406 for (iAddr = 0; iAddr < pIntfIDItem->numaddr; iAddr++)
407 {
408 if (pIPAddrEntry->iae_index == pIFEntry->if_index)
409 pIntfInfo->iiFlags |= IFF_UP;
410
411 pIPAddrEntry++;
412 pIntfInfo++;
413 }
414 }
415
416 pEntityID++;
417 }
418
419 if (NumberOfBytesReturned)
420 *NumberOfBytesReturned = outNumberOfBytes;
421 if (NeedsCompletion != NULL)
422 *NeedsCompletion = FALSE;
423
424 res = NO_ERROR;
425cleanup:
426 DPRINT("WSHIoctl_GetInterfaceList - CLEANUP\n");
427 if (TcpFile != NULL)
428 closeTcpFile(TcpFile);
429 if (pIFEntry != NULL)
430 HeapFree(hHeap, 0, pIFEntry);
431 LIST_FOR_EACH_ENTRY_SAFE_REV(pIntfIDItem, pIntfIDNext,
432 &IntfIDList->entry, struct _IntfIDItem, entry)
433 {
434 if (pIntfIDItem->pIPAddrEntry0 != NULL)
435 HeapFree(hHeap, 0, pIntfIDItem->pIPAddrEntry0);
436 list_remove(&pIntfIDItem->entry);
437 HeapFree(hHeap, 0, pIntfIDItem);
438 }
439 HeapFree(hHeap, 0, IntfIDList);
440 return res;
441}
#define IP_MIB_ADDRTABLE_ENTRY_ID
Definition: afd.h:36
LONG NTSTATUS
Definition: precomp.h:26
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
Status
Definition: gdiplustypes.h:25
GLuint res
Definition: glext.h:9613
INT GetIPSNMPInfo(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT IPSNMPInfo *outIPSNMPInfo)
Definition: iflist.c:113
INT GetIFEntry(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT IFEntry *pIFEntry, IN ULONG IFEntryLen)
Definition: iflist.c:173
BOOL AllocAndGetEntityArray(IN HANDLE TcpFile, IN HANDLE hHeap, OUT TDIEntityID **ppEntities, OUT PDWORD idCount)
Definition: iflist.c:18
INT GetTdiEntityType(IN HANDLE TcpFile, IN TDIEntityID *pEntityID, OUT PULONG pType)
Definition: iflist.c:143
#define MAX_ADAPTER_DESCRIPTION_LENGTH
Definition: iinfo.c:16
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
@ 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
#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
VOID closeTcpFile(HANDLE h)
Definition: handle.c:43
#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:206
int numaddr
Definition: iflist.c:209
IPAddrEntry * pIPAddrEntry0
Definition: iflist.c:211
TDIEntityID id
Definition: iflist.c:207
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().