ReactOS 0.4.16-dev-1535-gea189a3
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 <tchar.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

LPTSTR GetRecordTypeName (WORD wType)
 
PCHAR PrintMacAddr (PBYTE Mac)
 
_Ret_opt_z_ PTSTR timeToStr (_In_ time_t TimeStamp)
 
VOID DoFormatMessage (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 (VOID)
 
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 48 of file ipconfig.c.

◆ NDEBUG

#define NDEBUG

Definition at line 39 of file ipconfig.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 13 of file ipconfig.c.

Typedef Documentation

◆ PRECORDTYPE

◆ RECORDTYPE

Function Documentation

◆ DisplayDns()

VOID DisplayDns ( VOID  )

Definition at line 1197 of file ipconfig.c.

1198{
1199 PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
1200
1202
1203 if (!DnsGetCacheDataTable(&DnsEntry))
1204 {
1206 return;
1207 }
1208
1209 if (DnsEntry == NULL)
1210 return;
1211
1212 pThisEntry = DnsEntry;
1213 while (pThisEntry != NULL)
1214 {
1215 pNextEntry = pThisEntry->pNext;
1216
1217 if (pThisEntry->wType1 != DNS_TYPE_ZERO)
1218 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
1219
1220 if (pThisEntry->wType2 != DNS_TYPE_ZERO)
1221 DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
1222
1223 if (pThisEntry->pszName)
1224 LocalFree(pThisEntry->pszName);
1225 LocalFree(pThisEntry);
1226
1227 pThisEntry = pNextEntry;
1228 }
1229}
#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(LONG ErrorCode)
Definition: ipconfig.c:208
static VOID DisplayDnsRecord(PWSTR pszName, WORD wType)
Definition: ipconfig.c:1069
Definition: windns_undoc.h:9
struct _DNS_CACHE_ENTRY * pNext
Definition: windns_undoc.h:10
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define DNS_TYPE_ZERO
Definition: windns.h:40

Referenced by wmain().

◆ DisplayDnsRecord()

static VOID DisplayDnsRecord ( PWSTR  pszName,
WORD  wType 
)
static

Definition at line 1069 of file ipconfig.c.

1072{
1073 PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
1074 WCHAR szBuffer[48];
1075 IN_ADDR Addr4;
1076 IN6_ADDR Addr6;
1077 DNS_STATUS Status;
1078
1079 ConResPrintf(StdOut, IDS_DNSNAME, pszName);
1081
1082 pQueryResults = NULL;
1083 Status = DnsQuery_W(pszName,
1084 wType,
1086 NULL,
1087 (PDNS_RECORD *)&pQueryResults,
1088 NULL);
1089 if (Status != ERROR_SUCCESS)
1090 {
1092 {
1094 }
1095 else if (Status == DNS_INFO_NO_RECORDS)
1096 {
1098 }
1099 return;
1100 }
1101
1102 pThisRecord = pQueryResults;
1103 while (pThisRecord != NULL)
1104 {
1105 pNextRecord = pThisRecord->pNext;
1106
1107 ConResPrintf(StdOut, IDS_DNSRECORDNAME, pThisRecord->pName);
1108 ConResPrintf(StdOut, IDS_DNSRECORDTYPE, pThisRecord->wType);
1109 ConResPrintf(StdOut, IDS_DNSRECORDTTL, pThisRecord->dwTtl);
1110 ConResPrintf(StdOut, IDS_DNSRECORDLENGTH, pThisRecord->wDataLength);
1111
1112 switch (pThisRecord->Flags.S.Section)
1113 {
1114 case DnsSectionQuestion:
1116 break;
1117
1118 case DnsSectionAnswer:
1120 break;
1121
1124 break;
1125
1128 break;
1129 }
1130
1131 switch (pThisRecord->wType)
1132 {
1133 case DNS_TYPE_A:
1134 Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
1135 RtlIpv4AddressToStringW(&Addr4, szBuffer);
1136 ConResPrintf(StdOut, IDS_DNSTYPEA, szBuffer);
1137 break;
1138
1139 case DNS_TYPE_NS:
1140 ConResPrintf(StdOut, IDS_DNSTYPENS, pThisRecord->Data.NS.pNameHost);
1141 break;
1142
1143 case DNS_TYPE_CNAME:
1144 ConResPrintf(StdOut, IDS_DNSTYPECNAME, pThisRecord->Data.CNAME.pNameHost);
1145 break;
1146
1147 case DNS_TYPE_SOA:
1149 pThisRecord->Data.SOA.pNamePrimaryServer,
1150 pThisRecord->Data.SOA.pNameAdministrator,
1151 pThisRecord->Data.SOA.dwSerialNo);
1153 pThisRecord->Data.SOA.dwRefresh,
1154 pThisRecord->Data.SOA.dwRetry,
1155 pThisRecord->Data.SOA.dwExpire,
1156 pThisRecord->Data.SOA.dwDefaultTtl);
1157 break;
1158
1159 case DNS_TYPE_PTR:
1160 ConResPrintf(StdOut, IDS_DNSTYPEPTR, pThisRecord->Data.PTR.pNameHost);
1161 break;
1162
1163 case DNS_TYPE_MX:
1165 pThisRecord->Data.MX.pNameExchange,
1166 pThisRecord->Data.MX.wPreference,
1167 pThisRecord->Data.MX.Pad);
1168 break;
1169
1170 case DNS_TYPE_AAAA:
1171 RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address, sizeof(IN6_ADDR));
1172 RtlIpv6AddressToStringW(&Addr6, szBuffer);
1174 break;
1175
1176 case DNS_TYPE_ATMA:
1178 break;
1179
1180 case DNS_TYPE_SRV:
1182 pThisRecord->Data.SRV.pNameTarget,
1183 pThisRecord->Data.SRV.wPriority,
1184 pThisRecord->Data.SRV.wWeight,
1185 pThisRecord->Data.SRV.wPort);
1186 break;
1187 }
1188 ConPuts(StdOut, L"\n\n");
1189
1190 pThisRecord = pNextRecord;
1191 }
1192
1194}
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:70
#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:71
#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
LPTSTR GetRecordTypeName(WORD wType)
Definition: ipconfig.c:113
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)
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::@1148 S_un
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#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 PDNS_RECORD
Definition: windns.h:636
#define DNS_TYPE_A
Definition: windns.h:41
#define DNS_INFO_NO_RECORDS
Definition: winerror.h:2672
#define DNS_ERROR_RCODE_NAME_ERROR
Definition: winerror.h:2629
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DisplayDns().

◆ DoFormatMessage()

VOID DoFormatMessage ( LONG  ErrorCode)

Definition at line 208 of file ipconfig.c.

209{
210 LPVOID lpMsgBuf;
211 //DWORD ErrorCode;
212
213 if (ErrorCode == 0)
215
219 NULL,
220 ErrorCode,
221 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
222 (LPTSTR) &lpMsgBuf,
223 0,
224 NULL))
225 {
226 _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
227 LocalFree(lpMsgBuf);
228 }
229}
#define _tprintf
Definition: tchar.h:506
_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 _T(x)
Definition: vfdio.h:22
#define FormatMessage
Definition: winbase.h:3836
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:453
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:456
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:452
CHAR * LPTSTR
Definition: xmlstorage.h:192

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

◆ FlushDns()

VOID FlushDns ( VOID  )

Definition at line 1045 of file ipconfig.c.

1046{
1048
1050 {
1052 }
1053 else
1054 {
1057 }
1058}
#define IDS_DNSFLUSHERROR
Definition: resource.h:72
#define IDS_DNSFLUSHSUCCESS
Definition: resource.h:73
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 251 of file ipconfig.c.

255{
256 HKEY hKey = NULL;
257 CHAR Path[256];
258 LPSTR PrePath = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
259 LPSTR PostPath = "\\Connection";
260 DWORD PathSize;
261 DWORD dwType;
262 DWORD dwDataSize;
263
264 /* don't overflow the buffer */
265 PathSize = strlen(PrePath) + strlen(lpClass) + strlen(PostPath) + 1;
266 if (PathSize >= 255)
267 return;
268
269 sprintf(Path, "%s%s%s", PrePath, lpClass, PostPath);
270
272 Path,
273 0,
274 KEY_READ,
275 &hKey) == ERROR_SUCCESS)
276 {
277 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
279 L"Name",
280 NULL,
281 &dwType,
282 (PBYTE)pszFriendlyName,
283 &dwDataSize);
284 }
285
286 if (hKey != NULL)
288}
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(buf, format,...)
Definition: sprintf.c:55
#define KEY_READ
Definition: nt_native.h:1023
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 291 of file ipconfig.c.

295{
296 HKEY hKey = NULL;
297 WCHAR Path[256];
298 LPWSTR PrePath = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
299 LPWSTR PostPath = L"\\Connection";
300 LPWSTR DevicePrefix = L"\\DEVICE\\TCPIP_";
301 DWORD PathSize;
302 DWORD dwType;
303 DWORD dwDataSize;
304
305 DWORD dwPrefixLength = wcslen(DevicePrefix);
306
307 /* don't overflow the buffer */
308 PathSize = wcslen(PrePath) + wcslen(lpDeviceName) - dwPrefixLength + wcslen(PostPath) + 1;
309 if (PathSize >= 255)
310 return;
311
312 swprintf(Path, L"%s%s%s", PrePath, &lpDeviceName[dwPrefixLength], PostPath);
313
315 Path,
316 0,
317 KEY_READ,
318 &hKey) == ERROR_SUCCESS)
319 {
320 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
322 L"Name",
323 NULL,
324 &dwType,
325 (PBYTE)pszFriendlyName,
326 &dwDataSize);
327 }
328
329 if (hKey != NULL)
331}
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)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ GetRecordTypeName()

LPTSTR GetRecordTypeName ( WORD  wType)

Definition at line 113 of file ipconfig.c.

114{
115 static TCHAR szType[8];
116 INT i;
117
118 for (i = 0; ; i++)
119 {
120 if (TypeArray[i].pszRecordName == NULL)
121 break;
122
123 if (TypeArray[i].wRecordType == wType)
124 return TypeArray[i].pszRecordName;
125 }
126
127 _stprintf(szType, _T("%hu"), wType);
128
129 return szType;
130}
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:53
#define _stprintf
Definition: utility.h:124
LPTSTR pszRecordName
Definition: ipconfig.c:45
int32_t INT
Definition: typedefs.h:58
char TCHAR
Definition: xmlstorage.h:189

Referenced by DisplayDnsRecord().

◆ GetUnicodeAdapterName()

LPWSTR GetUnicodeAdapterName ( _In_ LPSTR  pszAnsiName)

Definition at line 232 of file ipconfig.c.

234{
235 LPWSTR pszUnicodeName;
236 int i, len;
237
238 len = strlen(pszAnsiName);
239 pszUnicodeName = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
240 if (pszUnicodeName == NULL)
241 return NULL;
242
243 for (i = 0; i < len; i++)
244 pszUnicodeName[i] = (WCHAR)pszAnsiName[i];
245 pszUnicodeName[i] = UNICODE_NULL;
246
247 return pszUnicodeName;
248}
#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 794 of file ipconfig.c.

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

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

Referenced by ShowInfo().

◆ PrintAdapterTypeAndName()

static VOID PrintAdapterTypeAndName ( PIP_ADAPTER_INFO  pAdapterInfo)
static

Definition at line 511 of file ipconfig.c.

513{
514 WCHAR szFriendlyName[MAX_PATH];
515
516 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
517
518 switch (pAdapterInfo->Type)
519 {
521 ConResPrintf(StdOut, IDS_OTHER, szFriendlyName);
522 break;
523
525 ConResPrintf(StdOut, IDS_ETH, szFriendlyName);
526 break;
527
529 ConResPrintf(StdOut, IDS_TOKEN, szFriendlyName);
530 break;
531
532 case MIB_IF_TYPE_FDDI:
533 ConResPrintf(StdOut, IDS_FDDI, szFriendlyName);
534 break;
535
536 case MIB_IF_TYPE_PPP:
537 ConResPrintf(StdOut, IDS_PPP, szFriendlyName);
538 break;
539
541 ConResPrintf(StdOut, IDS_LOOP, szFriendlyName);
542 break;
543
544 case MIB_IF_TYPE_SLIP:
545 ConResPrintf(StdOut, IDS_SLIP, szFriendlyName);
546 break;
547
549 ConResPrintf(StdOut, IDS_WIFI, szFriendlyName);
550 break;
551
552 default:
553 ConResPrintf(StdOut, IDS_UNKNOWNADAPTER, szFriendlyName);
554 break;
555 }
556}
#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:251
#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:55

Referenced by ShowInfo().

◆ PrintMacAddr()

PCHAR PrintMacAddr ( PBYTE  Mac)

Definition at line 133 of file ipconfig.c.

134{
135 static CHAR MacAddr[20];
136
137 sprintf(MacAddr, "%02X-%02X-%02X-%02X-%02X-%02X",
138 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
139
140 return MacAddr;
141}

Referenced by ShowInfo().

◆ PrintNodeType()

static VOID PrintNodeType ( _In_ UINT  NodeType)
static

Definition at line 482 of file ipconfig.c.

484{
485 switch (NodeType)
486 {
489 break;
490
493 break;
494
495 case MIXED_NODETYPE:
497 break;
498
499 case HYBRID_NODETYPE:
501 break;
502
503 default :
505 break;
506 }
507}
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:38
#define HYBRID_NODETYPE
Definition: iptypes.h:39
#define PEER_TO_PEER_NODETYPE
Definition: iptypes.h:37
#define BROADCAST_NODETYPE
Definition: iptypes.h:36

Referenced by ShowInfo().

◆ RegisterDns()

VOID RegisterDns ( VOID  )

Definition at line 1061 of file ipconfig.c.

1062{
1063 /* FIXME */
1064 _tprintf(_T("\nSorry /registerdns is not implemented yet\n"));
1065}

Referenced by wmain().

◆ Release()

VOID Release ( LPWSTR  pszAdapterName)

Definition at line 840 of file ipconfig.c.

842{
843 PIP_ADAPTER_INFO pAdapterInfo = NULL;
844 PIP_ADAPTER_INFO pAdapter = NULL;
845 ULONG adaptOutBufLen = 0;
846 ULONG ret = 0;
847 WCHAR szFriendlyName[MAX_PATH];
848 WCHAR szUnicodeAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
849 MIB_IFROW mibEntry;
852
854
855 /* call GetAdaptersInfo to obtain the adapter info */
856 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
858 {
860 return;
861 }
862
863 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
864 if (pAdapterInfo == NULL)
865 {
866 _tprintf(_T("memory allocation error"));
867 return;
868 }
869
870 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
871 if (ret != NO_ERROR)
872 {
874 goto done;
875 }
876
878
879 pAdapter = pAdapterInfo;
880
881 while (pAdapter)
882 {
883 GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
884
885 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
886 {
888
889 mibEntry.dwIndex = pAdapter->Index;
890 GetIfEntry(&mibEntry);
891
894 {
895 if (pAdapter->DhcpEnabled)
896 {
897 if (strcmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0"))
898 {
899 mbstowcs(szUnicodeAdapterName, pAdapter->AdapterName, strlen(pAdapter->AdapterName) + 1);
900 DPRINT1("AdapterName: %S\n", szUnicodeAdapterName);
901
902 /* Call DhcpReleaseParameters to release the IP address on the specified adapter. */
903 ret = DhcpReleaseParameters(szUnicodeAdapterName);
904 if (ret != NO_ERROR)
905 {
906 ConResPrintf(StdOut, IDS_DHCPRELEASEERROR, szFriendlyName);
908 }
909 }
910 else
911 {
913 }
914 }
915 else
916 {
917 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
918 }
919 }
920 else
921 {
922 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
923 }
924 }
925
926 pAdapter = pAdapter->Next;
927 }
928
930
931 if (bFoundAdapter == FALSE)
932 {
934 }
935 else
936 {
938 }
939
940done:
941 if (pAdapterInfo)
942 HeapFree(ProcessHeap, 0, pAdapterInfo);
943}
DWORD dwVersion
Definition: LocaleTests.cpp:63
#define IDS_DHCPRELEASED
Definition: resource.h:77
#define IDS_DHCPNOTENABLED
Definition: resource.h:75
#define IDS_DHCPNOADAPTER
Definition: resource.h:76
#define IDS_DHCPNOTCONNECTED
Definition: resource.h:74
#define IDS_DHCPRELEASEERROR
Definition: resource.h:78
#define DPRINT1
Definition: precomp.h:8
#define NO_ERROR
Definition: dderror.h:5
static BOOL bFoundAdapter
Definition: deskmon.c:13
void WINAPI DhcpCApiCleanup(void)
Definition: dhcpcsvc.c:71
DWORD APIENTRY DhcpReleaseParameters(_In_ PWSTR AdapterName)
Definition: dhcpcsvc.c:112
DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version)
Definition: dhcpcsvc.c:26
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID ShowInfo(BOOL bShowHeader, BOOL bAll)
Definition: ipconfig.c:559
static BOOL MatchWildcard(_In_ PWSTR pszExpression, _In_ PWSTR pszName)
Definition: ipconfig.c:794
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
#define MAX_ADAPTER_NAME_LENGTH
Definition: iptypes.h:27
mbstowcs
Definition: stdlib.h:925
char String[4 *4]
Definition: iptypes.h:42
IP_ADDR_STRING IpAddressList
Definition: iptypes.h:63
struct _IP_ADAPTER_INFO * Next
Definition: iptypes.h:53
UINT DhcpEnabled
Definition: iptypes.h:61
IP_ADDRESS_STRING IpAddress
Definition: iptypes.h:47
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:308

◆ Renew()

VOID Renew ( LPWSTR  pszAdapterName)

Definition at line 946 of file ipconfig.c.

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

Referenced by wmain().

◆ SetClassId()

VOID SetClassId ( LPWSTR  pszAdapterName,
LPWSTR  pszClassId 
)

Definition at line 1239 of file ipconfig.c.

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

Referenced by wmain().

◆ ShowClassId()

VOID ShowClassId ( LPWSTR  pszAdapterName)

Definition at line 1232 of file ipconfig.c.

1234{
1235 _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
1236}

Referenced by wmain().

◆ ShowInfo()

VOID ShowInfo ( BOOL  bShowHeader,
BOOL  bAll 
)

Definition at line 559 of file ipconfig.c.

562{
563 MIB_IFROW mibEntry;
564 PIP_ADAPTER_INFO pAdapterInfo = NULL;
565 PIP_ADAPTER_INFO pAdapter = NULL;
566 ULONG adaptOutBufLen = 0;
567 PFIXED_INFO pFixedInfo = NULL;
568 ULONG netOutBufLen = 0;
569 PIP_PER_ADAPTER_INFO pPerAdapterInfo = NULL;
570 ULONG ulPerAdapterInfoLength = 0;
571 PSTR pszDomainName = NULL;
572 DWORD dwDomainNameSize = 0;
573 ULONG ret = 0;
574
575 GetComputerNameExA(ComputerNameDnsDomain,
576 NULL,
577 &dwDomainNameSize);
578 if (dwDomainNameSize > 0)
579 {
580 pszDomainName = HeapAlloc(ProcessHeap,
581 0,
582 dwDomainNameSize * sizeof(TCHAR));
583 if (pszDomainName != NULL)
584 GetComputerNameExA(ComputerNameDnsDomain,
585 pszDomainName,
586 &dwDomainNameSize);
587 }
588
589 /* call GetAdaptersInfo to obtain the adapter info */
590 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
592 {
593 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
594 if (pAdapterInfo == NULL)
595 goto done;
596
597 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
598 if (ret != NO_ERROR)
599 {
601 goto done;
602 }
603 }
604 else
605 {
606 if (ret != ERROR_NO_DATA)
607 {
609 goto done;
610 }
611 }
612
613 /* call GetNetworkParams to obtain the network info */
614 if (GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
615 {
616 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
617 if (pFixedInfo == NULL)
618 {
619 goto done;
620 }
621 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
622 {
624 goto done;
625 }
626 }
627 else
628 {
630 goto done;
631 }
632
633 pAdapter = pAdapterInfo;
634
635 if (bShowHeader)
637
638 if (bAll)
639 {
641 ConResPrintf(StdOut, IDS_PRIMARYDNSSUFFIX, (pszDomainName != NULL) ? pszDomainName : "");
642
643 PrintNodeType(pFixedInfo->NodeType);
644
645 if (pFixedInfo->EnableRouting)
647 else
649
650 if (pAdapter && pAdapter->HaveWins)
652 else
654
655 if (pszDomainName != NULL && pszDomainName[0] != 0)
656 {
657 ConResPrintf(StdOut, IDS_DNSSUFFIXLIST, pszDomainName);
659 }
660 else
661 {
663 }
664 }
665
666 while (pAdapter)
667 {
669
670 mibEntry.dwIndex = pAdapter->Index;
671 GetIfEntry(&mibEntry);
672
673 PrintAdapterTypeAndName(pAdapter);
674
675 if (GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength) == ERROR_BUFFER_OVERFLOW)
676 {
677 pPerAdapterInfo = (PIP_PER_ADAPTER_INFO)HeapAlloc(ProcessHeap, 0, ulPerAdapterInfoLength);
678 if (pPerAdapterInfo != NULL)
679 {
680 GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength);
681 }
682 }
683
684 /* check if the adapter is connected to the media */
686 {
689 }
690 else
691 {
693 }
694
695 if (bAll)
696 {
699 printf("\n");
700
702
703 if (bConnected)
704 {
705 if (pAdapter->DhcpEnabled)
706 {
708
709 if (pPerAdapterInfo != NULL)
710 {
711 if (pPerAdapterInfo->AutoconfigEnabled)
713 else
715 }
716 }
717 else
718 {
720 }
721 }
722 }
723
724 if (!bConnected)
725 {
726 pAdapter = pAdapter->Next;
727 continue;
728 }
729
732
733 if (strcmp(pAdapter->GatewayList.IpAddress.String, "0.0.0.0"))
735 else
737
738 if (bAll)
739 {
740 PIP_ADDR_STRING pIPAddr;
741
742 if (pAdapter->DhcpEnabled)
744
746 pIPAddr = pFixedInfo->DnsServerList.Next;
747 while (pIPAddr)
748 {
749 ConResPrintf(StdOut, IDS_EMPTYLINE, pIPAddr ->IpAddress.String);
750 pIPAddr = pIPAddr->Next;
751 }
752
753 if (pAdapter->HaveWins)
754 {
757 }
758
759 if (pAdapter->DhcpEnabled && strcmp(pAdapter->DhcpServer.IpAddress.String, "255.255.255.255"))
760 {
761 PTSTR DateTimeString;
762 DateTimeString = timeToStr(pAdapter->LeaseObtained);
763 ConResPrintf(StdOut, IDS_LEASEOBTAINED, DateTimeString ? DateTimeString : _T("N/A"));
764 if (DateTimeString)
765 {
766 HeapFree(ProcessHeap, 0, DateTimeString);
767 }
768 DateTimeString = timeToStr(pAdapter->LeaseExpires);
769 ConResPrintf(StdOut, IDS_LEASEEXPIRES, DateTimeString ? DateTimeString : _T("N/A"));
770 if (DateTimeString)
771 {
772 HeapFree(ProcessHeap, 0, DateTimeString);
773 }
774 }
775 }
776
777 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
778 pPerAdapterInfo = NULL;
779
780 pAdapter = pAdapter->Next;
781 }
782
783done:
784 if (pszDomainName)
785 HeapFree(ProcessHeap, 0, pszDomainName);
786 if (pFixedInfo)
787 HeapFree(ProcessHeap, 0, pFixedInfo);
788 if (pAdapterInfo)
789 HeapFree(ProcessHeap, 0, pAdapterInfo);
790}
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_ PTSTR timeToStr(_In_ time_t TimeStamp)
Definition: ipconfig.c:145
static VOID PrintAdapterDescription(LPSTR lpClass)
Definition: ipconfig.c:335
PCHAR PrintMacAddr(PBYTE Mac)
Definition: ipconfig.c:133
static VOID PrintNodeType(_In_ UINT NodeType)
Definition: ipconfig.c:482
static VOID PrintAdapterTypeAndName(PIP_ADAPTER_INFO pAdapterInfo)
Definition: ipconfig.c:511
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
struct _IP_PER_ADAPTER_INFO * PIP_PER_ADAPTER_INFO
IP_ADDR_STRING DnsServerList
Definition: iptypes.h:84
UINT EnableRouting
Definition: iptypes.h:87
char HostName[MAX_HOSTNAME_LEN+4]
Definition: iptypes.h:81
UINT NodeType
Definition: iptypes.h:85
char DomainName[MAX_DOMAIN_NAME_LEN+4]
Definition: iptypes.h:82
IP_ADDR_STRING SecondaryWinsServer
Definition: iptypes.h:68
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]
Definition: iptypes.h:58
IP_ADDR_STRING DhcpServer
Definition: iptypes.h:65
time_t LeaseObtained
Definition: iptypes.h:69
IP_ADDR_STRING GatewayList
Definition: iptypes.h:64
time_t LeaseExpires
Definition: iptypes.h:70
IP_ADDR_STRING PrimaryWinsServer
Definition: iptypes.h:67
struct _IP_ADDR_STRING * Next
Definition: iptypes.h:46
IP_MASK_STRING IpMask
Definition: iptypes.h:48
UINT AutoconfigEnabled
Definition: iptypes.h:74
char * PSTR
Definition: typedefs.h:51
#define ERROR_NO_DATA
Definition: winerror.h:407
CHAR * PTSTR
Definition: xmlstorage.h:191

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

◆ timeToStr()

_Ret_opt_z_ PTSTR timeToStr ( _In_ time_t  TimeStamp)

Definition at line 145 of file ipconfig.c.

146{
147 struct tm* ptm;
148 SYSTEMTIME SystemTime;
149 INT DateCchSize, TimeCchSize, TotalCchSize, i;
150 PTSTR DateTimeString, psz;
151
152 /* Convert Unix time to SYSTEMTIME */
153 /* localtime_s may be preferred if available */
154 ptm = localtime(&TimeStamp);
155 if (!ptm)
156 {
157 return NULL;
158 }
159 SystemTime.wYear = ptm->tm_year + 1900;
160 SystemTime.wMonth = ptm->tm_mon + 1;
161 SystemTime.wDay = ptm->tm_mday;
162 SystemTime.wHour = ptm->tm_hour;
163 SystemTime.wMinute = ptm->tm_min;
164 SystemTime.wSecond = ptm->tm_sec;
165
166 /* Get total size in characters required of buffer */
167 DateCchSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &SystemTime, NULL, NULL, 0);
168 if (!DateCchSize)
169 {
170 return NULL;
171 }
172 TimeCchSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &SystemTime, NULL, NULL, 0);
173 if (!TimeCchSize)
174 {
175 return NULL;
176 }
177 /* Two terminating null are included, the first one will be replaced by space */
178 TotalCchSize = DateCchSize + TimeCchSize;
179
180 /* Allocate buffer and format datetime string */
181 DateTimeString = (PTSTR)HeapAlloc(ProcessHeap, 0, TotalCchSize * sizeof(TCHAR));
182 if (!DateTimeString)
183 {
184 return NULL;
185 }
186
187 /* Get date string */
188 i = GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &SystemTime, NULL, DateTimeString, TotalCchSize);
189 if (i)
190 {
191 /* Append space and move pointer */
192 DateTimeString[i - 1] = _T(' ');
193 psz = DateTimeString + i;
194 TotalCchSize -= i;
195
196 /* Get time string */
197 if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, &SystemTime, NULL, psz, TotalCchSize))
198 {
199 return DateTimeString;
200 }
201 }
202
203 HeapFree(ProcessHeap, 0, DateTimeString);
204 return NULL;
205}
#define LOCALE_USER_DEFAULT
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
WORD wYear
Definition: winbase.h:946
WORD wMonth
Definition: winbase.h:947
WORD wHour
Definition: winbase.h:950
WORD wSecond
Definition: winbase.h:952
WORD wMinute
Definition: winbase.h:951
WORD wDay
Definition: winbase.h:949
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 GetTimeFormat
Definition: winnls.h:1292
#define DATE_LONGDATE
Definition: winnls.h:210
#define GetDateFormat
Definition: winnls.h:1287

Referenced by ShowInfo().

◆ Usage()

VOID Usage ( VOID  )

Definition at line 1334 of file ipconfig.c.

1335{
1337}
#define IDS_USAGE
Definition: resource.h:3

◆ wmain()

int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 1339 of file ipconfig.c.

1340{
1341 BOOL DoUsage=FALSE;
1342 BOOL DoAll=FALSE;
1343 BOOL DoRelease=FALSE;
1344 BOOL DoRenew=FALSE;
1345 BOOL DoFlushdns=FALSE;
1346 BOOL DoRegisterdns=FALSE;
1347 BOOL DoDisplaydns=FALSE;
1348 BOOL DoShowclassid=FALSE;
1349 BOOL DoSetclassid=FALSE;
1350
1351 /* Initialize the Console Standard Streams */
1353
1356
1357 /* Parse command line for options we have been given. */
1358 if ((argc > 1) && (argv[1][0]=='/' || argv[1][0]=='-'))
1359 {
1360 if (!_tcsicmp(&argv[1][1], _T("?")))
1361 {
1362 DoUsage = TRUE;
1363 }
1364 else if (!_tcsnicmp(&argv[1][1], _T("ALL"), _tcslen(&argv[1][1])))
1365 {
1366 DoAll = TRUE;
1367 }
1368 else if (!_tcsnicmp(&argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1])))
1369 {
1370 DoRelease = TRUE;
1371 }
1372 else if (!_tcsnicmp(&argv[1][1], _T("RENEW"), _tcslen(&argv[1][1])))
1373 {
1374 DoRenew = TRUE;
1375 }
1376 else if (!_tcsnicmp(&argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1])))
1377 {
1378 DoFlushdns = TRUE;
1379 }
1380 else if (!_tcsnicmp(&argv[1][1], _T("FLUSHREGISTERDNS"), _tcslen(&argv[1][1])))
1381 {
1382 DoRegisterdns = TRUE;
1383 }
1384 else if (!_tcsnicmp(&argv[1][1], _T("DISPLAYDNS"), _tcslen(&argv[1][1])))
1385 {
1386 DoDisplaydns = TRUE;
1387 }
1388 else if (!_tcsnicmp(&argv[1][1], _T("SHOWCLASSID"), _tcslen(&argv[1][1])))
1389 {
1390 DoShowclassid = TRUE;
1391 }
1392 else if (!_tcsnicmp(&argv[1][1], _T("SETCLASSID"), _tcslen(&argv[1][1])))
1393 {
1394 DoSetclassid = TRUE;
1395 }
1396 }
1397
1398 switch (argc)
1399 {
1400 case 1: /* Default behaviour if no options are given*/
1402 break;
1403 case 2: /* Process all the options that take no parameters */
1404 if (DoUsage)
1405 Usage();
1406 else if (DoAll)
1407 ShowInfo(TRUE, TRUE);
1408 else if (DoRelease)
1409 Release(NULL);
1410 else if (DoRenew)
1411 Renew(NULL);
1412 else if (DoFlushdns)
1413 FlushDns();
1414 else if (DoRegisterdns)
1415 RegisterDns();
1416 else if (DoDisplaydns)
1417 DisplayDns();
1418 else
1419 Usage();
1420 break;
1421 case 3: /* Process all the options that can have 1 parameter */
1422 if (DoRelease)
1423 Release(argv[2]);
1424 else if (DoRenew)
1425 Renew(argv[2]);
1426 else if (DoShowclassid)
1427 ShowClassId(argv[2]);
1428 else if (DoSetclassid)
1429 SetClassId(argv[2], NULL);
1430 else
1431 Usage();
1432 break;
1433 case 4: /* Process all the options that can have 2 parameters */
1434 if (DoSetclassid)
1435 SetClassId(argv[2], argv[3]);
1436 else
1437 Usage();
1438 break;
1439 default:
1440 Usage();
1441 }
1442
1443 return 0;
1444}
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:946
VOID RegisterDns(VOID)
Definition: ipconfig.c:1061
VOID FlushDns(VOID)
Definition: ipconfig.c:1045
VOID SetClassId(LPWSTR pszAdapterName, LPWSTR pszClassId)
Definition: ipconfig.c:1239
HINSTANCE hInstance
Definition: ipconfig.c:50
VOID ShowClassId(LPWSTR pszAdapterName)
Definition: ipconfig.c:1232
VOID DisplayDns(VOID)
Definition: ipconfig.c:1197
#define argv
Definition: mplay32.c:18
#define GetModuleHandle
Definition: winbase.h:3868
#define _tcsnicmp
Definition: xmlstorage.h:207
#define _tcslen
Definition: xmlstorage.h:198
#define _tcsicmp
Definition: xmlstorage.h:205

Variable Documentation

◆ hInstance

HINSTANCE hInstance

Definition at line 50 of file ipconfig.c.

Referenced by wmain().

◆ ProcessHeap

HANDLE ProcessHeap
  • Internal Headers *‍/

Definition at line 51 of file ipconfig.c.

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

◆ TypeArray

RECORDTYPE TypeArray[]

Definition at line 53 of file ipconfig.c.

Referenced by GetRecordTypeName().