ReactOS 0.4.17-dev-243-g1369312
ip.c File Reference
#include "precomp.h"
#include <guiddef.h>
#include <devguid.h>
#include <debug.h>
#include "guid.h"
#include "resource.h"
Include dependency graph for ip.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DISPLAY_ADRESSES   0x1
 
#define DISPLAY_DNS   0x2
 

Functions

static DWORD WINAPI IpSetAddress (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
static HRESULT GetInterfaceProperties (GUID *InterfaceGuid, PTCPIP_PROPERTIES *ppProperties)
 
static PWSTR ExtractParameterValue (PWSTR pszParameters, PWSTR pszParameter)
 
static DWORD IpShowAdapters (_In_ DWORD DisplayFlags, _In_ PWSTR InterfaceName)
 
static DWORD WINAPI IpShowAddresses (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
static DWORD WINAPI IpShowConfig (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
static DWORD WINAPI IpShowDns (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
static DWORD WINAPI IpDumpFn (_In_ LPCWSTR pwszRouter, _In_ LPWSTR *ppwcArguments, _In_ DWORD dwArgCount, _In_ LPCVOID pvData)
 
static DWORD WINAPI IpStart (_In_ const GUID *pguidParent, _In_ DWORD dwVersion)
 
DWORD WINAPI RegisterIpHelper (VOID)
 

Variables

static FN_HANDLE_CMD IpSetAddress
 
static FN_HANDLE_CMD IpShowAddresses
 
static FN_HANDLE_CMD IpShowConfig
 
static FN_HANDLE_CMD IpShowDns
 
static CMD_ENTRY IpSetCommands []
 
static CMD_ENTRY IpShowCommands []
 
static CMD_GROUP_ENTRY IpGroups []
 

Macro Definition Documentation

◆ DISPLAY_ADRESSES

#define DISPLAY_ADRESSES   0x1

Definition at line 19 of file ip.c.

◆ DISPLAY_DNS

#define DISPLAY_DNS   0x2

Definition at line 20 of file ip.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file ip.c.

Function Documentation

◆ ExtractParameterValue()

static PWSTR ExtractParameterValue ( PWSTR  pszParameters,
PWSTR  pszParameter 
)
static

Definition at line 352 of file ip.c.

355{
356 PWSTR pToken, pStart, pEnd, pBuffer;
357 INT length;
358
359 pToken = wcsstr(pszParameters, pszParameter);
360 if (pToken == NULL)
361 return NULL;
362
363 pStart = wcschr(pToken, L'=');
364 if (pStart == NULL)
365 return NULL;
366
367 pStart++;
368 pEnd = wcschr(pStart, L';');
369 if (pEnd == NULL)
370 length = wcslen(pStart);
371 else
372 length = pEnd - pStart;
373
374 if (length == 0)
375 return NULL;
376
378 if (pBuffer)
379 {
380 CopyMemory(pBuffer, pStart, length * sizeof(WCHAR));
381 }
382
383 return pBuffer;
384}
#define NULL
Definition: types.h:112
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
Definition: wcs.c:2993
#define L(x)
Definition: resources.c:13
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define CopyMemory
Definition: minwinbase.h:29
short WCHAR
Definition: pedump.c:58
PVOID pBuffer
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58

Referenced by IpDumpFn(), and IpShowAdapters().

◆ GetInterfaceProperties()

static HRESULT GetInterfaceProperties ( GUID InterfaceGuid,
PTCPIP_PROPERTIES ppProperties 
)
static

Definition at line 202 of file ip.c.

205{
206 INetCfg *pNetCfg = NULL;
207 INetCfgLock *pNetCfgLock = NULL;
208 INetCfgClass *pNetCfgClass = NULL;
209 INetCfgComponent *pTcpipComponent = NULL;
210 INetCfgComponentPrivate *pTcpipComponentPrivate = NULL;
211 ITcpipProperties *pTcpipProperties = NULL;
212
213 BOOL fWriteLocked = FALSE, fInitialized = FALSE;
214 HRESULT hr;
215
216 DPRINT("GetInterfaceProperties()\n");
217
219 if (hr != S_OK)
220 {
221 DPRINT1("CoInitialize failed\n");
222 goto exit;
223 }
224
226 NULL,
227 CLSCTX_INPROC_SERVER,
229 (PVOID*)&pNetCfg);
230 if (hr != S_OK)
231 {
232 DPRINT1("CoCreateInstance failed\n");
233 goto exit;
234 }
235
236 /* Acquire the write-lock */
237 hr = INetCfg_QueryInterface(pNetCfg,
239 (PVOID*)&pNetCfgLock);
240 if (hr != S_OK)
241 {
242 DPRINT1("QueryInterface failed\n");
243 goto exit;
244 }
245
246 hr = INetCfgLock_AcquireWriteLock(pNetCfgLock, 5000,
247 L"NetSh",
248 NULL);
249 if (hr != S_OK)
250 {
251 DPRINT1("AcquireWriteLock failed\n");
252 goto exit;
253 }
254
255 fWriteLocked = TRUE;
256
257 /* Initialize the network configuration */
258 hr = INetCfg_Initialize(pNetCfg, NULL);
259 if (hr != S_OK)
260 {
261 DPRINT1("Initialize failed\n");
262 goto exit;
263 }
264
265 fInitialized = TRUE;
266
267 GUID ClassGuid = GUID_DEVCLASS_NETTRANS;
268 hr = INetCfg_QueryNetCfgClass(pNetCfg, &ClassGuid, &IID_INetCfgClass, (PVOID*)&pNetCfgClass);
269 if (hr != S_OK)
270 {
271 DPRINT1("INetCfg_QueryNetCfgClass failed!\n");
272 goto exit;
273 }
274
275 hr = INetCfgClass_FindComponent(pNetCfgClass, L"MS_TCPIP", &pTcpipComponent);
276 if (hr != S_OK)
277 {
278 DPRINT1("INetCfgClass_FindComponent failed\n");
279 goto exit;
280 }
281
282 hr = INetCfgComponent_QueryInterface(pTcpipComponent, &IID_INetCfgComponentPrivate, (PVOID*)&pTcpipComponentPrivate);
283 if (hr != S_OK)
284 {
285 DPRINT1("INetCfgComponent_QueryInterface failed\n");
286 goto exit;
287 }
288
289 hr = INetCfgComponentPrivate_Unknown1(pTcpipComponentPrivate, &IID_ITcpipProperties, (PVOID*)&pTcpipProperties);
290 if (hr != S_OK)
291 {
292 DPRINT1("INetCfgComponentPrivate_Unknown1 failed\n");
293 goto exit;
294 }
295
296 PTCPIP_PROPERTIES pInfo = NULL;
297 hr = ITcpipProperties_Unknown1(pTcpipProperties, InterfaceGuid, &pInfo);
298 if (hr != S_OK)
299 {
300 DPRINT1("ITcpipProperties_Unknown1 failed\n");
301 }
302 else
303 {
304 DPRINT("pInfo: %p\n", pInfo);
305 DPRINT("dwDhcp: %lx\n", pInfo->dwDhcp);
306 DPRINT("IpAddress: %p\n", pInfo->pszIpAddress);
307 DPRINT("IpAddress: %S\n", pInfo->pszIpAddress);
308 DPRINT("SubnetMask: %p\n", pInfo->pszSubnetMask);
309 DPRINT("SubnetMask: %S\n", pInfo->pszSubnetMask);
310 DPRINT("Parameters: %p\n", pInfo->pszParameters);
311 DPRINT("Parameters: %S\n", pInfo->pszParameters);
312
313 *ppProperties = pInfo;
314 }
315
316 DPRINT("Done!\n");
317exit:
318 if (pTcpipProperties)
319 ITcpipProperties_Release(pTcpipProperties);
320
321 if (pTcpipComponentPrivate)
322 INetCfgComponentPrivate_Release(pTcpipComponentPrivate);
323
324 if (pTcpipComponent != NULL)
325 INetCfgComponent_Release(pTcpipComponent);
326
327 if (pNetCfgClass != NULL)
328 INetCfgClass_Release(pNetCfgClass);
329
330 if (fInitialized)
331 INetCfg_Uninitialize(pNetCfg);
332
333 if (fWriteLocked)
334 INetCfgLock_ReleaseWriteLock(pNetCfgLock);
335
336 if (pNetCfgLock != NULL)
337 INetCfgLock_Release(pNetCfgLock);
338
339 if (pNetCfg != NULL)
340 INetCfg_Release(pNetCfg);
341
343
344 DPRINT("GetInterfaceProperties() done!\n");
345
346 return hr;
347}
#define DPRINT1
Definition: precomp.h:8
HRESULT hr
Definition: delayimp.cpp:582
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_OK
Definition: intsafe.h:52
#define ITcpipProperties_Unknown1(p, a, b)
Definition: netcfgn_undoc.h:31
EXTERN_C const IID IID_ITcpipProperties
Definition: netcfgn_undoc.h:24
#define ITcpipProperties_Release(p)
Definition: netcfgn_undoc.h:30
#define INetCfgComponent_QueryInterface(p, a, b)
Definition: netcfgx.h:60
#define INetCfg_Release(p)
Definition: netcfgx.h:289
#define INetCfgComponent_Release(p)
Definition: netcfgx.h:62
#define INetCfg_QueryInterface(p, a, b)
Definition: netcfgx.h:287
#define INetCfg_QueryNetCfgClass(p, a, b, c)
Definition: netcfgx.h:296
EXTERN_C const IID IID_INetCfgLock
Definition: netcfgx.h:17
EXTERN_C const IID IID_INetCfgClass
Definition: netcfgx.h:317
EXTERN_C const GUID CLSID_CNetCfg
Definition: netcfgx.h:299
#define INetCfgLock_AcquireWriteLock(p, a, b, c)
Definition: netcfgx.h:24
#define INetCfgLock_ReleaseWriteLock(p)
Definition: netcfgx.h:25
#define INetCfgClass_Release(p)
Definition: netcfgx.h:335
#define INetCfg_Uninitialize(p)
Definition: netcfgx.h:291
#define INetCfgLock_Release(p)
Definition: netcfgx.h:23
EXTERN_C const IID IID_INetCfg
Definition: netcfgx.h:300
#define INetCfgClass_FindComponent(p, a, b)
Definition: netcfgx.h:336
#define INetCfg_Initialize(p, a)
Definition: netcfgx.h:290
#define INetCfgComponentPrivate_Unknown1(p, a, b)
Definition: netcfgx_undoc.h:23
#define INetCfgComponentPrivate_Release(p)
Definition: netcfgx_undoc.h:22
EXTERN_C const IID IID_INetCfgComponentPrivate
Definition: netcfgx_undoc.h:16
#define exit(n)
Definition: config.h:202
#define DPRINT
Definition: sndvol32.h:73
static const GUID InterfaceGuid
Definition: wlanapi.c:25

Referenced by IpDumpFn(), and IpShowAdapters().

◆ IpDumpFn()

static DWORD WINAPI IpDumpFn ( _In_ LPCWSTR  pwszRouter,
_In_ LPWSTR ppwcArguments,
_In_ DWORD  dwArgCount,
_In_ LPCVOID  pvData 
)
static

Definition at line 611 of file ip.c.

616{
618 DWORD dwCount = 0, i;
619 DWORD dwError;
620 WCHAR szFriendlyName[80];
621 DWORD dwFriendlyNameSize;
622 PTCPIP_PROPERTIES pProperties = NULL;
624
625 DPRINT("IpDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData);
626
628 &dwCount,
629 FALSE,
631 0);
632 if (dwError != ERROR_SUCCESS)
633 {
634 DPRINT1("NhpAllocateAndGetInterfaceInfoFromStack() failed (Error %lu)\n", dwError);
635 return dwError;
636 }
637
641 PrintMessage(L"pushd interface ip\n");
643
644 DPRINT("\nEntries: %lu\n", dwCount);
645
646 for (i = 0; i < dwCount; i++)
647 {
648 DPRINT("\nEntry %lu\n", i);
649 DPRINT("Index: %lu\n", pTable[i].Index);
650 DPRINT("MediaType: %lu\n", pTable[i].MediaType);
651 DPRINT("ConnectionType: %u\n", pTable[i].ConnectionType);
652 DPRINT("AccessType: %u\n", pTable[i].AccessType);
653 DPRINT("DeviceGuid: %08lx\n", pTable[i].DeviceGuid.Data1);
654 DPRINT("InterfaceGuid: %08lx\n", pTable[i].InterfaceGuid.Data1);
655
656 dwFriendlyNameSize = sizeof(szFriendlyName);
658 szFriendlyName,
659 &dwFriendlyNameSize,
660 0,
661 0);
662
666
667 GetInterfaceProperties(&pTable[i].DeviceGuid, &pProperties);
668
669 if (pProperties)
670 {
671 DPRINT("Dhcp %lu\n", pProperties->dwDhcp);
672 DPRINT("IpAddress %S\n", pProperties->pszIpAddress);
673 DPRINT("SubnetMask %S\n", pProperties->pszSubnetMask);
674 DPRINT("Parameters %S\n", pProperties->pszParameters);
675
676 if (pProperties->dwDhcp)
677 {
678 PrintMessage(L"set address name=\"%s\" source=dhcp\n",
679 szFriendlyName);
680 }
681 else
682 {
683 PrintMessage(L"set address name=\"%s\" source=static address=%s mask=%s\n",
684 szFriendlyName, pProperties->pszIpAddress, pProperties->pszSubnetMask);
685 }
686
687 if (pProperties->dwDhcp)
688 {
689 PrintMessage(L"set dns name=\"%s\" source=dhcp\n",
690 szFriendlyName);
691 }
692 else
693 {
694 pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DNS");
695 if (pBuffer)
696 {
697 PrintMessage(L"set dns name=\"%s\" source=static address=%s\n",
698 szFriendlyName, pBuffer);
700 }
701 }
702
703 CoTaskMemFree(pProperties);
704 pProperties = NULL;
705 }
706 }
707
709 PrintMessage(L"popd\n");
712
713 if (pTable)
715
716
717 return ERROR_SUCCESS;
718}
VOID PrintMessage(DWORD dwMessage)
Definition: arp.c:95
static HINSTANCE hDllInstance
Definition: clb.c:9
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HeapFree(x, y, z)
Definition: compat.h:735
static HRESULT GetInterfaceProperties(GUID *InterfaceGuid, PTCPIP_PROPERTIES *ppProperties)
Definition: ip.c:202
static PWSTR ExtractParameterValue(PWSTR pszParameters, PWSTR pszParameter)
Definition: ip.c:352
#define IDS_DUMP_NEWLINE
Definition: resource.h:42
#define IDS_DUMP_IP_HEADER
Definition: resource.h:44
#define IDS_DUMP_HEADERLINE
Definition: resource.h:43
#define IDS_DUMP_IP_INTERFACE
Definition: resource.h:45
#define IDS_DUMP_IP_FOOTER
Definition: resource.h:46
unsigned long DWORD
Definition: ntddk_ex.h:95
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
DWORD WINAPI NhGetInterfaceNameFromGuid(_In_ const GUID *pInterfaceGUID, _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName, _Inout_ PULONG pOutBufLen, DWORD dwUnknown4, DWORD dwUnknown5)
DWORD WINAPI NhpAllocateAndGetInterfaceInfoFromStack(_Inout_ IP_INTERFACE_NAME_INFO **ppTable, _Inout_ PDWORD pdwCount, _In_ BOOL bOrder, _In_ HANDLE hHeap, _In_ DWORD dwFlags)
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
DWORD CDECL PrintMessageFromModule(_In_ HANDLE hModule, _In_ DWORD dwMsgId,...)
Definition: netsh.c:545
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116
_In_ LPWSTR * ppwcArguments
Definition: netsh.h:114
_In_ LPWSTR _In_ DWORD dwArgCount
Definition: netsh.h:115
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by IpStart().

◆ IpSetAddress()

static DWORD WINAPI IpSetAddress ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)
static

Definition at line 58 of file ip.c.

66{
67 TAG_TYPE pttTags[] = {{L"name", NS_REQ_ZERO, FALSE},
68 {L"source", NS_REQ_ZERO, FALSE},
69 {L"addr", NS_REQ_ZERO, FALSE},
70 {L"mask", NS_REQ_ZERO, FALSE},
71 {L"gateway", NS_REQ_ZERO, FALSE},
72 {L"gwmetric", NS_REQ_ZERO, FALSE}};
73 TOKEN_VALUE ptvSource[] = {{L"static", 1},
74 {L"dhcp", 2}};
75 GUID InterfaceGUID;
76 PDWORD pdwTagType = NULL;
77 DWORD i, dwSource = 0;
78 BOOL bHaveName = FALSE, bHaveSource = FALSE;
79 DWORD dwError = ERROR_SUCCESS;
80
81 DPRINT1("IpSetAddress()\n");
82
83 pdwTagType = HeapAlloc(GetProcessHeap(),
84 0,
85 (dwArgCount - dwCurrentIndex) * sizeof(DWORD));
86 if (pdwTagType == NULL)
87 {
89 }
90
92 argv,
95 pttTags,
96 ARRAYSIZE(pttTags),
97 pdwTagType);
98 if (dwError != ERROR_SUCCESS)
99 {
100 DPRINT1("MatchTagsInCmdLine() failed (Error %lu)\n", dwError);
101 HeapFree(GetProcessHeap(), 0, pdwTagType);
102 return dwError;
103 }
104
105 for (i = 0; i < (dwArgCount - dwCurrentIndex); i++)
106 {
107 DPRINT1("Tag %lu: %lu\n", i, pdwTagType[i]);
108
109 switch (pdwTagType[i])
110 {
111 case 0: /* name */
112 DPRINT1("Tag: name (%S)\n", argv[i + dwCurrentIndex]);
113
115 &InterfaceGUID,
116 0, 0);
117 if (dwError != ERROR_SUCCESS)
118 {
119 DPRINT1("NhGetGuidFromInterfaceName() failed (Error %lu)\n", dwError);
123 dwError = ERROR_SUPPRESS_OUTPUT;
124 break;
125 }
126 DPRINT1("Interface: {%08lx-%04hx-%04hx-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
127 InterfaceGUID.Data1, InterfaceGUID.Data2, InterfaceGUID.Data3, InterfaceGUID.Data4[0], InterfaceGUID.Data4[1],
128 InterfaceGUID.Data4[2], InterfaceGUID.Data4[3], InterfaceGUID.Data4[4], InterfaceGUID.Data4[5], InterfaceGUID.Data4[6], InterfaceGUID.Data4[7]);
129 bHaveName = TRUE;
130 break;
131
132 case 1: /* source */
133 DPRINT1("Tag: source (%S)\n", argv[i + dwCurrentIndex]);
134
135 dwError = MatchEnumTag(hDllInstance,
137 ARRAYSIZE(ptvSource),
138 ptvSource,
139 &dwSource);
140 if (dwError != ERROR_SUCCESS)
141 {
142 DPRINT1("MatchEnumTag() failed (Error %lu)\n", dwError);
146 pttTags[pdwTagType[i]].pwszTag);
147 dwError = ERROR_SUPPRESS_OUTPUT;
148 break;
149 }
150 DPRINT1("Source: %lu\n", dwSource);
151 bHaveSource = TRUE;
152 break;
153
154 case 2: /* addr */
155 DPRINT1("Tag: addr (%S)\n", argv[i + dwCurrentIndex]);
156 break;
157
158 case 3: /* mask */
159 DPRINT1("Tag: mask (%S)\n", argv[i + dwCurrentIndex]);
160 break;
161
162 case 4: /* gateway */
163 DPRINT1("Tag: gateway (%S)\n", argv[i + dwCurrentIndex]);
164 break;
165
166 case 5: /* gwmetric */
167 DPRINT1("Tag: gwmetric (%S)\n", argv[i + dwCurrentIndex]);
168 break;
169
170 default:
171 DPRINT1("Unknown tag type %lu\n", pdwTagType[i]);
172 break;
173 }
174 }
175
176 if (pdwTagType)
177 HeapFree(GetProcessHeap(), 0, pdwTagType);
178
179
180 /* Check parameters */
181
182 /* The interface name is mandatory */
183 if (bHaveName == FALSE)
184 {
185 DPRINT1("The Name argument is mssing!\n");
186// return ERROR_INVALID_SYNTAX;
187 }
188
189 if (bHaveSource == FALSE)
190 {
191 DPRINT1("The Source argument is mssing!\n");
192// return ERROR_INVALID_SYNTAX;
193 }
194
195 DPRINT1("IpSetAddress() done (Error %lu)\n", dwError);
196 return dwError;
197}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define IDS_ERROR_BAD_VALUE
Definition: resource.h:49
#define IDS_ERROR_INVALID_INTERFACE
Definition: resource.h:48
DWORD WINAPI NhGetGuidFromInterfaceName(_In_ PWCHAR pInterfaceName, _Out_ GUID *pInterfaceGUID, DWORD dwUnknown3, DWORD dwUnknown4)
#define argv
Definition: mplay32.c:18
DWORD WINAPI MatchEnumTag(_In_ HANDLE hModule, _In_ LPCWSTR pwcArg, _In_ DWORD dwNumArg, _In_ const TOKEN_VALUE *pEnumTable, _Out_ PDWORD pdwValue)
Definition: netsh.c:346
DWORD WINAPI MatchTagsInCmdLine(_In_ HANDLE hModule, _Inout_ LPWSTR *ppwcArguments, _In_ DWORD dwCurrentIndex, _In_ DWORD dwArgCount, _In_ TAG_TYPE *pttTags, _In_ DWORD dwTagCount, _Out_ DWORD *pdwTagType)
Definition: netsh.c:375
@ NS_REQ_ZERO
Definition: netsh.h:34
#define ERROR_SUPPRESS_OUTPUT
Definition: netsh.h:26
_In_ LPWSTR _In_ DWORD dwCurrentIndex
Definition: netsh.h:139
DWORD * PDWORD
Definition: pedump.c:68

◆ IpShowAdapters()

static DWORD IpShowAdapters ( _In_ DWORD  DisplayFlags,
_In_ PWSTR  InterfaceName 
)
static

Definition at line 389 of file ip.c.

392{
394 DWORD dwCount = 0, i;
395 DWORD dwError;
396 WCHAR szFriendlyName[80];
397 DWORD dwFriendlyNameSize;
398 PTCPIP_PROPERTIES pProperties = NULL;
399 PWSTR pBuffer, pStart, pEnd;
400
402 &dwCount,
403 FALSE,
405 0);
406 if (dwError != ERROR_SUCCESS)
407 {
408 DPRINT1("NhpAllocateAndGetInterfaceInfoFromStack() failed (Error %lu)\n", dwError);
409 return dwError;
410 }
411
412 DPRINT("\nEntries: %lu\n", dwCount);
413
414 for (i = 0; i < dwCount; i++)
415 {
416 DPRINT("\nEntry %lu\n", i);
417 DPRINT("Index: %lu\n", pTable[i].Index);
418 DPRINT("MediaType: %lu\n", pTable[i].MediaType);
419 DPRINT("ConnectionType: %u\n", pTable[i].ConnectionType);
420 DPRINT("AccessType: %u\n", pTable[i].AccessType);
421 DPRINT("DeviceGuid: %08lx\n", pTable[i].DeviceGuid.Data1);
422 DPRINT("InterfaceGuid: %08lx\n", pTable[i].InterfaceGuid.Data1);
423
424 dwFriendlyNameSize = sizeof(szFriendlyName);
426 szFriendlyName,
427 &dwFriendlyNameSize,
428 0,
429 0);
430
431 if ((InterfaceName == NULL) || MatchToken(InterfaceName, szFriendlyName))
432 {
434
435 GetInterfaceProperties(&pTable[i].DeviceGuid, &pProperties);
436
437 if (pProperties)
438 {
439 DPRINT("Dhcp %lu\n", pProperties->dwDhcp);
440 DPRINT("IpAddress %S\n", pProperties->pszIpAddress);
441 DPRINT("SubnetMask %S\n", pProperties->pszSubnetMask);
442 DPRINT("Parameters %S\n", pProperties->pszParameters);
443
444 if (DisplayFlags & DISPLAY_ADRESSES)
445 {
447
448 if (pProperties->dwDhcp == 0)
449 {
450 if (*pProperties->pszIpAddress == UNICODE_NULL)
451 {
453 }
454 else
455 {
457 }
458
459 if (*pProperties->pszSubnetMask == UNICODE_NULL)
460 {
462 }
463 else
464 {
466 }
467
468 pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DefGw");
469 if (pBuffer)
470 {
473 }
474
475 pBuffer = ExtractParameterValue(pProperties->pszParameters, L"GwMetric");
476 if (pBuffer)
477 {
480 }
481 }
482
483 pBuffer = ExtractParameterValue(pProperties->pszParameters, L"IfMetric");
484 if (pBuffer)
485 {
488 }
489 }
490
491 if (DisplayFlags & DISPLAY_DNS)
492 {
493 if (pProperties->dwDhcp == 0)
494 {
495 pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DNS");
496 if (pBuffer)
497 {
498 pEnd = wcschr(pBuffer, L',');
499 if (pEnd == NULL)
500 {
502 }
503 else
504 {
505 pStart = pBuffer;
506 *pEnd = UNICODE_NULL;
508 for (;;)
509 {
510 pStart = pEnd + 1;
511 pEnd = wcschr(pStart, L',');
512 if (pEnd == NULL)
513 break;
514 *pEnd = UNICODE_NULL;
516 }
517 }
519 }
520 }
521 }
522
523 CoTaskMemFree(pProperties);
524 pProperties = NULL;
525 }
526 }
527 }
528
529 if (pTable)
531
532 return ERROR_SUCCESS;
533}
#define IDS_DEFAULTGATEWAY
Definition: resource.h:28
#define IDS_IPADDRESS
Definition: resource.h:26
#define IDS_SUBNETMASK
Definition: resource.h:27
#define IDS_EMPTYLINE
Definition: resource.h:16
#define DISPLAY_DNS
Definition: ip.c:20
#define DISPLAY_ADRESSES
Definition: ip.c:19
#define IDS_GATEWAYMETRIC
Definition: resource.h:35
#define IDS_NOIPADDRESS
Definition: resource.h:28
#define IDS_IP_HEADER
Definition: resource.h:25
#define IDS_NOSUBNETMASK
Definition: resource.h:31
#define IDS_DHCP_ON
Definition: resource.h:26
#define IDS_STATICNAMESERVER
Definition: resource.h:37
#define IDS_INTERFACEMETRIC
Definition: resource.h:36
#define IDS_DHCP_OFF
Definition: resource.h:27
BOOL WINAPI MatchToken(_In_ LPCWSTR pwszUserToken, _In_ LPCWSTR pwszCmdToken)
Definition: netsh.c:427
#define UNICODE_NULL

Referenced by IpShowAddresses(), IpShowConfig(), and IpShowDns().

◆ IpShowAddresses()

static DWORD WINAPI IpShowAddresses ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)
static

Definition at line 539 of file ip.c.

547{
548 PWSTR pszInterfaceName = NULL;
549
550 if (dwArgCount - dwCurrentIndex > 1)
552
553 if (dwArgCount - dwCurrentIndex == 1)
554 pszInterfaceName = argv[dwCurrentIndex];
555
556 return IpShowAdapters(DISPLAY_ADRESSES, pszInterfaceName);
557}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static DWORD IpShowAdapters(_In_ DWORD DisplayFlags, _In_ PWSTR InterfaceName)
Definition: ip.c:389

◆ IpShowConfig()

static DWORD WINAPI IpShowConfig ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)
static

Definition at line 563 of file ip.c.

571{
572 PWSTR pszInterfaceName = NULL;
573
574 if (dwArgCount - dwCurrentIndex > 1)
576
577 if (dwArgCount - dwCurrentIndex == 1)
578 pszInterfaceName = argv[dwCurrentIndex];
579
580 return IpShowAdapters(DISPLAY_ADRESSES | DISPLAY_DNS, pszInterfaceName);
581}

◆ IpShowDns()

static DWORD WINAPI IpShowDns ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)
static

Definition at line 587 of file ip.c.

595{
596 PWSTR pszInterfaceName = NULL;
597
598 if (dwArgCount - dwCurrentIndex > 1)
600
601 if (dwArgCount - dwCurrentIndex == 1)
602 pszInterfaceName = argv[dwCurrentIndex];
603
604 return IpShowAdapters(DISPLAY_DNS, pszInterfaceName);
605}

◆ IpStart()

static DWORD WINAPI IpStart ( _In_ const GUID pguidParent,
_In_ DWORD  dwVersion 
)
static

Definition at line 724 of file ip.c.

727{
728 NS_CONTEXT_ATTRIBUTES ContextAttributes;
729
730 DPRINT1("IpStart()\n");
731
732 ZeroMemory(&ContextAttributes, sizeof(ContextAttributes));
733 ContextAttributes.dwVersion = 1;
734 ContextAttributes.pwszContext = L"ip";
735 ContextAttributes.guidHelper = GUID_IFMON_IP;
736
737 ContextAttributes.ulNumTopCmds = 0;
738 ContextAttributes.pTopCmds = NULL;
739
740 ContextAttributes.ulNumGroups = sizeof(IpGroups) / sizeof(CMD_GROUP_ENTRY);
741 ContextAttributes.pCmdGroups = IpGroups;
742
743 ContextAttributes.pfnDumpFn = IpDumpFn;
744
745 RegisterContext(&ContextAttributes);
746
747 return ERROR_SUCCESS;
748}
DWORD WINAPI RegisterContext(_In_ const NS_CONTEXT_ATTRIBUTES *pChildContext)
Definition: context.c:909
static CMD_GROUP_ENTRY IpGroups[]
Definition: ip.c:48
static DWORD WINAPI IpDumpFn(_In_ LPCWSTR pwszRouter, _In_ LPWSTR *ppwcArguments, _In_ DWORD dwArgCount, _In_ LPCVOID pvData)
Definition: ip.c:611
#define ZeroMemory
Definition: minwinbase.h:31
Definition: netsh.h:158
CMD_ENTRY * pTopCmds
Definition: netsh.h:199
CMD_GROUP_ENTRY * pCmdGroups
Definition: netsh.h:201
PNS_CONTEXT_DUMP_FN pfnDumpFn
Definition: netsh.h:203

Referenced by RegisterIpHelper().

◆ RegisterIpHelper()

DWORD WINAPI RegisterIpHelper ( VOID  )

Definition at line 753 of file ip.c.

754{
755 NS_HELPER_ATTRIBUTES HelperAttributes;
756 GUID guidParent = GUID_IFMON_INTERFACE;
757
758 DPRINT1("RegisterIpHelper()\n");
759
760 ZeroMemory(&HelperAttributes, sizeof(HelperAttributes));
761 HelperAttributes.dwVersion = 1;
762 HelperAttributes.guidHelper = GUID_IFMON_IP;
763 HelperAttributes.pfnStart = IpStart;
764 HelperAttributes.pfnStop = NULL;
765 RegisterHelper(&guidParent, &HelperAttributes);
766
767 return ERROR_SUCCESS;
768}
static DWORD WINAPI IpStart(_In_ const GUID *pguidParent, _In_ DWORD dwVersion)
Definition: ip.c:724
DWORD WINAPI RegisterHelper(_In_ const GUID *pguidParentHelper, _In_ const NS_HELPER_ATTRIBUTES *pHelperAttributes)
Definition: helper.c:385
PNS_HELPER_STOP_FN pfnStop
Definition: netsh.h:180
PNS_HELPER_START_FN pfnStart
Definition: netsh.h:179

Referenced by InitHelperDll().

Variable Documentation

◆ IpGroups

CMD_GROUP_ENTRY IpGroups[]
static
Initial value:
=
{
{L"set", IDS_HLP_IP_SET, sizeof(IpSetCommands) / sizeof(CMD_ENTRY), 0, IpSetCommands, NULL},
{L"show", IDS_HLP_IP_SHOW, sizeof(IpShowCommands) / sizeof(CMD_ENTRY), 0, IpShowCommands, NULL},
}
static CMD_ENTRY IpShowCommands[]
Definition: ip.c:38
static CMD_ENTRY IpSetCommands[]
Definition: ip.c:30
#define IDS_HLP_IP_SHOW
Definition: resource.h:11
#define IDS_HLP_IP_SET
Definition: resource.h:6
Definition: netsh.h:148

Definition at line 48 of file ip.c.

Referenced by IpStart().

◆ IpSetAddress

FN_HANDLE_CMD IpSetAddress
static

Definition at line 22 of file ip.c.

◆ IpSetCommands

CMD_ENTRY IpSetCommands[]
static
Initial value:
=
{
}
static FN_HANDLE_CMD IpSetAddress
Definition: ip.c:22
#define IDS_HLP_IP_SET_ADDRESS
Definition: resource.h:7
#define IDS_HLP_IP_SET_ADDRESS_EX
Definition: resource.h:8

Definition at line 30 of file ip.c.

◆ IpShowAddresses

FN_HANDLE_CMD IpShowAddresses
static

Definition at line 23 of file ip.c.

◆ IpShowCommands

CMD_ENTRY IpShowCommands[]
static
Initial value:
=
{
}
static FN_HANDLE_CMD IpShowAddresses
Definition: ip.c:23
static FN_HANDLE_CMD IpShowConfig
Definition: ip.c:24
static FN_HANDLE_CMD IpShowDns
Definition: ip.c:25
#define IDS_HLP_DNS
Definition: resource.h:16
#define IDS_HLP_ADDRESSES
Definition: resource.h:12
#define IDS_HLP_DNS_EX
Definition: resource.h:17
#define IDS_HLP_ADDRESSES_EX
Definition: resource.h:13
#define IDS_HLP_CONFIG_EX
Definition: resource.h:15
#define IDS_HLP_CONFIG
Definition: resource.h:14

Definition at line 38 of file ip.c.

◆ IpShowConfig

FN_HANDLE_CMD IpShowConfig
static

Definition at line 24 of file ip.c.

◆ IpShowDns

FN_HANDLE_CMD IpShowDns
static

Definition at line 25 of file ip.c.