ReactOS 0.4.16-dev-2522-g97cc325
ipconfig.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winreg.h>
#include <iphlpapi.h>
#include <ndk/rtlfuncs.h>
#include <inaddr.h>
#include <windns.h>
#include <windns_undoc.h>
#include <dhcpcsdk.h>
#include <dhcpcapi.h>
#include <strsafe.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for ipconfig.c:

Go to the source code of this file.

Classes

struct  _RECORDTYPE
 

Macros

#define WIN32_NO_STATUS
 
#define GUID_LEN   40
 

Typedefs

typedef struct _RECORDTYPE RECORDTYPE
 
typedef struct _RECORDTYPEPRECORDTYPE
 

Functions

PCWSTR GetRecordTypeName (WORD wType)
 
PCSTR PrintMacAddr (PBYTE Mac)
 
_Ret_opt_z_ PWSTR timeToStr (_In_ time_t TimeStamp)
 
VOID DoFormatMessage (_In_ LONG ErrorCode)
 
PWSTR GetUnicodeAdapterName (_In_ PSTR pszAnsiName)
 
VOID GetAdapterFriendlyName (_In_ PSTR lpClass, _In_ DWORD cchFriendlyNameLength, _Out_ PWSTR pszFriendlyName)
 
VOID GetInterfaceFriendlyName (_In_ PCWSTR lpDeviceName, _In_ DWORD cchFriendlyNameLength, _Out_ PWSTR pszFriendlyName)
 
static VOID PrintAdapterDescription (PSTR lpClass)
 
static VOID PrintNodeType (_In_ UINT NodeType)
 
static VOID PrintAdapterTypeAndName (PIP_ADAPTER_INFO pAdapterInfo)
 
VOID ShowInfo (BOOL bShowHeader, BOOL bAll)
 
static BOOL MatchWildcard (_In_ PWSTR pszExpression, _In_ PWSTR pszName)
 
VOID Release (PWSTR pszAdapterName)
 
VOID Renew (PWSTR pszAdapterName)
 
VOID FlushDns (VOID)
 
VOID RegisterDns (VOID)
 
static VOID DisplayDnsRecord (PWSTR pszName, WORD wType)
 
VOID DisplayDns (VOID)
 
VOID ShowClassId (PWSTR pszAdapterName)
 
VOID SetClassId (PWSTR pszAdapterName, PWSTR pszClassId)
 
VOID Usage (_In_ BOOL Error)
 
int wmain (int argc, wchar_t *argv[])
 

Variables

HINSTANCE hInstance
 
HANDLE ProcessHeap
 
RECORDTYPE TypeArray []
 

Macro Definition Documentation

◆ GUID_LEN

#define GUID_LEN   40

Definition at line 39 of file ipconfig.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file ipconfig.c.

Typedef Documentation

◆ PRECORDTYPE

◆ RECORDTYPE

Function Documentation

◆ DisplayDns()

VOID DisplayDns ( VOID  )

Definition at line 1175 of file ipconfig.c.

1176{
1177 PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
1178
1180
1181 if (!DnsGetCacheDataTable(&DnsEntry))
1182 {
1184 return;
1185 }
1186
1187 if (DnsEntry == NULL)
1188 return;
1189
1190 pThisEntry = DnsEntry;
1191 while (pThisEntry != NULL)
1192 {
1193 pNextEntry = pThisEntry->pNext;
1194
1195 if (pThisEntry->wType1 != DNS_TYPE_ZERO)
1196 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
1197
1198 if (pThisEntry->wType2 != DNS_TYPE_ZERO)
1199 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
1200
1201 if (pThisEntry->pszName)
1202 LocalFree(pThisEntry->pszName);
1203 LocalFree(pThisEntry);
1204
1205 pThisEntry = pNextEntry;
1206 }
1207}
#define IDS_HEADER
Definition: resource.h:3
#define StdOut
Definition: conutils_noros.h:6
void ConResPrintf(FILE *fp, UINT nID,...)
#define NULL
Definition: types.h:112
BOOL WINAPI DnsGetCacheDataTable(_Out_ PDNS_CACHE_ENTRY *DnsCache)
Definition: query.c:1055
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
VOID DoFormatMessage(_In_ LONG ErrorCode)
Definition: ipconfig.c:198
static VOID DisplayDnsRecord(PWSTR pszName, WORD wType)
Definition: ipconfig.c:1047
#define DNS_TYPE_ZERO
Definition: windns.h:40
Definition: windns_undoc.h:9
struct _DNS_CACHE_ENTRY * pNext
Definition: windns_undoc.h:10
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by wmain().

◆ DisplayDnsRecord()

static VOID DisplayDnsRecord ( PWSTR  pszName,
WORD  wType 
)
static

Definition at line 1047 of file ipconfig.c.

1050{
1051 PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
1052 WCHAR szBuffer[48];
1053 IN_ADDR Addr4;
1054 IN6_ADDR Addr6;
1056
1057 ConResPrintf(StdOut, IDS_DNSNAME, pszName);
1059
1060 pQueryResults = NULL;
1061 Status = DnsQuery_W(pszName,
1062 wType,
1064 NULL,
1065 (PDNS_RECORD *)&pQueryResults,
1066 NULL);
1067 if (Status != ERROR_SUCCESS)
1068 {
1070 {
1072 }
1073 else if (Status == DNS_INFO_NO_RECORDS)
1074 {
1076 }
1077 return;
1078 }
1079
1080 pThisRecord = pQueryResults;
1081 while (pThisRecord != NULL)
1082 {
1083 pNextRecord = pThisRecord->pNext;
1084
1085 ConResPrintf(StdOut, IDS_DNSRECORDNAME, pThisRecord->pName);
1086 ConResPrintf(StdOut, IDS_DNSRECORDTYPE, pThisRecord->wType);
1087 ConResPrintf(StdOut, IDS_DNSRECORDTTL, pThisRecord->dwTtl);
1088 ConResPrintf(StdOut, IDS_DNSRECORDLENGTH, pThisRecord->wDataLength);
1089
1090 switch (pThisRecord->Flags.S.Section)
1091 {
1092 case DnsSectionQuestion:
1094 break;
1095
1096 case DnsSectionAnswer:
1098 break;
1099
1102 break;
1103
1106 break;
1107 }
1108
1109 switch (pThisRecord->wType)
1110 {
1111 case DNS_TYPE_A:
1112 Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
1113 RtlIpv4AddressToStringW(&Addr4, szBuffer);
1114 ConResPrintf(StdOut, IDS_DNSTYPEA, szBuffer);
1115 break;
1116
1117 case DNS_TYPE_NS:
1118 ConResPrintf(StdOut, IDS_DNSTYPENS, pThisRecord->Data.NS.pNameHost);
1119 break;
1120
1121 case DNS_TYPE_CNAME:
1122 ConResPrintf(StdOut, IDS_DNSTYPECNAME, pThisRecord->Data.CNAME.pNameHost);
1123 break;
1124
1125 case DNS_TYPE_SOA:
1127 pThisRecord->Data.SOA.pNamePrimaryServer,
1128 pThisRecord->Data.SOA.pNameAdministrator,
1129 pThisRecord->Data.SOA.dwSerialNo);
1131 pThisRecord->Data.SOA.dwRefresh,
1132 pThisRecord->Data.SOA.dwRetry,
1133 pThisRecord->Data.SOA.dwExpire,
1134 pThisRecord->Data.SOA.dwDefaultTtl);
1135 break;
1136
1137 case DNS_TYPE_PTR:
1138 ConResPrintf(StdOut, IDS_DNSTYPEPTR, pThisRecord->Data.PTR.pNameHost);
1139 break;
1140
1141 case DNS_TYPE_MX:
1143 pThisRecord->Data.MX.pNameExchange,
1144 pThisRecord->Data.MX.wPreference,
1145 pThisRecord->Data.MX.Pad);
1146 break;
1147
1148 case DNS_TYPE_AAAA:
1149 RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address, sizeof(Addr6));
1150 RtlIpv6AddressToStringW(&Addr6, szBuffer);
1152 break;
1153
1154 case DNS_TYPE_ATMA:
1156 break;
1157
1158 case DNS_TYPE_SRV:
1160 pThisRecord->Data.SRV.pNameTarget,
1161 pThisRecord->Data.SRV.wPriority,
1162 pThisRecord->Data.SRV.wWeight,
1163 pThisRecord->Data.SRV.wPort);
1164 break;
1165 }
1166 ConPuts(StdOut, L"\n\n");
1167
1168 pThisRecord = pNextRecord;
1169 }
1170
1172}
#define IDS_DNSSECTIONAUTHORITY
Definition: resource.h:55
#define IDS_DNSRECORDTYPE
Definition: resource.h:50
#define IDS_DNSSECTIONANSWER
Definition: resource.h:54
#define IDS_DNSTYPESOA2
Definition: resource.h:61
#define IDS_DNSTYPESRV
Definition: resource.h:66
#define IDS_DNSTYPEAAAA
Definition: resource.h:64
#define IDS_DNSRECORDTTL
Definition: resource.h:51
#define IDS_DNSTYPECNAME
Definition: resource.h:59
#define IDS_DNSNORECORD
Definition: resource.h:71
#define IDS_DNSRECORDLENGTH
Definition: resource.h:52
#define IDS_DNSSECTIONADDITIONAL
Definition: resource.h:56
#define IDS_DNSSECTIONQUESTION
Definition: resource.h:53
#define IDS_DNSNAME
Definition: resource.h:47
#define IDS_DNSRECORDNAME
Definition: resource.h:49
#define IDS_DNSLINE
Definition: resource.h:48
#define IDS_DNSTYPEA
Definition: resource.h:57
#define IDS_DNSTYPENS
Definition: resource.h:58
#define IDS_DNSTYPEPTR
Definition: resource.h:62
#define IDS_DNSTYPEATMA
Definition: resource.h:65
#define IDS_DNSTYPEMX
Definition: resource.h:63
#define IDS_DNSNONAME
Definition: resource.h:72
#define IDS_DNSTYPESOA1
Definition: resource.h:60
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
DNS_STATUS WINAPI DnsQuery_W(LPCWSTR Name, WORD Type, DWORD Options, PVOID Extra, PDNS_RECORD *QueryResultSet, PVOID *Reserved)
Definition: query.c:469
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
#define L(x)
Definition: resources.c:13
Status
Definition: gdiplustypes.h:25
PCWSTR GetRecordTypeName(WORD wType)
Definition: ipconfig.c:104
NTSYSAPI PWSTR NTAPI RtlIpv4AddressToStringW(_In_ const struct in_addr *Addr, _Out_writes_(16) PWCHAR S)
NTSYSAPI PWSTR NTAPI RtlIpv6AddressToStringW(_In_ const struct in6_addr *Addr, _Out_writes_(46) PWSTR S)
#define DNS_TYPE_MX
Definition: windns.h:55
#define DNS_TYPE_ATMA
Definition: windns.h:74
@ DnsSectionAdditional
Definition: windns.h:156
@ DnsSectionAnswer
Definition: windns.h:154
@ DnsSectionQuestion
Definition: windns.h:153
@ DnsSectionAuthority
Definition: windns.h:155
@ DnsFreeRecordList
Definition: windns.h:139
#define DNS_TYPE_PTR
Definition: windns.h:52
#define DNS_TYPE_CNAME
Definition: windns.h:45
#define DNS_TYPE_NS
Definition: windns.h:42
#define DNS_TYPE_SOA
Definition: windns.h:46
#define DNS_QUERY_NO_WIRE_QUERY
Definition: windns.h:13
#define DNS_TYPE_SRV
Definition: windns.h:73
#define DNS_TYPE_AAAA
Definition: windns.h:68
#define DNS_TYPE_A
Definition: windns.h:41
struct _DnsRecordW * pNext
Definition: windns.h:598
Definition: inet.h:67
Definition: tcpip.h:126
u_long S_addr
Definition: tcpip.h:131
union in_addr::@1116 S_un
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
LONG DNS_STATUS
Definition: windns.h:183
#define DNS_INFO_NO_RECORDS
Definition: winerror.h:2671
#define DNS_ERROR_RCODE_NAME_ERROR
Definition: winerror.h:2628
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DisplayDns().

◆ DoFormatMessage()

VOID DoFormatMessage ( _In_ LONG  ErrorCode)

Definition at line 198 of file ipconfig.c.

200{
201 if (ErrorCode == 0)
203
206 NULL,
207 ErrorCode,
209}
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:835
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400

Referenced by DisplayDns(), FlushDns(), PrintAdapterDescription(), Release(), Renew(), SetClassId(), and ShowInfo().

◆ FlushDns()

VOID FlushDns ( VOID  )

Definition at line 1023 of file ipconfig.c.

1024{
1026
1028 {
1030 }
1031 else
1032 {
1035 }
1036}
#define IDS_DNSFLUSHERROR
Definition: resource.h:73
#define IDS_DNSFLUSHSUCCESS
Definition: resource.h:74
BOOL WINAPI DnsFlushResolverCache(VOID)
Definition: query.c:933

Referenced by wmain().

◆ GetAdapterFriendlyName()

VOID GetAdapterFriendlyName ( _In_ PSTR  lpClass,
_In_ DWORD  cchFriendlyNameLength,
_Out_ PWSTR  pszFriendlyName 
)

Definition at line 231 of file ipconfig.c.

235{
236 HKEY hKey = NULL;
237 CHAR Path[256];
238 PCSTR PrePath = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
239 PCSTR PostPath = "\\Connection";
240 size_t PathSize;
241 DWORD dwType;
242 DWORD dwDataSize;
243
244 /* don't overflow the buffer */
245 PathSize = strlen(PrePath) + strlen(lpClass) + strlen(PostPath) + 1;
246 if (PathSize > _countof(Path))
247 return;
248
249 sprintf(Path, "%s%s%s", PrePath, lpClass, PostPath);
250
252 Path,
253 0,
254 KEY_READ,
255 &hKey) == ERROR_SUCCESS)
256 {
257 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
259 L"Name",
260 NULL,
261 &dwType,
262 (PBYTE)pszFriendlyName,
263 &dwDataSize);
264 }
265
266 if (hKey != NULL)
268}
PRTL_UNICODE_STRING_BUFFER Path
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define sprintf
Definition: sprintf.c:45
#define KEY_READ
Definition: nt_native.h:1026
BYTE * PBYTE
Definition: pedump.c:66
#define _countof(array)
Definition: sndvol32.h:70
const char * PCSTR
Definition: typedefs.h:52
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char CHAR
Definition: xmlstorage.h:175

Referenced by PrintAdapterTypeAndName(), Release(), Renew(), and SetClassId().

◆ GetInterfaceFriendlyName()

VOID GetInterfaceFriendlyName ( _In_ PCWSTR  lpDeviceName,
_In_ DWORD  cchFriendlyNameLength,
_Out_ PWSTR  pszFriendlyName 
)

Definition at line 271 of file ipconfig.c.

275{
276 HKEY hKey = NULL;
277 WCHAR Path[256];
278 PCWSTR PrePath = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
279 PCWSTR PostPath = L"\\Connection";
280 PCWSTR DevicePrefix = L"\\DEVICE\\TCPIP_";
281 size_t PathSize;
282 DWORD dwType;
283 DWORD dwDataSize;
284
285 size_t dwPrefixLength = wcslen(DevicePrefix);
286
287 /* don't overflow the buffer */
288 PathSize = wcslen(PrePath) + wcslen(lpDeviceName) - dwPrefixLength + wcslen(PostPath) + 1;
289 if (PathSize > _countof(Path))
290 return;
291
292 swprintf(Path, L"%s%s%s", PrePath, &lpDeviceName[dwPrefixLength], PostPath);
293
295 Path,
296 0,
297 KEY_READ,
298 &hKey) == ERROR_SUCCESS)
299 {
300 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
302 L"Name",
303 NULL,
304 &dwType,
305 (PBYTE)pszFriendlyName,
306 &dwDataSize);
307 }
308
309 if (hKey != NULL)
311}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define swprintf
Definition: precomp.h:40
const uint16_t * PCWSTR
Definition: typedefs.h:57

◆ GetRecordTypeName()

PCWSTR GetRecordTypeName ( WORD  wType)

Definition at line 104 of file ipconfig.c.

105{
106 static WCHAR szType[8];
107 INT i;
108
109 for (i = 0; ; i++)
110 {
111 if (TypeArray[i].pszRecordName == NULL)
112 break;
113
114 if (TypeArray[i].wRecordType == wType)
115 return TypeArray[i].pszRecordName;
116 }
117
118 swprintf(szType, L"%hu", wType);
119
120 return szType;
121}
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
RECORDTYPE TypeArray[]
Definition: ipconfig.c:44
PCWSTR pszRecordName
Definition: ipconfig.c:36
int32_t INT
Definition: typedefs.h:58

Referenced by DisplayDnsRecord().

◆ GetUnicodeAdapterName()

PWSTR GetUnicodeAdapterName ( _In_ PSTR  pszAnsiName)

Definition at line 212 of file ipconfig.c.

214{
215 PWSTR pszUnicodeName;
216 size_t i, len;
217
218 len = strlen(pszAnsiName);
219 pszUnicodeName = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
220 if (pszUnicodeName == NULL)
221 return NULL;
222
223 for (i = 0; i < len; i++)
224 pszUnicodeName[i] = (WCHAR)pszAnsiName[i];
225 pszUnicodeName[i] = UNICODE_NULL;
226
227 return pszUnicodeName;
228}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
GLenum GLsizei len
Definition: glext.h:6722
#define UNICODE_NULL
uint16_t * PWSTR
Definition: typedefs.h:56

◆ MatchWildcard()

static BOOL MatchWildcard ( _In_ PWSTR  pszExpression,
_In_ PWSTR  pszName 
)
static

Definition at line 774 of file ipconfig.c.

777{
778 WCHAR *pCharE, *pCharN, charE, charN;
779
780 if (pszExpression == NULL)
781 return TRUE;
782
783 if (pszName == NULL)
784 return FALSE;
785
786 pCharE = pszExpression;
787 pCharN = pszName;
788 while (*pCharE != UNICODE_NULL)
789 {
790 charE = towlower(*pCharE);
791 charN = towlower(*pCharN);
792
793 if (charE == L'*')
794 {
795 if (*(pCharE + 1) != charN)
796 pCharN++;
797 else
798 pCharE++;
799 }
800 else if (charE == L'?')
801 {
802 pCharE++;
803 pCharN++;
804 }
805 else if (charE == charN)
806 {
807 pCharE++;
808 pCharN++;
809 }
810 else
811 {
812 return FALSE;
813 }
814 }
815
816 return TRUE;
817}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define towlower(c)
Definition: wctype.h:97

Referenced by Release(), Renew(), and SetClassId().

◆ PrintAdapterDescription()

static VOID PrintAdapterDescription ( PSTR  lpClass)
static

Definition at line 315 of file ipconfig.c.

316{
317 HKEY hBaseKey = NULL;
319 PSTR lpKeyClass = NULL;
320 PSTR lpConDesc = NULL;
321 PWSTR lpPath = NULL;
322 WCHAR szPrePath[] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\";
323 DWORD dwType;
324 DWORD dwDataSize;
325 INT i;
326
328 szPrePath,
329 0,
330 KEY_READ,
331 &hBaseKey) != ERROR_SUCCESS)
332 {
333 return;
334 }
335
336 for (i = 0; ; i++)
337 {
338 size_t PathSize;
339 LONG Status;
340 WCHAR szName[10];
341 DWORD NameLen = 9;
342
343 if ((Status = RegEnumKeyExW(hBaseKey,
344 i,
345 szName,
346 &NameLen,
347 NULL,
348 NULL,
349 NULL,
350 NULL)) != ERROR_SUCCESS)
351 {
353 {
355 lpConDesc = NULL;
356 goto CLEANUP;
357 }
358 else
359 continue;
360 }
361
362 PathSize = wcslen(szPrePath) + wcslen(szName) + 1;
363 lpPath = (PWSTR)HeapAlloc(ProcessHeap,
364 0,
365 PathSize * sizeof(WCHAR));
366 if (lpPath == NULL)
367 goto CLEANUP;
368
369 swprintf(lpPath, L"%s%s", szPrePath, szName);
370
371 //MessageBox(NULL, lpPath, NULL, 0);
372
374 lpPath,
375 0,
376 KEY_READ,
378 {
379 goto CLEANUP;
380 }
381
382 HeapFree(ProcessHeap, 0, lpPath);
383 lpPath = NULL;
384
386 "NetCfgInstanceId",
387 NULL,
388 &dwType,
389 NULL,
390 &dwDataSize) == ERROR_SUCCESS)
391 {
392 lpKeyClass = (PSTR)HeapAlloc(ProcessHeap,
393 0,
394 dwDataSize);
395 if (lpKeyClass == NULL)
396 goto CLEANUP;
397
399 "NetCfgInstanceId",
400 NULL,
401 &dwType,
402 (PBYTE)lpKeyClass,
403 &dwDataSize) != ERROR_SUCCESS)
404 {
405 HeapFree(ProcessHeap, 0, lpKeyClass);
406 lpKeyClass = NULL;
407 continue;
408 }
409 }
410 else
411 continue;
412
413 if (!strcmp(lpClass, lpKeyClass))
414 {
415 HeapFree(ProcessHeap, 0, lpKeyClass);
416 lpKeyClass = NULL;
417
419 "DriverDesc",
420 NULL,
421 &dwType,
422 NULL,
423 &dwDataSize) == ERROR_SUCCESS)
424 {
425 lpConDesc = (PSTR)HeapAlloc(ProcessHeap,
426 0,
427 dwDataSize);
428 if (lpConDesc != NULL)
429 {
431 "DriverDesc",
432 NULL,
433 &dwType,
434 (PBYTE)lpConDesc,
435 &dwDataSize) == ERROR_SUCCESS)
436 {
437 printf("%s", lpConDesc);
438 }
439
440 HeapFree(ProcessHeap, 0, lpConDesc);
441 lpConDesc = NULL;
442 }
443 }
444
445 break;
446 }
447 }
448
449CLEANUP:
450 if (hBaseKey != NULL)
451 RegCloseKey(hBaseKey);
452 if (hClassKey != NULL)
454 if (lpPath != NULL)
455 HeapFree(ProcessHeap, 0, lpPath);
456 if (lpKeyClass != NULL)
457 HeapFree(ProcessHeap, 0, lpKeyClass);
458}
HKEY hClassKey
Definition: umpnpmgr.c:45
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define HeapFree(x, y, z)
Definition: compat.h:735
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
#define printf
Definition: freeldr.h:104
HANDLE ProcessHeap
Definition: ipconfig.c:42
long LONG
Definition: pedump.c:60
static const WCHAR szName[]
Definition: powrprof.c:45
char * PSTR
Definition: typedefs.h:51

Referenced by ShowInfo().

◆ PrintAdapterTypeAndName()

static VOID PrintAdapterTypeAndName ( PIP_ADAPTER_INFO  pAdapterInfo)
static

Definition at line 491 of file ipconfig.c.

493{
494 WCHAR szFriendlyName[MAX_PATH];
495
496 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
497
498 switch (pAdapterInfo->Type)
499 {
501 ConResPrintf(StdOut, IDS_OTHER, szFriendlyName);
502 break;
503
505 ConResPrintf(StdOut, IDS_ETH, szFriendlyName);
506 break;
507
509 ConResPrintf(StdOut, IDS_TOKEN, szFriendlyName);
510 break;
511
512 case MIB_IF_TYPE_FDDI:
513 ConResPrintf(StdOut, IDS_FDDI, szFriendlyName);
514 break;
515
516 case MIB_IF_TYPE_PPP:
517 ConResPrintf(StdOut, IDS_PPP, szFriendlyName);
518 break;
519
521 ConResPrintf(StdOut, IDS_LOOP, szFriendlyName);
522 break;
523
524 case MIB_IF_TYPE_SLIP:
525 ConResPrintf(StdOut, IDS_SLIP, szFriendlyName);
526 break;
527
529 ConResPrintf(StdOut, IDS_WIFI, szFriendlyName);
530 break;
531
532 default:
533 ConResPrintf(StdOut, IDS_UNKNOWNADAPTER, szFriendlyName);
534 break;
535 }
536}
#define IDS_UNKNOWNADAPTER
Definition: resource.h:17
#define IDS_LOOP
Definition: resource.h:43
#define IDS_FDDI
Definition: resource.h:41
#define IDS_OTHER
Definition: resource.h:38
#define IDS_WIFI
Definition: resource.h:45
#define IDS_TOKEN
Definition: resource.h:40
#define IDS_ETH
Definition: resource.h:39
#define IDS_PPP
Definition: resource.h:42
#define IDS_SLIP
Definition: resource.h:44
#define MAX_PATH
Definition: compat.h:34
VOID GetAdapterFriendlyName(_In_ PSTR lpClass, _In_ DWORD cchFriendlyNameLength, _Out_ PWSTR pszFriendlyName)
Definition: ipconfig.c:231
#define MIB_IF_TYPE_ETHERNET
Definition: ipifcons.h:223
#define MIB_IF_TYPE_LOOPBACK
Definition: ipifcons.h:227
#define MIB_IF_TYPE_SLIP
Definition: ipifcons.h:228
#define MIB_IF_TYPE_OTHER
Definition: ipifcons.h:222
#define IF_TYPE_IEEE80211
Definition: ipifcons.h:91
#define MIB_IF_TYPE_TOKENRING
Definition: ipifcons.h:224
#define MIB_IF_TYPE_FDDI
Definition: ipifcons.h:225
#define MIB_IF_TYPE_PPP
Definition: ipifcons.h:226
char AdapterName[MAX_ADAPTER_NAME_LENGTH+4]
Definition: iptypes.h:44

Referenced by ShowInfo().

◆ PrintMacAddr()

PCSTR PrintMacAddr ( PBYTE  Mac)

Definition at line 124 of file ipconfig.c.

125{
126 static CHAR MacAddr[20];
127
128 sprintf(MacAddr, "%02X-%02X-%02X-%02X-%02X-%02X",
129 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
130
131 return MacAddr;
132}

Referenced by ShowInfo().

◆ PrintNodeType()

static VOID PrintNodeType ( _In_ UINT  NodeType)
static

Definition at line 462 of file ipconfig.c.

464{
465 switch (NodeType)
466 {
469 break;
470
473 break;
474
475 case MIXED_NODETYPE:
477 break;
478
479 case HYBRID_NODETYPE:
481 break;
482
483 default :
485 break;
486 }
487}
NodeType
Definition: Node.h:6
#define IDS_NODETYPEP2P
Definition: resource.h:7
#define IDS_NODETYPEBCAST
Definition: resource.h:6
#define IDS_NODETYPEUNKNOWN
Definition: resource.h:10
#define IDS_NODETYPEMIXED
Definition: resource.h:8
#define IDS_NODETYPEHYBRID
Definition: resource.h:9
#define MIXED_NODETYPE
Definition: iptypes.h:27
#define HYBRID_NODETYPE
Definition: iptypes.h:28
#define PEER_TO_PEER_NODETYPE
Definition: iptypes.h:26
#define BROADCAST_NODETYPE
Definition: iptypes.h:25

Referenced by ShowInfo().

◆ RegisterDns()

VOID RegisterDns ( VOID  )

Definition at line 1039 of file ipconfig.c.

1040{
1041 /* FIXME */
1042 printf("\nSorry /registerdns is not implemented yet\n");
1043}

Referenced by wmain().

◆ Release()

VOID Release ( PWSTR  pszAdapterName)

Definition at line 820 of file ipconfig.c.

822{
823 PIP_ADAPTER_INFO pAdapterInfo = NULL;
824 PIP_ADAPTER_INFO pAdapter = NULL;
825 ULONG adaptOutBufLen = 0;
826 ULONG ret = 0;
827 WCHAR szFriendlyName[MAX_PATH];
828 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
829 MIB_IFROW mibEntry;
832
834
835 /* call GetAdaptersInfo to obtain the adapter info */
836 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
838 {
840 return;
841 }
842
843 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
844 if (pAdapterInfo == NULL)
845 {
847 return;
848 }
849
850 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
851 if (ret != NO_ERROR)
852 {
854 goto done;
855 }
856
858
859 pAdapter = pAdapterInfo;
860
861 while (pAdapter)
862 {
863 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
864
865 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
866 {
868
869 mibEntry.dwIndex = pAdapter->Index;
870 GetIfEntry(&mibEntry);
871
874 {
875 if (pAdapter->DhcpEnabled)
876 {
877 if (strcmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0"))
878 {
879 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
880
881 /* Call DhcpReleaseParameters to release the IP address on the specified adapter. */
882 ret = DhcpReleaseParameters(szUnicodeAdapterName);
883 if (ret != NO_ERROR)
884 {
885 ConResPrintf(StdOut, IDS_DHCPRELEASEERROR, szFriendlyName);
887 }
888 }
889 else
890 {
892 }
893 }
894 else
895 {
896 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
897 }
898 }
899 else
900 {
901 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
902 }
903 }
904
905 pAdapter = pAdapter->Next;
906 }
907
909
910 if (bFoundAdapter == FALSE)
911 {
913 }
914 else
915 {
917 }
918
919done:
920 if (pAdapterInfo)
921 HeapFree(ProcessHeap, 0, pAdapterInfo);
922}
#define IDS_DHCPRELEASED
Definition: resource.h:78
#define IDS_DHCPNOTENABLED
Definition: resource.h:76
#define IDS_DHCPNOADAPTER
Definition: resource.h:77
#define IDS_DHCPNOTCONNECTED
Definition: resource.h:75
#define IDS_DHCPRELEASEERROR
Definition: resource.h:79
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
static BOOL bFoundAdapter
Definition: deskmon.c:13
DWORD APIENTRY DhcpCApiInitialize(_Out_ LPDWORD Version)
Definition: dhcpcsvc.c:213
DWORD APIENTRY DhcpReleaseParameters(_In_ PWSTR AdapterName)
Definition: dhcpcsvc.c:429
VOID APIENTRY DhcpCApiCleanup(VOID)
Definition: dhcpcsvc.c:227
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID ShowInfo(BOOL bShowHeader, BOOL bAll)
Definition: ipconfig.c:539
static BOOL MatchWildcard(_In_ PWSTR pszExpression, _In_ PWSTR pszName)
Definition: ipconfig.c:774
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
#define MIB_IF_OPER_STATUS_CONNECTED
Definition: ipifcons.h:250
#define MIB_IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:251
_In_ DWORD dwVersion
Definition: netsh.h:85
#define MAX_ADAPTER_NAME_LENGTH
Definition: iptypes.h:16
mbstowcs
Definition: stdlib.h:925
char String[4 *4]
Definition: iptypes.h:31
struct _IP_ADAPTER_INFO * Next
Definition: iptypes.h:42
IP_ADDR_STRING IpAddressList
Definition: iptypes.h:52
UINT DhcpEnabled
Definition: iptypes.h:50
IP_ADDRESS_STRING IpAddress
Definition: iptypes.h:36
INTERNAL_IF_OPER_STATUS dwOperStatus
Definition: ifmib.h:45
DWORD dwIndex
Definition: ifmib.h:38
uint32_t ULONG
Definition: typedefs.h:59
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:307

◆ Renew()

VOID Renew ( PWSTR  pszAdapterName)

Definition at line 925 of file ipconfig.c.

927{
928 PIP_ADAPTER_INFO pAdapterInfo = NULL;
929 PIP_ADAPTER_INFO pAdapter = NULL;
930 ULONG adaptOutBufLen = 0;
931 ULONG ret = 0;
932 WCHAR szFriendlyName[MAX_PATH];
933 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
934 MIB_IFROW mibEntry;
937
939
940 /* call GetAdaptersInfo to obtain the adapter info */
941 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
943 {
945 return;
946 }
947
948 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
949 if (pAdapterInfo == NULL)
950 {
952 return;
953 }
954
955 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
956 if (ret != NO_ERROR)
957 {
959 goto done;
960 }
961
963
964 pAdapter = pAdapterInfo;
965
966 while (pAdapter)
967 {
968 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
969
970 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
971 {
973
974 mibEntry.dwIndex = pAdapter->Index;
975 GetIfEntry(&mibEntry);
976
979 {
980 if (pAdapter->DhcpEnabled)
981 {
982 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
983
984 /* Call DhcpAcquireParameters to renew the IP address on the specified adapter. */
985 ret = DhcpAcquireParameters(szUnicodeAdapterName);
986 if (ret != NO_ERROR)
987 {
988 ConResPrintf(StdOut, IDS_DHCPRENEWERROR, szFriendlyName);
990 }
991 }
992 else
993 {
994 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
995 }
996 }
997 else
998 {
999 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
1000 }
1001 }
1002
1003 pAdapter = pAdapter->Next;
1004 }
1005
1007
1008 if (bFoundAdapter == FALSE)
1009 {
1011 }
1012 else
1013 {
1015 }
1016
1017done:
1018 if (pAdapterInfo)
1019 HeapFree(ProcessHeap, 0, pAdapterInfo);
1020}
#define IDS_DHCPRENEWERROR
Definition: resource.h:80
DWORD APIENTRY DhcpAcquireParameters(_In_ PWSTR AdapterName)
Definition: dhcpcsvc.c:243

Referenced by wmain().

◆ SetClassId()

VOID SetClassId ( PWSTR  pszAdapterName,
PWSTR  pszClassId 
)

Definition at line 1217 of file ipconfig.c.

1220{
1221 PIP_ADAPTER_INFO pAdapterInfo = NULL;
1222 PIP_ADAPTER_INFO pAdapter = NULL, pFoundAdapter = NULL;
1223 ULONG adaptOutBufLen = 0;
1224 ULONG ret = 0;
1225 WCHAR szFriendlyName[MAX_PATH];
1226 WCHAR szKeyName[256];
1227 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
1228 MIB_IFROW mibEntry;
1229 HKEY hKey;
1230 DHCP_PNP_EVENT PnpEvent;
1231
1233
1234 /* call GetAdaptersInfo to obtain the adapter info */
1235 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1237 {
1239 return;
1240 }
1241
1242 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
1243 if (pAdapterInfo == NULL)
1244 {
1246 return;
1247 }
1248
1249 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1250 if (ret != NO_ERROR)
1251 {
1252 DoFormatMessage(0);
1253 goto done;
1254 }
1255
1256 pAdapter = pAdapterInfo;
1257 while (pAdapter)
1258 {
1259 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
1260
1261 if (MatchWildcard(pszAdapterName, szFriendlyName))
1262 {
1263 mibEntry.dwIndex = pAdapter->Index;
1264 GetIfEntry(&mibEntry);
1265
1268 {
1269 pFoundAdapter = pAdapter;
1270 break;
1271 }
1272 }
1273
1274 pAdapter = pAdapter->Next;
1275 }
1276
1277 if (pFoundAdapter)
1278 {
1279 swprintf(szKeyName,
1280 L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%S",
1281 pFoundAdapter->AdapterName);
1282
1284 szKeyName,
1285 0,
1286 KEY_WRITE,
1287 &hKey);
1288 if (ret != ERROR_SUCCESS)
1289 {
1290 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1292 goto done;
1293 }
1294
1295 if (pszClassId == NULL)
1296 pszClassId = L"";
1297
1299 L"DhcpClassId",
1300 0, REG_SZ,
1301 (PBYTE)pszClassId,
1302 (DWORD)((wcslen(pszClassId) + 1) * sizeof(WCHAR)));
1304 if (ret != ERROR_SUCCESS)
1305 {
1306 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1308 goto done;
1309 }
1310
1311 mbstowcs(szUnicodeAdapterName, pFoundAdapter->AdapterName, strlen(pFoundAdapter->AdapterName) + 1);
1312
1313 ZeroMemory(&PnpEvent, sizeof(PnpEvent));
1314 PnpEvent.Unknown5 = 1;
1315
1317 1,
1318 szUnicodeAdapterName,
1319 &PnpEvent,
1320 0);
1321 if (ret != ERROR_SUCCESS)
1322 {
1323 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1325 goto done;
1326 }
1327
1328 ConResPrintf(StdOut, IDS_DHCPSETIDSUCCESS, szFriendlyName);
1329 }
1330 else
1331 {
1333 }
1334
1335done:
1336 if (pAdapterInfo)
1337 HeapFree(ProcessHeap, 0, pAdapterInfo);
1338}
#define IDS_DHCPSETIDSUCCESS
Definition: resource.h:82
#define IDS_DHCPSETIDERROR
Definition: resource.h:81
DWORD APIENTRY DhcpHandlePnPEvent(_In_ DWORD Unknown1, _In_ DWORD Unknown2, _In_ PWSTR AdapterName, _In_ PDHCP_PNP_EVENT PnpEvent, _In_ DWORD Unknown5)
Definition: dhcpcsvc.c:319
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
#define REG_SZ
Definition: layer.c:22
#define ZeroMemory
Definition: minwinbase.h:31
#define KEY_WRITE
Definition: nt_native.h:1034
DWORD Unknown5
Definition: dhcpcapi.h:14

Referenced by wmain().

◆ ShowClassId()

VOID ShowClassId ( PWSTR  pszAdapterName)

Definition at line 1210 of file ipconfig.c.

1212{
1213 printf("\nSorry /showclassid adapter is not implemented yet\n");
1214}

Referenced by wmain().

◆ ShowInfo()

VOID ShowInfo ( BOOL  bShowHeader,
BOOL  bAll 
)

Definition at line 539 of file ipconfig.c.

542{
543 MIB_IFROW mibEntry;
544 PIP_ADAPTER_INFO pAdapterInfo = NULL;
545 PIP_ADAPTER_INFO pAdapter = NULL;
546 ULONG adaptOutBufLen = 0;
547 PFIXED_INFO pFixedInfo = NULL;
548 ULONG netOutBufLen = 0;
549 PIP_PER_ADAPTER_INFO pPerAdapterInfo = NULL;
550 ULONG ulPerAdapterInfoLength = 0;
551 PSTR pszDomainName = NULL;
552 DWORD dwDomainNameSize = 0;
553 ULONG ret = 0;
554
555 GetComputerNameExA(ComputerNameDnsDomain,
556 NULL,
557 &dwDomainNameSize);
558 if (dwDomainNameSize > 0)
559 {
560 pszDomainName = HeapAlloc(ProcessHeap,
561 0,
562 dwDomainNameSize * sizeof(CHAR));
563 if (pszDomainName != NULL)
564 GetComputerNameExA(ComputerNameDnsDomain,
565 pszDomainName,
566 &dwDomainNameSize);
567 }
568
569 /* call GetAdaptersInfo to obtain the adapter info */
570 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
572 {
573 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
574 if (pAdapterInfo == NULL)
575 goto done;
576
577 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
578 if (ret != NO_ERROR)
579 {
581 goto done;
582 }
583 }
584 else
585 {
586 if (ret != ERROR_NO_DATA)
587 {
589 goto done;
590 }
591 }
592
593 /* call GetNetworkParams to obtain the network info */
594 if (GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
595 {
596 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
597 if (pFixedInfo == NULL)
598 {
599 goto done;
600 }
601 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
602 {
604 goto done;
605 }
606 }
607 else
608 {
610 goto done;
611 }
612
613 pAdapter = pAdapterInfo;
614
615 if (bShowHeader)
617
618 if (bAll)
619 {
621 ConResPrintf(StdOut, IDS_PRIMARYDNSSUFFIX, (pszDomainName != NULL) ? pszDomainName : "");
622
623 PrintNodeType(pFixedInfo->NodeType);
624
625 if (pFixedInfo->EnableRouting)
627 else
629
630 if (pAdapter && pAdapter->HaveWins)
632 else
634
635 if (pszDomainName != NULL && pszDomainName[0] != 0)
636 {
637 ConResPrintf(StdOut, IDS_DNSSUFFIXLIST, pszDomainName);
639 }
640 else
641 {
643 }
644 }
645
646 while (pAdapter)
647 {
649
650 mibEntry.dwIndex = pAdapter->Index;
651 GetIfEntry(&mibEntry);
652
653 PrintAdapterTypeAndName(pAdapter);
654
655 if (GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength) == ERROR_BUFFER_OVERFLOW)
656 {
657 pPerAdapterInfo = (PIP_PER_ADAPTER_INFO)HeapAlloc(ProcessHeap, 0, ulPerAdapterInfoLength);
658 if (pPerAdapterInfo != NULL)
659 {
660 GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength);
661 }
662 }
663
664 /* check if the adapter is connected to the media */
666 {
669 }
670 else
671 {
673 }
674
675 if (bAll)
676 {
679 printf("\n");
680
682
683 if (bConnected)
684 {
685 if (pAdapter->DhcpEnabled)
686 {
688
689 if (pPerAdapterInfo != NULL)
690 {
691 if (pPerAdapterInfo->AutoconfigEnabled)
693 else
695 }
696 }
697 else
698 {
700 }
701 }
702 }
703
704 if (!bConnected)
705 {
706 pAdapter = pAdapter->Next;
707 continue;
708 }
709
712
713 if (strcmp(pAdapter->GatewayList.IpAddress.String, "0.0.0.0"))
715 else
717
718 if (bAll)
719 {
720 PIP_ADDR_STRING pIPAddr;
721
722 if (pAdapter->DhcpEnabled)
724
726 pIPAddr = pFixedInfo->DnsServerList.Next;
727 while (pIPAddr)
728 {
730 pIPAddr = pIPAddr->Next;
731 }
732
733 if (pAdapter->HaveWins)
734 {
737 }
738
739 if (pAdapter->DhcpEnabled && strcmp(pAdapter->DhcpServer.IpAddress.String, "255.255.255.255"))
740 {
741 PWSTR DateTimeString;
742 DateTimeString = timeToStr(pAdapter->LeaseObtained);
743 ConResPrintf(StdOut, IDS_LEASEOBTAINED, DateTimeString ? DateTimeString : L"N/A");
744 if (DateTimeString)
745 {
746 HeapFree(ProcessHeap, 0, DateTimeString);
747 }
748 DateTimeString = timeToStr(pAdapter->LeaseExpires);
749 ConResPrintf(StdOut, IDS_LEASEEXPIRES, DateTimeString ? DateTimeString : L"N/A");
750 if (DateTimeString)
751 {
752 HeapFree(ProcessHeap, 0, DateTimeString);
753 }
754 }
755 }
756
757 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
758 pPerAdapterInfo = NULL;
759
760 pAdapter = pAdapter->Next;
761 }
762
763done:
764 if (pszDomainName)
765 HeapFree(ProcessHeap, 0, pszDomainName);
766 if (pFixedInfo)
767 HeapFree(ProcessHeap, 0, pFixedInfo);
768 if (pAdapterInfo)
769 HeapFree(ProcessHeap, 0, pAdapterInfo);
770}
unsigned char BOOLEAN
Definition: actypes.h:127
#define IDS_DESCRIPTION
Definition: resource.h:4
#define IDS_IPROUTINGNO
Definition: resource.h:11
#define IDS_DEFAULTGATEWAY
Definition: resource.h:28
#define IDS_CONNECTIONDNSSUFFIX
Definition: resource.h:19
#define IDS_WINSPROXYYES
Definition: resource.h:14
#define IDS_IPADDRESS
Definition: resource.h:26
#define IDS_DNSSERVERS
Definition: resource.h:30
#define IDS_HOSTNAME
Definition: resource.h:4
#define IDS_SUBNETMASK
Definition: resource.h:27
#define IDS_WINSPROXYNO
Definition: resource.h:13
#define IDS_LEASEEXPIRES
Definition: resource.h:34
#define IDS_PRIMARYWINSSERVER
Definition: resource.h:31
#define IDS_DNSSUFFIXLIST
Definition: resource.h:15
#define IDS_DHCPNO
Definition: resource.h:22
#define IDS_LEASEOBTAINED
Definition: resource.h:33
#define IDS_SECONDARYWINSSERVER
Definition: resource.h:32
#define IDS_AUTOCONFIGNO
Definition: resource.h:24
#define IDS_PHYSICALADDRESS
Definition: resource.h:21
#define IDS_AUTOCONFIGYES
Definition: resource.h:25
#define IDS_MEDIADISCONNECTED
Definition: resource.h:18
#define IDS_DHCPSERVER
Definition: resource.h:29
#define IDS_DHCPYES
Definition: resource.h:23
#define IDS_IPROUTINGYES
Definition: resource.h:12
#define IDS_PRIMARYDNSSUFFIX
Definition: resource.h:5
#define IDS_EMPTYLINE
Definition: resource.h:16
BOOL bConnected
Definition: fdebug.c:27
PCSTR PrintMacAddr(PBYTE Mac)
Definition: ipconfig.c:124
_Ret_opt_z_ PWSTR timeToStr(_In_ time_t TimeStamp)
Definition: ipconfig.c:135
static VOID PrintAdapterDescription(PSTR lpClass)
Definition: ipconfig.c:315
static VOID PrintNodeType(_In_ UINT NodeType)
Definition: ipconfig.c:462
static VOID PrintAdapterTypeAndName(PIP_ADAPTER_INFO pAdapterInfo)
Definition: ipconfig.c:491
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT, LPSTR, LPDWORD)
Definition: compname.c:376
IP_PER_ADAPTER_INFO_W2KSP1 * PIP_PER_ADAPTER_INFO
Definition: iptypes.h:70
char DomainName[MAX_DOMAIN_NAME_LEN+4]
Definition: iptypes.h:75
char HostName[MAX_HOSTNAME_LEN+4]
Definition: iptypes.h:74
IP_ADDR_STRING DnsServerList
Definition: iptypes.h:77
UINT EnableRouting
Definition: iptypes.h:80
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]
Definition: iptypes.h:47
IP_ADDR_STRING SecondaryWinsServer
Definition: iptypes.h:57
IP_ADDR_STRING DhcpServer
Definition: iptypes.h:54
time_t LeaseObtained
Definition: iptypes.h:58
IP_ADDR_STRING GatewayList
Definition: iptypes.h:53
time_t LeaseExpires
Definition: iptypes.h:59
IP_ADDR_STRING PrimaryWinsServer
Definition: iptypes.h:56
struct _IP_ADDR_STRING * Next
Definition: iptypes.h:35
IP_MASK_STRING IpMask
Definition: iptypes.h:37
#define ERROR_NO_DATA
Definition: winerror.h:406

Referenced by Release(), Renew(), and wmain().

◆ timeToStr()

_Ret_opt_z_ PWSTR timeToStr ( _In_ time_t  TimeStamp)

Definition at line 135 of file ipconfig.c.

136{
137 struct tm* ptm;
138 SYSTEMTIME SystemTime;
139 INT DateCchSize, TimeCchSize, TotalCchSize, i;
140 PWSTR DateTimeString, psz;
141
142 /* Convert Unix time to SYSTEMTIME */
143 /* localtime_s may be preferred if available */
144 ptm = localtime(&TimeStamp);
145 if (!ptm)
146 {
147 return NULL;
148 }
149 SystemTime.wYear = ptm->tm_year + 1900;
150 SystemTime.wMonth = ptm->tm_mon + 1;
151 SystemTime.wDay = ptm->tm_mday;
152 SystemTime.wHour = ptm->tm_hour;
153 SystemTime.wMinute = ptm->tm_min;
154 SystemTime.wSecond = ptm->tm_sec;
155
156 /* Get total size in characters required of buffer */
157 DateCchSize = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &SystemTime, NULL, NULL, 0);
158 if (!DateCchSize)
159 {
160 return NULL;
161 }
162 TimeCchSize = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &SystemTime, NULL, NULL, 0);
163 if (!TimeCchSize)
164 {
165 return NULL;
166 }
167 /* Two terminating null are included, the first one will be replaced by space */
168 TotalCchSize = DateCchSize + TimeCchSize;
169
170 /* Allocate buffer and format datetime string */
171 DateTimeString = (PWSTR)HeapAlloc(ProcessHeap, 0, TotalCchSize * sizeof(WCHAR));
172 if (!DateTimeString)
173 {
174 return NULL;
175 }
176
177 /* Get date string */
178 i = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &SystemTime, NULL, DateTimeString, TotalCchSize);
179 if (i)
180 {
181 /* Append space and move pointer */
182 DateTimeString[i - 1] = L' ';
183 psz = DateTimeString + i;
184 TotalCchSize -= i;
185
186 /* Get time string */
187 if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &SystemTime, NULL, psz, TotalCchSize))
188 {
189 return DateTimeString;
190 }
191 }
192
193 HeapFree(ProcessHeap, 0, DateTimeString);
194 return NULL;
195}
static struct tm * localtime(const time_t *t)
Definition: time.h:121
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1101
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:1001
#define LOCALE_USER_DEFAULT
WORD wSecond
Definition: minwinbase.h:262
WORD wMinute
Definition: minwinbase.h:261
int tm_mon
Definition: corecrt_wtime.h:16
int tm_year
Definition: corecrt_wtime.h:17
int tm_hour
Definition: corecrt_wtime.h:14
int tm_sec
Definition: corecrt_wtime.h:12
int tm_mday
Definition: corecrt_wtime.h:15
int tm_min
Definition: corecrt_wtime.h:13
#define DATE_LONGDATE
Definition: winnls.h:210

Referenced by ShowInfo().

◆ Usage()

VOID Usage ( _In_ BOOL  Error)

Definition at line 1341 of file ipconfig.c.

1343{
1344 if (Error)
1347}
#define IDS_USAGE
Definition: resource.h:3
#define IDS_CMDLINEERROR
Definition: resource.h:69
BOOL Error
Definition: chkdsk.c:66

◆ wmain()

int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 1349 of file ipconfig.c.

1350{
1351 BOOL DoUsage=FALSE;
1352 BOOL DoAll=FALSE;
1353 BOOL DoRelease=FALSE;
1354 BOOL DoRenew=FALSE;
1355 BOOL DoFlushdns=FALSE;
1356 BOOL DoRegisterdns=FALSE;
1357 BOOL DoDisplaydns=FALSE;
1358 BOOL DoShowclassid=FALSE;
1359 BOOL DoSetclassid=FALSE;
1360
1361 /* Initialize the Console Standard Streams */
1363
1366
1367 /* Parse command line for options we have been given. */
1368 if ((argc > 1) && (argv[1][0] == L'/' || argv[1][0] == L'-'))
1369 {
1370 if (!_wcsicmp(&argv[1][1], L"?"))
1371 {
1372 DoUsage = TRUE;
1373 }
1374 else if (!_wcsnicmp(&argv[1][1], L"ALL", wcslen(&argv[1][1])))
1375 {
1376 DoAll = TRUE;
1377 }
1378 else if (!_wcsnicmp(&argv[1][1], L"RELEASE", wcslen(&argv[1][1])))
1379 {
1380 DoRelease = TRUE;
1381 }
1382 else if (!_wcsnicmp(&argv[1][1], L"RENEW", wcslen(&argv[1][1])))
1383 {
1384 DoRenew = TRUE;
1385 }
1386 else if (!_wcsnicmp(&argv[1][1], L"FLUSHDNS", wcslen(&argv[1][1])))
1387 {
1388 DoFlushdns = TRUE;
1389 }
1390 else if (!_wcsnicmp(&argv[1][1], L"FLUSHREGISTERDNS", wcslen(&argv[1][1])))
1391 {
1392 DoRegisterdns = TRUE;
1393 }
1394 else if (!_wcsnicmp(&argv[1][1], L"DISPLAYDNS", wcslen(&argv[1][1])))
1395 {
1396 DoDisplaydns = TRUE;
1397 }
1398 else if (!_wcsnicmp(&argv[1][1], L"SHOWCLASSID", wcslen(&argv[1][1])))
1399 {
1400 DoShowclassid = TRUE;
1401 }
1402 else if (!_wcsnicmp(&argv[1][1], L"SETCLASSID", wcslen(&argv[1][1])))
1403 {
1404 DoSetclassid = TRUE;
1405 }
1406 }
1407
1408 switch (argc)
1409 {
1410 case 1: /* Default behaviour if no options are given*/
1412 break;
1413 case 2: /* Process all the options that take no parameters */
1414 if (DoUsage)
1415 Usage(FALSE);
1416 else if (DoAll)
1417 ShowInfo(TRUE, TRUE);
1418 else if (DoRelease)
1419 Release(NULL);
1420 else if (DoRenew)
1421 Renew(NULL);
1422 else if (DoFlushdns)
1423 FlushDns();
1424 else if (DoRegisterdns)
1425 RegisterDns();
1426 else if (DoDisplaydns)
1427 DisplayDns();
1428 else
1429 Usage(TRUE);
1430 break;
1431 case 3: /* Process all the options that can have 1 parameter */
1432 if (DoRelease)
1433 Release(argv[2]);
1434 else if (DoRenew)
1435 Renew(argv[2]);
1436 else if (DoShowclassid)
1437 ShowClassId(argv[2]);
1438 else if (DoSetclassid)
1439 SetClassId(argv[2], NULL);
1440 else
1441 Usage(TRUE);
1442 break;
1443 case 4: /* Process all the options that can have 2 parameters */
1444 if (DoSetclassid)
1445 SetClassId(argv[2], argv[3]);
1446 else
1447 Usage(TRUE);
1448 break;
1449 default:
1450 Usage(TRUE);
1451 }
1452
1453 return 0;
1454}
_In_ BOOLEAN Release
Definition: cdrom.h:920
#define ConInitStdStreams()
Definition: conutils_noros.h:5
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:195
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
VOID RegisterDns(VOID)
Definition: ipconfig.c:1039
VOID FlushDns(VOID)
Definition: ipconfig.c:1023
VOID Renew(PWSTR pszAdapterName)
Definition: ipconfig.c:925
VOID ShowClassId(PWSTR pszAdapterName)
Definition: ipconfig.c:1210
HINSTANCE hInstance
Definition: ipconfig.c:41
VOID SetClassId(PWSTR pszAdapterName, PWSTR pszClassId)
Definition: ipconfig.c:1217
VOID DisplayDns(VOID)
Definition: ipconfig.c:1175
#define argv
Definition: mplay32.c:18
#define GetModuleHandle
Definition: winbase.h:3576

Variable Documentation

◆ hInstance

HINSTANCE hInstance

Definition at line 41 of file ipconfig.c.

Referenced by wmain().

◆ ProcessHeap

HANDLE ProcessHeap
  • Internal Headers *‍/

Definition at line 42 of file ipconfig.c.

Referenced by PrintAdapterDescription(), Release(), Renew(), SetClassId(), ShowInfo(), timeToStr(), and wmain().

◆ TypeArray

RECORDTYPE TypeArray[]

Definition at line 44 of file ipconfig.c.

Referenced by GetRecordTypeName().