ReactOS 0.4.17-dev-573-g8315b8c
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 1177 of file ipconfig.c.

1178{
1179 PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
1180
1182
1183 if (!DnsGetCacheDataTable(&DnsEntry))
1184 {
1186 return;
1187 }
1188
1189 if (DnsEntry == NULL)
1190 return;
1191
1192 pThisEntry = DnsEntry;
1193 while (pThisEntry != NULL)
1194 {
1195 pNextEntry = pThisEntry->pNext;
1196
1197 if (pThisEntry->wType1 != DNS_TYPE_ZERO)
1198 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
1199
1200 if (pThisEntry->wType2 != DNS_TYPE_ZERO)
1201 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
1202
1203 if (pThisEntry->pszName)
1204 LocalFree(pThisEntry->pszName);
1205 LocalFree(pThisEntry);
1206
1207 pThisEntry = pNextEntry;
1208 }
1209}
#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:1049
#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 1049 of file ipconfig.c.

1052{
1053 PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
1054 WCHAR szBuffer[48];
1055 IN_ADDR Addr4;
1056 IN6_ADDR Addr6;
1058
1059 ConResPrintf(StdOut, IDS_DNSNAME, pszName);
1061
1062 pQueryResults = NULL;
1063 Status = DnsQuery_W(pszName,
1064 wType,
1066 NULL,
1067 (PDNS_RECORD *)&pQueryResults,
1068 NULL);
1069 if (Status != ERROR_SUCCESS)
1070 {
1072 {
1074 }
1075 else if (Status == DNS_INFO_NO_RECORDS)
1076 {
1078 }
1079 return;
1080 }
1081
1082 pThisRecord = pQueryResults;
1083 while (pThisRecord != NULL)
1084 {
1085 pNextRecord = pThisRecord->pNext;
1086
1087 ConResPrintf(StdOut, IDS_DNSRECORDNAME, pThisRecord->pName);
1088 ConResPrintf(StdOut, IDS_DNSRECORDTYPE, pThisRecord->wType);
1089 ConResPrintf(StdOut, IDS_DNSRECORDTTL, pThisRecord->dwTtl);
1090 ConResPrintf(StdOut, IDS_DNSRECORDLENGTH, pThisRecord->wDataLength);
1091
1092 switch (pThisRecord->Flags.S.Section)
1093 {
1094 case DnsSectionQuestion:
1096 break;
1097
1098 case DnsSectionAnswer:
1100 break;
1101
1104 break;
1105
1108 break;
1109 }
1110
1111 switch (pThisRecord->wType)
1112 {
1113 case DNS_TYPE_A:
1114 Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
1115 RtlIpv4AddressToStringW(&Addr4, szBuffer);
1116 ConResPrintf(StdOut, IDS_DNSTYPEA, szBuffer);
1117 break;
1118
1119 case DNS_TYPE_NS:
1120 ConResPrintf(StdOut, IDS_DNSTYPENS, pThisRecord->Data.NS.pNameHost);
1121 break;
1122
1123 case DNS_TYPE_CNAME:
1124 ConResPrintf(StdOut, IDS_DNSTYPECNAME, pThisRecord->Data.CNAME.pNameHost);
1125 break;
1126
1127 case DNS_TYPE_SOA:
1129 pThisRecord->Data.SOA.pNamePrimaryServer,
1130 pThisRecord->Data.SOA.pNameAdministrator,
1131 pThisRecord->Data.SOA.dwSerialNo);
1133 pThisRecord->Data.SOA.dwRefresh,
1134 pThisRecord->Data.SOA.dwRetry,
1135 pThisRecord->Data.SOA.dwExpire,
1136 pThisRecord->Data.SOA.dwDefaultTtl);
1137 break;
1138
1139 case DNS_TYPE_PTR:
1140 ConResPrintf(StdOut, IDS_DNSTYPEPTR, pThisRecord->Data.PTR.pNameHost);
1141 break;
1142
1143 case DNS_TYPE_MX:
1145 pThisRecord->Data.MX.pNameExchange,
1146 pThisRecord->Data.MX.wPreference,
1147 pThisRecord->Data.MX.Pad);
1148 break;
1149
1150 case DNS_TYPE_AAAA:
1151 RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address, sizeof(Addr6));
1152 RtlIpv6AddressToStringW(&Addr6, szBuffer);
1154 break;
1155
1156 case DNS_TYPE_ATMA:
1158 break;
1159
1160 case DNS_TYPE_SRV:
1162 pThisRecord->Data.SRV.pNameTarget,
1163 pThisRecord->Data.SRV.wPriority,
1164 pThisRecord->Data.SRV.wWeight,
1165 pThisRecord->Data.SRV.wPort);
1166 break;
1167 }
1168 ConPuts(StdOut, L"\n\n");
1169
1170 pThisRecord = pNextRecord;
1171 }
1172
1174}
#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:24
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)
short WCHAR
Definition: pedump.c:58
#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::@1129 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

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 1025 of file ipconfig.c.

1026{
1028
1030 {
1032 }
1033 else
1034 {
1037 }
1038}
#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:1597
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
char CHAR
Definition: pedump.c:57
#define _countof(array)
Definition: sndvol32.h:70
const char * PCSTR
Definition: typedefs.h:52
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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:2988
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
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 776 of file ipconfig.c.

779{
780 WCHAR *pCharE, *pCharN, charE, charN;
781
782 if (pszExpression == NULL)
783 return TRUE;
784
785 if (pszName == NULL)
786 return FALSE;
787
788 pCharE = pszExpression;
789 pCharN = pszName;
790 while (*pCharE != UNICODE_NULL)
791 {
792 charE = towlower(*pCharE);
793 charN = towlower(*pCharN);
794
795 if (charE == L'*')
796 {
797 if (*(pCharE + 1) != charN)
798 pCharN++;
799 else
800 pCharE++;
801 }
802 else if (charE == L'?')
803 {
804 pCharE++;
805 pCharN++;
806 }
807 else if (charE == charN)
808 {
809 pCharE++;
810 pCharN++;
811 }
812 else
813 {
814 return FALSE;
815 }
816 }
817
818 return TRUE;
819}
#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:3324
#define printf
Definition: freeldr.h:103
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 1041 of file ipconfig.c.

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

Referenced by wmain().

◆ Release()

VOID Release ( PWSTR  pszAdapterName)

Definition at line 822 of file ipconfig.c.

824{
825 PIP_ADAPTER_INFO pAdapterInfo = NULL;
826 PIP_ADAPTER_INFO pAdapter = NULL;
827 ULONG adaptOutBufLen = 0;
828 ULONG ret = 0;
829 WCHAR szFriendlyName[MAX_PATH];
830 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
831 MIB_IFROW mibEntry;
834
836
837 /* call GetAdaptersInfo to obtain the adapter info */
838 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
840 {
842 return;
843 }
844
845 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
846 if (pAdapterInfo == NULL)
847 {
849 return;
850 }
851
852 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
853 if (ret != NO_ERROR)
854 {
856 goto done;
857 }
858
860
861 pAdapter = pAdapterInfo;
862
863 while (pAdapter)
864 {
865 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
866
867 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
868 {
870
871 mibEntry.dwIndex = pAdapter->Index;
872 GetIfEntry(&mibEntry);
873
876 {
877 if (pAdapter->DhcpEnabled)
878 {
879 if (strcmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0"))
880 {
881 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
882
883 /* Call DhcpReleaseParameters to release the IP address on the specified adapter. */
884 ret = DhcpReleaseParameters(szUnicodeAdapterName);
885 if (ret != NO_ERROR)
886 {
887 ConResPrintf(StdOut, IDS_DHCPRELEASEERROR, szFriendlyName);
889 }
890 }
891 else
892 {
894 }
895 }
896 else
897 {
898 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
899 }
900 }
901 else
902 {
903 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
904 }
905 }
906
907 pAdapter = pAdapter->Next;
908 }
909
911
912 if (bFoundAdapter == FALSE)
913 {
915 }
916 else
917 {
919 }
920
921done:
922 if (pAdapterInfo)
923 HeapFree(ProcessHeap, 0, pAdapterInfo);
924}
#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:611
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:776
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
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 927 of file ipconfig.c.

929{
930 PIP_ADAPTER_INFO pAdapterInfo = NULL;
931 PIP_ADAPTER_INFO pAdapter = NULL;
932 ULONG adaptOutBufLen = 0;
933 ULONG ret = 0;
934 WCHAR szFriendlyName[MAX_PATH];
935 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
936 MIB_IFROW mibEntry;
939
941
942 /* call GetAdaptersInfo to obtain the adapter info */
943 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
945 {
947 return;
948 }
949
950 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
951 if (pAdapterInfo == NULL)
952 {
954 return;
955 }
956
957 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
958 if (ret != NO_ERROR)
959 {
961 goto done;
962 }
963
965
966 pAdapter = pAdapterInfo;
967
968 while (pAdapter)
969 {
970 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
971
972 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
973 {
975
976 mibEntry.dwIndex = pAdapter->Index;
977 GetIfEntry(&mibEntry);
978
981 {
982 if (pAdapter->DhcpEnabled)
983 {
984 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
985
986 /* Call DhcpAcquireParameters to renew the IP address on the specified adapter. */
987 ret = DhcpAcquireParameters(szUnicodeAdapterName);
988 if (ret != NO_ERROR)
989 {
990 ConResPrintf(StdOut, IDS_DHCPRENEWERROR, szFriendlyName);
992 }
993 }
994 else
995 {
996 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
997 }
998 }
999 else
1000 {
1001 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
1002 }
1003 }
1004
1005 pAdapter = pAdapter->Next;
1006 }
1007
1009
1010 if (bFoundAdapter == FALSE)
1011 {
1013 }
1014 else
1015 {
1017 }
1018
1019done:
1020 if (pAdapterInfo)
1021 HeapFree(ProcessHeap, 0, pAdapterInfo);
1022}
#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 1219 of file ipconfig.c.

1222{
1223 PIP_ADAPTER_INFO pAdapterInfo = NULL;
1224 PIP_ADAPTER_INFO pAdapter = NULL, pFoundAdapter = NULL;
1225 ULONG adaptOutBufLen = 0;
1226 ULONG ret = 0;
1227 WCHAR szFriendlyName[MAX_PATH];
1228 WCHAR szKeyName[256];
1229 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
1230 MIB_IFROW mibEntry;
1231 HKEY hKey;
1232 DHCP_PNP_EVENT PnpEvent;
1233
1235
1236 /* call GetAdaptersInfo to obtain the adapter info */
1237 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1239 {
1241 return;
1242 }
1243
1244 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
1245 if (pAdapterInfo == NULL)
1246 {
1248 return;
1249 }
1250
1251 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1252 if (ret != NO_ERROR)
1253 {
1254 DoFormatMessage(0);
1255 goto done;
1256 }
1257
1258 pAdapter = pAdapterInfo;
1259 while (pAdapter)
1260 {
1261 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
1262
1263 if (MatchWildcard(pszAdapterName, szFriendlyName))
1264 {
1265 mibEntry.dwIndex = pAdapter->Index;
1266 GetIfEntry(&mibEntry);
1267
1270 {
1271 pFoundAdapter = pAdapter;
1272 break;
1273 }
1274 }
1275
1276 pAdapter = pAdapter->Next;
1277 }
1278
1279 if (pFoundAdapter)
1280 {
1281 _swprintf(szKeyName,
1282 L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%S",
1283 pFoundAdapter->AdapterName);
1284
1286 szKeyName,
1287 0,
1288 KEY_WRITE,
1289 &hKey);
1290 if (ret != ERROR_SUCCESS)
1291 {
1292 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1294 goto done;
1295 }
1296
1297 if (pszClassId == NULL)
1298 pszClassId = L"";
1299
1301 L"DhcpClassId",
1302 0, REG_SZ,
1303 (PBYTE)pszClassId,
1304 (DWORD)((wcslen(pszClassId) + 1) * sizeof(WCHAR)));
1306 if (ret != ERROR_SUCCESS)
1307 {
1308 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1310 goto done;
1311 }
1312
1313 mbstowcs(szUnicodeAdapterName, pFoundAdapter->AdapterName, strlen(pFoundAdapter->AdapterName) + 1);
1314
1315 ZeroMemory(&PnpEvent, sizeof(PnpEvent));
1316 PnpEvent.Unknown5 = 1;
1317
1319 1,
1320 szUnicodeAdapterName,
1321 &PnpEvent,
1322 0);
1323 if (ret != ERROR_SUCCESS)
1324 {
1325 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1327 goto done;
1328 }
1329
1330 ConResPrintf(StdOut, IDS_DHCPSETIDSUCCESS, szFriendlyName);
1331 }
1332 else
1333 {
1335 }
1336
1337done:
1338 if (pAdapterInfo)
1339 HeapFree(ProcessHeap, 0, pAdapterInfo);
1340}
#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:394
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 1212 of file ipconfig.c.

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

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 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
707 pPerAdapterInfo = NULL;
708 pAdapter = pAdapter->Next;
709 continue;
710 }
711
714
715 if (strcmp(pAdapter->GatewayList.IpAddress.String, "0.0.0.0"))
717 else
719
720 if (bAll)
721 {
722 PIP_ADDR_STRING pIPAddr;
723
724 if (pAdapter->DhcpEnabled)
726
728 pIPAddr = pFixedInfo->DnsServerList.Next;
729 while (pIPAddr)
730 {
732 pIPAddr = pIPAddr->Next;
733 }
734
735 if (pAdapter->HaveWins)
736 {
739 }
740
741 if (pAdapter->DhcpEnabled && strcmp(pAdapter->DhcpServer.IpAddress.String, "255.255.255.255"))
742 {
743 PWSTR DateTimeString;
744 DateTimeString = timeToStr(pAdapter->LeaseObtained);
745 ConResPrintf(StdOut, IDS_LEASEOBTAINED, DateTimeString ? DateTimeString : L"N/A");
746 if (DateTimeString)
747 {
748 HeapFree(ProcessHeap, 0, DateTimeString);
749 }
750 DateTimeString = timeToStr(pAdapter->LeaseExpires);
751 ConResPrintf(StdOut, IDS_LEASEEXPIRES, DateTimeString ? DateTimeString : L"N/A");
752 if (DateTimeString)
753 {
754 HeapFree(ProcessHeap, 0, DateTimeString);
755 }
756 }
757 }
758
759 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
760 pPerAdapterInfo = NULL;
761
762 pAdapter = pAdapter->Next;
763 }
764
765done:
766 if (pszDomainName)
767 HeapFree(ProcessHeap, 0, pszDomainName);
768 if (pFixedInfo)
769 HeapFree(ProcessHeap, 0, pFixedInfo);
770 if (pAdapterInfo)
771 HeapFree(ProcessHeap, 0, pAdapterInfo);
772}
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:217

Referenced by ShowInfo().

◆ Usage()

VOID Usage ( _In_ BOOL  Error)

Definition at line 1343 of file ipconfig.c.

1345{
1346 if (Error)
1349}
#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 1351 of file ipconfig.c.

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

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().