ReactOS 0.4.16-dev-1946-g52006dd
ipconfig.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winuser.h>
#include <winreg.h>
#include <stdio.h>
#include <time.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 <debug.h>
Include dependency graph for ipconfig.c:

Go to the source code of this file.

Classes

struct  _RECORDTYPE
 

Macros

#define WIN32_NO_STATUS
 
#define NDEBUG
 
#define GUID_LEN   40
 

Typedefs

typedef struct _RECORDTYPE RECORDTYPE
 
typedef struct _RECORDTYPEPRECORDTYPE
 

Functions

LPWSTR GetRecordTypeName (WORD wType)
 
PCHAR PrintMacAddr (PBYTE Mac)
 
_Ret_opt_z_ PWSTR timeToStr (_In_ time_t TimeStamp)
 
VOID DoFormatMessage (_In_ LONG ErrorCode)
 
LPWSTR GetUnicodeAdapterName (_In_ LPSTR pszAnsiName)
 
VOID GetAdapterFriendlyName (_In_ LPSTR lpClass, _In_ DWORD cchFriendlyNameLength, _Out_ LPWSTR pszFriendlyName)
 
VOID GetInterfaceFriendlyName (_In_ LPWSTR lpDeviceName, _In_ DWORD cchFriendlyNameLength, _Out_ LPWSTR pszFriendlyName)
 
static VOID PrintAdapterDescription (LPSTR 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 (LPWSTR pszAdapterName)
 
VOID Renew (LPWSTR pszAdapterName)
 
VOID FlushDns (VOID)
 
VOID RegisterDns (VOID)
 
static VOID DisplayDnsRecord (PWSTR pszName, WORD wType)
 
VOID DisplayDns (VOID)
 
VOID ShowClassId (LPWSTR pszAdapterName)
 
VOID SetClassId (LPWSTR pszAdapterName, LPWSTR 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 44 of file ipconfig.c.

◆ NDEBUG

#define NDEBUG

Definition at line 35 of file ipconfig.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 12 of file ipconfig.c.

Typedef Documentation

◆ PRECORDTYPE

◆ RECORDTYPE

Function Documentation

◆ DisplayDns()

VOID DisplayDns ( VOID  )

Definition at line 1195 of file ipconfig.c.

1196{
1197 PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
1198
1200
1201 if (!DnsGetCacheDataTable(&DnsEntry))
1202 {
1204 return;
1205 }
1206
1207 if (DnsEntry == NULL)
1208 return;
1209
1210 pThisEntry = DnsEntry;
1211 while (pThisEntry != NULL)
1212 {
1213 pNextEntry = pThisEntry->pNext;
1214
1215 if (pThisEntry->wType1 != DNS_TYPE_ZERO)
1216 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
1217
1218 if (pThisEntry->wType2 != DNS_TYPE_ZERO)
1219 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
1220
1221 if (pThisEntry->pszName)
1222 LocalFree(pThisEntry->pszName);
1223 LocalFree(pThisEntry);
1224
1225 pThisEntry = pNextEntry;
1226 }
1227}
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define IDS_HEADER
Definition: resource.h:3
#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:205
static VOID DisplayDnsRecord(PWSTR pszName, WORD wType)
Definition: ipconfig.c:1067
#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 1067 of file ipconfig.c.

1070{
1071 PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
1072 WCHAR szBuffer[48];
1073 IN_ADDR Addr4;
1074 IN6_ADDR Addr6;
1076
1077 ConResPrintf(StdOut, IDS_DNSNAME, pszName);
1079
1080 pQueryResults = NULL;
1081 Status = DnsQuery_W(pszName,
1082 wType,
1084 NULL,
1085 (PDNS_RECORD *)&pQueryResults,
1086 NULL);
1087 if (Status != ERROR_SUCCESS)
1088 {
1090 {
1092 }
1093 else if (Status == DNS_INFO_NO_RECORDS)
1094 {
1096 }
1097 return;
1098 }
1099
1100 pThisRecord = pQueryResults;
1101 while (pThisRecord != NULL)
1102 {
1103 pNextRecord = pThisRecord->pNext;
1104
1105 ConResPrintf(StdOut, IDS_DNSRECORDNAME, pThisRecord->pName);
1106 ConResPrintf(StdOut, IDS_DNSRECORDTYPE, pThisRecord->wType);
1107 ConResPrintf(StdOut, IDS_DNSRECORDTTL, pThisRecord->dwTtl);
1108 ConResPrintf(StdOut, IDS_DNSRECORDLENGTH, pThisRecord->wDataLength);
1109
1110 switch (pThisRecord->Flags.S.Section)
1111 {
1112 case DnsSectionQuestion:
1114 break;
1115
1116 case DnsSectionAnswer:
1118 break;
1119
1122 break;
1123
1126 break;
1127 }
1128
1129 switch (pThisRecord->wType)
1130 {
1131 case DNS_TYPE_A:
1132 Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
1133 RtlIpv4AddressToStringW(&Addr4, szBuffer);
1134 ConResPrintf(StdOut, IDS_DNSTYPEA, szBuffer);
1135 break;
1136
1137 case DNS_TYPE_NS:
1138 ConResPrintf(StdOut, IDS_DNSTYPENS, pThisRecord->Data.NS.pNameHost);
1139 break;
1140
1141 case DNS_TYPE_CNAME:
1142 ConResPrintf(StdOut, IDS_DNSTYPECNAME, pThisRecord->Data.CNAME.pNameHost);
1143 break;
1144
1145 case DNS_TYPE_SOA:
1147 pThisRecord->Data.SOA.pNamePrimaryServer,
1148 pThisRecord->Data.SOA.pNameAdministrator,
1149 pThisRecord->Data.SOA.dwSerialNo);
1151 pThisRecord->Data.SOA.dwRefresh,
1152 pThisRecord->Data.SOA.dwRetry,
1153 pThisRecord->Data.SOA.dwExpire,
1154 pThisRecord->Data.SOA.dwDefaultTtl);
1155 break;
1156
1157 case DNS_TYPE_PTR:
1158 ConResPrintf(StdOut, IDS_DNSTYPEPTR, pThisRecord->Data.PTR.pNameHost);
1159 break;
1160
1161 case DNS_TYPE_MX:
1163 pThisRecord->Data.MX.pNameExchange,
1164 pThisRecord->Data.MX.wPreference,
1165 pThisRecord->Data.MX.Pad);
1166 break;
1167
1168 case DNS_TYPE_AAAA:
1169 RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address, sizeof(IN6_ADDR));
1170 RtlIpv6AddressToStringW(&Addr6, szBuffer);
1172 break;
1173
1174 case DNS_TYPE_ATMA:
1176 break;
1177
1178 case DNS_TYPE_SRV:
1180 pThisRecord->Data.SRV.pNameTarget,
1181 pThisRecord->Data.SRV.wPriority,
1182 pThisRecord->Data.SRV.wWeight,
1183 pThisRecord->Data.SRV.wPort);
1184 break;
1185 }
1186 ConPuts(StdOut, L"\n\n");
1187
1188 pThisRecord = pNextRecord;
1189 }
1190
1192}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#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
#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
LPWSTR GetRecordTypeName(WORD wType)
Definition: ipconfig.c:109
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::@1141 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 205 of file ipconfig.c.

207{
208 LPVOID lpMsgBuf;
209 //DWORD ErrorCode;
210
211 if (ErrorCode == 0)
213
217 NULL,
218 ErrorCode,
219 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
220 (LPWSTR)&lpMsgBuf,
221 0,
222 NULL))
223 {
224 ConPuts(StdOut, (LPWSTR)lpMsgBuf);
225 LocalFree(lpMsgBuf);
226 }
227}
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:397
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:396
WCHAR * LPWSTR
Definition: xmlstorage.h:184

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

◆ FlushDns()

VOID FlushDns ( VOID  )

Definition at line 1043 of file ipconfig.c.

1044{
1046
1048 {
1050 }
1051 else
1052 {
1055 }
1056}
#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_ LPSTR  lpClass,
_In_ DWORD  cchFriendlyNameLength,
_Out_ LPWSTR  pszFriendlyName 
)

Definition at line 249 of file ipconfig.c.

253{
254 HKEY hKey = NULL;
255 CHAR Path[256];
256 LPSTR PrePath = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
257 LPSTR PostPath = "\\Connection";
258 DWORD PathSize;
259 DWORD dwType;
260 DWORD dwDataSize;
261
262 /* don't overflow the buffer */
263 PathSize = strlen(PrePath) + strlen(lpClass) + strlen(PostPath) + 1;
264 if (PathSize >= 255)
265 return;
266
267 sprintf(Path, "%s%s%s", PrePath, lpClass, PostPath);
268
270 Path,
271 0,
272 KEY_READ,
273 &hKey) == ERROR_SUCCESS)
274 {
275 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
277 L"Name",
278 NULL,
279 &dwType,
280 (PBYTE)pszFriendlyName,
281 &dwDataSize);
282 }
283
284 if (hKey != NULL)
286}
PRTL_UNICODE_STRING_BUFFER Path
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#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
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 HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175

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

◆ GetInterfaceFriendlyName()

VOID GetInterfaceFriendlyName ( _In_ LPWSTR  lpDeviceName,
_In_ DWORD  cchFriendlyNameLength,
_Out_ LPWSTR  pszFriendlyName 
)

Definition at line 289 of file ipconfig.c.

293{
294 HKEY hKey = NULL;
295 WCHAR Path[256];
296 LPWSTR PrePath = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
297 LPWSTR PostPath = L"\\Connection";
298 LPWSTR DevicePrefix = L"\\DEVICE\\TCPIP_";
299 DWORD PathSize;
300 DWORD dwType;
301 DWORD dwDataSize;
302
303 DWORD dwPrefixLength = wcslen(DevicePrefix);
304
305 /* don't overflow the buffer */
306 PathSize = wcslen(PrePath) + wcslen(lpDeviceName) - dwPrefixLength + wcslen(PostPath) + 1;
307 if (PathSize >= 255)
308 return;
309
310 swprintf(Path, L"%s%s%s", PrePath, &lpDeviceName[dwPrefixLength], PostPath);
311
313 Path,
314 0,
315 KEY_READ,
316 &hKey) == ERROR_SUCCESS)
317 {
318 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
320 L"Name",
321 NULL,
322 &dwType,
323 (PBYTE)pszFriendlyName,
324 &dwDataSize);
325 }
326
327 if (hKey != NULL)
329}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
#define swprintf
Definition: precomp.h:40
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ GetRecordTypeName()

LPWSTR GetRecordTypeName ( WORD  wType)

Definition at line 109 of file ipconfig.c.

110{
111 static WCHAR szType[8];
112 INT i;
113
114 for (i = 0; ; i++)
115 {
116 if (TypeArray[i].pszRecordName == NULL)
117 break;
118
119 if (TypeArray[i].wRecordType == wType)
120 return TypeArray[i].pszRecordName;
121 }
122
123 swprintf(szType, L"%hu", wType);
124
125 return szType;
126}
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:49
LPWSTR pszRecordName
Definition: ipconfig.c:41
int32_t INT
Definition: typedefs.h:58

Referenced by DisplayDnsRecord().

◆ GetUnicodeAdapterName()

LPWSTR GetUnicodeAdapterName ( _In_ LPSTR  pszAnsiName)

Definition at line 230 of file ipconfig.c.

232{
233 LPWSTR pszUnicodeName;
234 int i, len;
235
236 len = strlen(pszAnsiName);
237 pszUnicodeName = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
238 if (pszUnicodeName == NULL)
239 return NULL;
240
241 for (i = 0; i < len; i++)
242 pszUnicodeName[i] = (WCHAR)pszAnsiName[i];
243 pszUnicodeName[i] = UNICODE_NULL;
244
245 return pszUnicodeName;
246}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
GLenum GLsizei len
Definition: glext.h:6722
#define UNICODE_NULL

◆ MatchWildcard()

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

Definition at line 792 of file ipconfig.c.

795{
796 WCHAR *pCharE, *pCharN, charE, charN;
797
798 if (pszExpression == NULL)
799 return TRUE;
800
801 if (pszName == NULL)
802 return FALSE;
803
804 pCharE = pszExpression;
805 pCharN = pszName;
806 while (*pCharE != UNICODE_NULL)
807 {
808 charE = towlower(*pCharE);
809 charN = towlower(*pCharN);
810
811 if (charE == L'*')
812 {
813 if (*(pCharE + 1) != charN)
814 pCharN++;
815 else
816 pCharE++;
817 }
818 else if (charE == L'?')
819 {
820 pCharE++;
821 pCharN++;
822 }
823 else if (charE == charN)
824 {
825 pCharE++;
826 pCharN++;
827 }
828 else
829 {
830 return FALSE;
831 }
832 }
833
834 return TRUE;
835}
#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 ( LPSTR  lpClass)
static

Definition at line 333 of file ipconfig.c.

334{
335 HKEY hBaseKey = NULL;
337 LPSTR lpKeyClass = NULL;
338 LPSTR lpConDesc = NULL;
339 LPWSTR lpPath = NULL;
340 WCHAR szPrePath[] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\";
341 DWORD dwType;
342 DWORD dwDataSize;
343 INT i;
344
346 szPrePath,
347 0,
348 KEY_READ,
349 &hBaseKey) != ERROR_SUCCESS)
350 {
351 return;
352 }
353
354 for (i = 0; ; i++)
355 {
356 DWORD PathSize;
357 LONG Status;
358 WCHAR szName[10];
359 DWORD NameLen = 9;
360
361 if ((Status = RegEnumKeyExW(hBaseKey,
362 i,
363 szName,
364 &NameLen,
365 NULL,
366 NULL,
367 NULL,
368 NULL)) != ERROR_SUCCESS)
369 {
371 {
373 lpConDesc = NULL;
374 goto CLEANUP;
375 }
376 else
377 continue;
378 }
379
380 PathSize = wcslen(szPrePath) + wcslen(szName) + 1;
381 lpPath = (LPWSTR)HeapAlloc(ProcessHeap,
382 0,
383 PathSize * sizeof(WCHAR));
384 if (lpPath == NULL)
385 goto CLEANUP;
386
387 wsprintf(lpPath, L"%s%s", szPrePath, szName);
388
389 //MessageBox(NULL, lpPath, NULL, 0);
390
392 lpPath,
393 0,
394 KEY_READ,
396 {
397 goto CLEANUP;
398 }
399
400 HeapFree(ProcessHeap, 0, lpPath);
401 lpPath = NULL;
402
404 "NetCfgInstanceId",
405 NULL,
406 &dwType,
407 NULL,
408 &dwDataSize) == ERROR_SUCCESS)
409 {
410 lpKeyClass = (LPSTR)HeapAlloc(ProcessHeap,
411 0,
412 dwDataSize);
413 if (lpKeyClass == NULL)
414 goto CLEANUP;
415
417 "NetCfgInstanceId",
418 NULL,
419 &dwType,
420 (PBYTE)lpKeyClass,
421 &dwDataSize) != ERROR_SUCCESS)
422 {
423 HeapFree(ProcessHeap, 0, lpKeyClass);
424 lpKeyClass = NULL;
425 continue;
426 }
427 }
428 else
429 continue;
430
431 if (!strcmp(lpClass, lpKeyClass))
432 {
433 HeapFree(ProcessHeap, 0, lpKeyClass);
434 lpKeyClass = NULL;
435
437 "DriverDesc",
438 NULL,
439 &dwType,
440 NULL,
441 &dwDataSize) == ERROR_SUCCESS)
442 {
443 lpConDesc = (LPSTR)HeapAlloc(ProcessHeap,
444 0,
445 dwDataSize);
446 if (lpConDesc != NULL)
447 {
449 "DriverDesc",
450 NULL,
451 &dwType,
452 (PBYTE)lpConDesc,
453 &dwDataSize) == ERROR_SUCCESS)
454 {
455 printf("%s", lpConDesc);
456 }
457
458 HeapFree(ProcessHeap, 0, lpConDesc);
459 lpConDesc = NULL;
460 }
461 }
462
463 break;
464 }
465 }
466
467CLEANUP:
468 if (hBaseKey != NULL)
469 RegCloseKey(hBaseKey);
470 if (hClassKey != NULL)
472 if (lpPath != NULL)
473 HeapFree(ProcessHeap, 0, lpPath);
474 if (lpKeyClass != NULL)
475 HeapFree(ProcessHeap, 0, lpKeyClass);
476}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
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
#define printf
Definition: freeldr.h:97
HANDLE ProcessHeap
Definition: ipconfig.c:47
long LONG
Definition: pedump.c:60
static const WCHAR szName[]
Definition: powrprof.c:45
#define wsprintf
Definition: winuser.h:5976

Referenced by ShowInfo().

◆ PrintAdapterTypeAndName()

static VOID PrintAdapterTypeAndName ( PIP_ADAPTER_INFO  pAdapterInfo)
static

Definition at line 509 of file ipconfig.c.

511{
512 WCHAR szFriendlyName[MAX_PATH];
513
514 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
515
516 switch (pAdapterInfo->Type)
517 {
519 ConResPrintf(StdOut, IDS_OTHER, szFriendlyName);
520 break;
521
523 ConResPrintf(StdOut, IDS_ETH, szFriendlyName);
524 break;
525
527 ConResPrintf(StdOut, IDS_TOKEN, szFriendlyName);
528 break;
529
530 case MIB_IF_TYPE_FDDI:
531 ConResPrintf(StdOut, IDS_FDDI, szFriendlyName);
532 break;
533
534 case MIB_IF_TYPE_PPP:
535 ConResPrintf(StdOut, IDS_PPP, szFriendlyName);
536 break;
537
539 ConResPrintf(StdOut, IDS_LOOP, szFriendlyName);
540 break;
541
542 case MIB_IF_TYPE_SLIP:
543 ConResPrintf(StdOut, IDS_SLIP, szFriendlyName);
544 break;
545
547 ConResPrintf(StdOut, IDS_WIFI, szFriendlyName);
548 break;
549
550 default:
551 ConResPrintf(StdOut, IDS_UNKNOWNADAPTER, szFriendlyName);
552 break;
553 }
554}
#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_ LPSTR lpClass, _In_ DWORD cchFriendlyNameLength, _Out_ LPWSTR pszFriendlyName)
Definition: ipconfig.c:249
#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()

PCHAR PrintMacAddr ( PBYTE  Mac)

Definition at line 129 of file ipconfig.c.

130{
131 static CHAR MacAddr[20];
132
133 sprintf(MacAddr, "%02X-%02X-%02X-%02X-%02X-%02X",
134 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
135
136 return MacAddr;
137}

Referenced by ShowInfo().

◆ PrintNodeType()

static VOID PrintNodeType ( _In_ UINT  NodeType)
static

Definition at line 480 of file ipconfig.c.

482{
483 switch (NodeType)
484 {
487 break;
488
491 break;
492
493 case MIXED_NODETYPE:
495 break;
496
497 case HYBRID_NODETYPE:
499 break;
500
501 default :
503 break;
504 }
505}
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 1059 of file ipconfig.c.

1060{
1061 /* FIXME */
1062 printf("\nSorry /registerdns is not implemented yet\n");
1063}

Referenced by wmain().

◆ Release()

VOID Release ( LPWSTR  pszAdapterName)

Definition at line 838 of file ipconfig.c.

840{
841 PIP_ADAPTER_INFO pAdapterInfo = NULL;
842 PIP_ADAPTER_INFO pAdapter = NULL;
843 ULONG adaptOutBufLen = 0;
844 ULONG ret = 0;
845 WCHAR szFriendlyName[MAX_PATH];
846 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
847 MIB_IFROW mibEntry;
850
852
853 /* call GetAdaptersInfo to obtain the adapter info */
854 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
856 {
858 return;
859 }
860
861 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
862 if (pAdapterInfo == NULL)
863 {
865 return;
866 }
867
868 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
869 if (ret != NO_ERROR)
870 {
872 goto done;
873 }
874
876
877 pAdapter = pAdapterInfo;
878
879 while (pAdapter)
880 {
881 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
882
883 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
884 {
886
887 mibEntry.dwIndex = pAdapter->Index;
888 GetIfEntry(&mibEntry);
889
892 {
893 if (pAdapter->DhcpEnabled)
894 {
895 if (strcmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0"))
896 {
897 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
898 DPRINT1("AdapterName: %S\n", szUnicodeAdapterName);
899
900 /* Call DhcpReleaseParameters to release the IP address on the specified adapter. */
901 ret = DhcpReleaseParameters(szUnicodeAdapterName);
902 if (ret != NO_ERROR)
903 {
904 ConResPrintf(StdOut, IDS_DHCPRELEASEERROR, szFriendlyName);
906 }
907 }
908 else
909 {
911 }
912 }
913 else
914 {
915 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
916 }
917 }
918 else
919 {
920 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
921 }
922 }
923
924 pAdapter = pAdapter->Next;
925 }
926
928
929 if (bFoundAdapter == FALSE)
930 {
932 }
933 else
934 {
936 }
937
938done:
939 if (pAdapterInfo)
940 HeapFree(ProcessHeap, 0, pAdapterInfo);
941}
#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 DPRINT1
Definition: precomp.h:8
#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:102
DWORD APIENTRY DhcpReleaseParameters(_In_ PWSTR AdapterName)
Definition: dhcpcsvc.c:266
VOID APIENTRY DhcpCApiCleanup(VOID)
Definition: dhcpcsvc.c:116
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID ShowInfo(BOOL bShowHeader, BOOL bAll)
Definition: ipconfig.c:557
static BOOL MatchWildcard(_In_ PWSTR pszExpression, _In_ PWSTR pszName)
Definition: ipconfig.c:792
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 ( LPWSTR  pszAdapterName)

Definition at line 944 of file ipconfig.c.

946{
947 PIP_ADAPTER_INFO pAdapterInfo = NULL;
948 PIP_ADAPTER_INFO pAdapter = NULL;
949 ULONG adaptOutBufLen = 0;
950 ULONG ret = 0;
951 WCHAR szFriendlyName[MAX_PATH];
952 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
953 MIB_IFROW mibEntry;
956
958
959 /* call GetAdaptersInfo to obtain the adapter info */
960 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
962 {
964 return;
965 }
966
967 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
968 if (pAdapterInfo == NULL)
969 {
971 return;
972 }
973
974 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
975 if (ret != NO_ERROR)
976 {
978 goto done;
979 }
980
982
983 pAdapter = pAdapterInfo;
984
985 while (pAdapter)
986 {
987 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
988
989 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
990 {
992
993 mibEntry.dwIndex = pAdapter->Index;
994 GetIfEntry(&mibEntry);
995
998 {
999 if (pAdapter->DhcpEnabled)
1000 {
1001 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
1002 DPRINT1("AdapterName: %S\n", szUnicodeAdapterName);
1003
1004 /* Call DhcpAcquireParameters to renew the IP address on the specified adapter. */
1005 ret = DhcpAcquireParameters(szUnicodeAdapterName);
1006 if (ret != NO_ERROR)
1007 {
1008 ConResPrintf(StdOut, IDS_DHCPRENEWERROR, szFriendlyName);
1010 }
1011 }
1012 else
1013 {
1014 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
1015 }
1016 }
1017 else
1018 {
1019 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
1020 }
1021 }
1022
1023 pAdapter = pAdapter->Next;
1024 }
1025
1027
1028 if (bFoundAdapter == FALSE)
1029 {
1031 }
1032 else
1033 {
1035 }
1036
1037done:
1038 if (pAdapterInfo)
1039 HeapFree(ProcessHeap, 0, pAdapterInfo);
1040}
#define IDS_DHCPRENEWERROR
Definition: resource.h:80
DWORD APIENTRY DhcpAcquireParameters(_In_ PWSTR AdapterName)
Definition: dhcpcsvc.c:132

Referenced by wmain().

◆ SetClassId()

VOID SetClassId ( LPWSTR  pszAdapterName,
LPWSTR  pszClassId 
)

Definition at line 1237 of file ipconfig.c.

1240{
1241 PIP_ADAPTER_INFO pAdapterInfo = NULL;
1242 PIP_ADAPTER_INFO pAdapter = NULL, pFoundAdapter = NULL;
1243 ULONG adaptOutBufLen = 0;
1244 ULONG ret = 0;
1245 WCHAR szFriendlyName[MAX_PATH];
1246 WCHAR szKeyName[256];
1247 MIB_IFROW mibEntry;
1248 HKEY hKey;
1249
1251
1252 /* call GetAdaptersInfo to obtain the adapter info */
1253 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1255 {
1257 return;
1258 }
1259
1260 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
1261 if (pAdapterInfo == NULL)
1262 {
1264 return;
1265 }
1266
1267 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1268 if (ret != NO_ERROR)
1269 {
1270 DoFormatMessage(0);
1271 goto done;
1272 }
1273
1274 pAdapter = pAdapterInfo;
1275 while (pAdapter)
1276 {
1277 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
1278
1279 if (MatchWildcard(pszAdapterName, szFriendlyName))
1280 {
1281 mibEntry.dwIndex = pAdapter->Index;
1282 GetIfEntry(&mibEntry);
1283
1286 {
1287 pFoundAdapter = pAdapter;
1288 break;
1289 }
1290 }
1291
1292 pAdapter = pAdapter->Next;
1293 }
1294
1295 if (pFoundAdapter)
1296 {
1297 swprintf(szKeyName,
1298 L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%S",
1299 pFoundAdapter->AdapterName);
1300
1302 szKeyName,
1303 0,
1304 KEY_WRITE,
1305 &hKey);
1306 if (ret != ERROR_SUCCESS)
1307 {
1308 ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1310 goto done;
1311 }
1312
1313 if (pszClassId == NULL)
1314 pszClassId = L"";
1315
1316 RegSetValueExW(hKey, L"DhcpClassId", 0, REG_SZ, (LPBYTE)pszClassId, (wcslen(pszClassId) + 1) * sizeof(WCHAR));
1318
1319 ConResPrintf(StdOut, IDS_DHCPSETIDSUCCESS, szFriendlyName);
1320 }
1321 else
1322 {
1324 }
1325
1326done:
1327 if (pAdapterInfo)
1328 HeapFree(ProcessHeap, 0, pAdapterInfo);
1329}
#define IDS_DHCPSETIDSUCCESS
Definition: resource.h:82
#define IDS_DHCPSETIDERROR
Definition: resource.h:81
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 KEY_WRITE
Definition: nt_native.h:1034
unsigned char * LPBYTE
Definition: typedefs.h:53

Referenced by wmain().

◆ ShowClassId()

VOID ShowClassId ( LPWSTR  pszAdapterName)

Definition at line 1230 of file ipconfig.c.

1232{
1233 printf("\nSorry /showclassid adapter is not implemented yet\n");
1234}

Referenced by wmain().

◆ ShowInfo()

VOID ShowInfo ( BOOL  bShowHeader,
BOOL  bAll 
)

Definition at line 557 of file ipconfig.c.

560{
561 MIB_IFROW mibEntry;
562 PIP_ADAPTER_INFO pAdapterInfo = NULL;
563 PIP_ADAPTER_INFO pAdapter = NULL;
564 ULONG adaptOutBufLen = 0;
565 PFIXED_INFO pFixedInfo = NULL;
566 ULONG netOutBufLen = 0;
567 PIP_PER_ADAPTER_INFO pPerAdapterInfo = NULL;
568 ULONG ulPerAdapterInfoLength = 0;
569 PSTR pszDomainName = NULL;
570 DWORD dwDomainNameSize = 0;
571 ULONG ret = 0;
572
573 GetComputerNameExA(ComputerNameDnsDomain,
574 NULL,
575 &dwDomainNameSize);
576 if (dwDomainNameSize > 0)
577 {
578 pszDomainName = HeapAlloc(ProcessHeap,
579 0,
580 dwDomainNameSize * sizeof(CHAR));
581 if (pszDomainName != NULL)
582 GetComputerNameExA(ComputerNameDnsDomain,
583 pszDomainName,
584 &dwDomainNameSize);
585 }
586
587 /* call GetAdaptersInfo to obtain the adapter info */
588 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
590 {
591 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
592 if (pAdapterInfo == NULL)
593 goto done;
594
595 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
596 if (ret != NO_ERROR)
597 {
599 goto done;
600 }
601 }
602 else
603 {
604 if (ret != ERROR_NO_DATA)
605 {
607 goto done;
608 }
609 }
610
611 /* call GetNetworkParams to obtain the network info */
612 if (GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
613 {
614 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
615 if (pFixedInfo == NULL)
616 {
617 goto done;
618 }
619 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
620 {
622 goto done;
623 }
624 }
625 else
626 {
628 goto done;
629 }
630
631 pAdapter = pAdapterInfo;
632
633 if (bShowHeader)
635
636 if (bAll)
637 {
639 ConResPrintf(StdOut, IDS_PRIMARYDNSSUFFIX, (pszDomainName != NULL) ? pszDomainName : "");
640
641 PrintNodeType(pFixedInfo->NodeType);
642
643 if (pFixedInfo->EnableRouting)
645 else
647
648 if (pAdapter && pAdapter->HaveWins)
650 else
652
653 if (pszDomainName != NULL && pszDomainName[0] != 0)
654 {
655 ConResPrintf(StdOut, IDS_DNSSUFFIXLIST, pszDomainName);
657 }
658 else
659 {
661 }
662 }
663
664 while (pAdapter)
665 {
667
668 mibEntry.dwIndex = pAdapter->Index;
669 GetIfEntry(&mibEntry);
670
671 PrintAdapterTypeAndName(pAdapter);
672
673 if (GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength) == ERROR_BUFFER_OVERFLOW)
674 {
675 pPerAdapterInfo = (PIP_PER_ADAPTER_INFO)HeapAlloc(ProcessHeap, 0, ulPerAdapterInfoLength);
676 if (pPerAdapterInfo != NULL)
677 {
678 GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength);
679 }
680 }
681
682 /* check if the adapter is connected to the media */
684 {
687 }
688 else
689 {
691 }
692
693 if (bAll)
694 {
697 printf("\n");
698
700
701 if (bConnected)
702 {
703 if (pAdapter->DhcpEnabled)
704 {
706
707 if (pPerAdapterInfo != NULL)
708 {
709 if (pPerAdapterInfo->AutoconfigEnabled)
711 else
713 }
714 }
715 else
716 {
718 }
719 }
720 }
721
722 if (!bConnected)
723 {
724 pAdapter = pAdapter->Next;
725 continue;
726 }
727
730
731 if (strcmp(pAdapter->GatewayList.IpAddress.String, "0.0.0.0"))
733 else
735
736 if (bAll)
737 {
738 PIP_ADDR_STRING pIPAddr;
739
740 if (pAdapter->DhcpEnabled)
742
744 pIPAddr = pFixedInfo->DnsServerList.Next;
745 while (pIPAddr)
746 {
748 pIPAddr = pIPAddr->Next;
749 }
750
751 if (pAdapter->HaveWins)
752 {
755 }
756
757 if (pAdapter->DhcpEnabled && strcmp(pAdapter->DhcpServer.IpAddress.String, "255.255.255.255"))
758 {
759 PWSTR DateTimeString;
760 DateTimeString = timeToStr(pAdapter->LeaseObtained);
761 ConResPrintf(StdOut, IDS_LEASEOBTAINED, DateTimeString ? DateTimeString : L"N/A");
762 if (DateTimeString)
763 {
764 HeapFree(ProcessHeap, 0, DateTimeString);
765 }
766 DateTimeString = timeToStr(pAdapter->LeaseExpires);
767 ConResPrintf(StdOut, IDS_LEASEEXPIRES, DateTimeString ? DateTimeString : L"N/A");
768 if (DateTimeString)
769 {
770 HeapFree(ProcessHeap, 0, DateTimeString);
771 }
772 }
773 }
774
775 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
776 pPerAdapterInfo = NULL;
777
778 pAdapter = pAdapter->Next;
779 }
780
781done:
782 if (pszDomainName)
783 HeapFree(ProcessHeap, 0, pszDomainName);
784 if (pFixedInfo)
785 HeapFree(ProcessHeap, 0, pFixedInfo);
786 if (pAdapterInfo)
787 HeapFree(ProcessHeap, 0, pAdapterInfo);
788}
unsigned char BOOLEAN
#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
_Ret_opt_z_ PWSTR timeToStr(_In_ time_t TimeStamp)
Definition: ipconfig.c:141
static VOID PrintAdapterDescription(LPSTR lpClass)
Definition: ipconfig.c:333
PCHAR PrintMacAddr(PBYTE Mac)
Definition: ipconfig.c:129
static VOID PrintNodeType(_In_ UINT NodeType)
Definition: ipconfig.c:480
static VOID PrintAdapterTypeAndName(PIP_ADAPTER_INFO pAdapterInfo)
Definition: ipconfig.c:509
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
uint16_t * PWSTR
Definition: typedefs.h:56
char * PSTR
Definition: typedefs.h:51
#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 141 of file ipconfig.c.

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

Referenced by ShowInfo().

◆ Usage()

VOID Usage ( _In_ BOOL  Error)

Definition at line 1332 of file ipconfig.c.

1334{
1335 if (Error)
1338}
#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 1340 of file ipconfig.c.

1341{
1342 BOOL DoUsage=FALSE;
1343 BOOL DoAll=FALSE;
1344 BOOL DoRelease=FALSE;
1345 BOOL DoRenew=FALSE;
1346 BOOL DoFlushdns=FALSE;
1347 BOOL DoRegisterdns=FALSE;
1348 BOOL DoDisplaydns=FALSE;
1349 BOOL DoShowclassid=FALSE;
1350 BOOL DoSetclassid=FALSE;
1351
1352 /* Initialize the Console Standard Streams */
1354
1357
1358 /* Parse command line for options we have been given. */
1359 if ((argc > 1) && (argv[1][0] == L'/' || argv[1][0] == L'-'))
1360 {
1361 if (!_wcsicmp(&argv[1][1], L"?"))
1362 {
1363 DoUsage = TRUE;
1364 }
1365 else if (!_wcsnicmp(&argv[1][1], L"ALL", wcslen(&argv[1][1])))
1366 {
1367 DoAll = TRUE;
1368 }
1369 else if (!_wcsnicmp(&argv[1][1], L"RELEASE", wcslen(&argv[1][1])))
1370 {
1371 DoRelease = TRUE;
1372 }
1373 else if (!_wcsnicmp(&argv[1][1], L"RENEW", wcslen(&argv[1][1])))
1374 {
1375 DoRenew = TRUE;
1376 }
1377 else if (!_wcsnicmp(&argv[1][1], L"FLUSHDNS", wcslen(&argv[1][1])))
1378 {
1379 DoFlushdns = TRUE;
1380 }
1381 else if (!_wcsnicmp(&argv[1][1], L"FLUSHREGISTERDNS", wcslen(&argv[1][1])))
1382 {
1383 DoRegisterdns = TRUE;
1384 }
1385 else if (!_wcsnicmp(&argv[1][1], L"DISPLAYDNS", wcslen(&argv[1][1])))
1386 {
1387 DoDisplaydns = TRUE;
1388 }
1389 else if (!_wcsnicmp(&argv[1][1], L"SHOWCLASSID", wcslen(&argv[1][1])))
1390 {
1391 DoShowclassid = TRUE;
1392 }
1393 else if (!_wcsnicmp(&argv[1][1], L"SETCLASSID", wcslen(&argv[1][1])))
1394 {
1395 DoSetclassid = TRUE;
1396 }
1397 }
1398
1399 switch (argc)
1400 {
1401 case 1: /* Default behaviour if no options are given*/
1403 break;
1404 case 2: /* Process all the options that take no parameters */
1405 if (DoUsage)
1406 Usage(FALSE);
1407 else if (DoAll)
1408 ShowInfo(TRUE, TRUE);
1409 else if (DoRelease)
1410 Release(NULL);
1411 else if (DoRenew)
1412 Renew(NULL);
1413 else if (DoFlushdns)
1414 FlushDns();
1415 else if (DoRegisterdns)
1416 RegisterDns();
1417 else if (DoDisplaydns)
1418 DisplayDns();
1419 else
1420 Usage(TRUE);
1421 break;
1422 case 3: /* Process all the options that can have 1 parameter */
1423 if (DoRelease)
1424 Release(argv[2]);
1425 else if (DoRenew)
1426 Renew(argv[2]);
1427 else if (DoShowclassid)
1428 ShowClassId(argv[2]);
1429 else if (DoSetclassid)
1430 SetClassId(argv[2], NULL);
1431 else
1432 Usage(TRUE);
1433 break;
1434 case 4: /* Process all the options that can have 2 parameters */
1435 if (DoSetclassid)
1436 SetClassId(argv[2], argv[3]);
1437 else
1438 Usage(TRUE);
1439 break;
1440 default:
1441 Usage(TRUE);
1442 }
1443
1444 return 0;
1445}
static int argc
Definition: ServiceArgs.c:12
#define ConInitStdStreams()
Definition: fc.c:13
_In_ BOOLEAN Release
Definition: cdrom.h:920
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
VOID Renew(LPWSTR pszAdapterName)
Definition: ipconfig.c:944
VOID RegisterDns(VOID)
Definition: ipconfig.c:1059
VOID FlushDns(VOID)
Definition: ipconfig.c:1043
VOID SetClassId(LPWSTR pszAdapterName, LPWSTR pszClassId)
Definition: ipconfig.c:1237
HINSTANCE hInstance
Definition: ipconfig.c:46
VOID ShowClassId(LPWSTR pszAdapterName)
Definition: ipconfig.c:1230
VOID DisplayDns(VOID)
Definition: ipconfig.c:1195
#define argv
Definition: mplay32.c:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define GetModuleHandle
Definition: winbase.h:3576

Variable Documentation

◆ hInstance

HINSTANCE hInstance

Definition at line 46 of file ipconfig.c.

Referenced by wmain().

◆ ProcessHeap

HANDLE ProcessHeap
  • Internal Headers *‍/

Definition at line 47 of file ipconfig.c.

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

◆ TypeArray

RECORDTYPE TypeArray[]

Definition at line 49 of file ipconfig.c.

Referenced by GetRecordTypeName().