ReactOS 0.4.15-dev-7918-g2a2556c
ipconfig.c File Reference
#include <stdarg.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 <strsafe.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for ipconfig.c:

Go to the source code of this file.

Classes

struct  _RECORDTYPE
 

Macros

#define WIN32_NO_STATUS
 
#define GUID_LEN   40
 

Typedefs

typedef struct _RECORDTYPE RECORDTYPE
 
typedef struct _RECORDTYPEPRECORDTYPE
 

Functions

LPTSTR GetRecordTypeName (WORD wType)
 
PCHAR PrintMacAddr (PBYTE Mac)
 
_Ret_opt_z_ PTSTR timeToStr (_In_ time_t TimeStamp)
 
VOID DoFormatMessage (LONG ErrorCode)
 
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)
 
static VOID BuildAdapterMap (PIP_ADAPTER_INDEX_MAP pAdapterMap, PIP_ADAPTER_INFO pAdapterInfo)
 
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 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 40 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

◆ BuildAdapterMap()

static VOID BuildAdapterMap ( PIP_ADAPTER_INDEX_MAP  pAdapterMap,
PIP_ADAPTER_INFO  pAdapterInfo 
)
static

Definition at line 814 of file ipconfig.c.

817{
818 int i, l1, l2;
819
820 pAdapterMap->Index = pAdapterInfo->Index;
821
822 wcscpy(pAdapterMap->Name, L"\\DEVICE\\TCPIP_");
823 l1 = wcslen(pAdapterMap->Name);
824 l2 = strlen(pAdapterInfo->AdapterName);
825 for (i = 0; i < l2; i++)
826 pAdapterMap->Name[i + l1] = (WCHAR)pAdapterInfo->AdapterName[i];
827 pAdapterMap->Name[i + l1] = UNICODE_NULL;
828}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
WCHAR Name[MAX_ADAPTER_NAME]
Definition: ipexport.h:147
char AdapterName[MAX_ADAPTER_NAME_LENGTH+4]
Definition: iptypes.h:55
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Release(), and Renew().

◆ DisplayDns()

VOID DisplayDns ( VOID  )

Definition at line 1176 of file ipconfig.c.

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

1051{
1052 PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
1053 WCHAR szBuffer[48];
1054 IN_ADDR Addr4;
1055 IN6_ADDR Addr6;
1056 DNS_STATUS Status;
1057
1058 ConResPrintf(StdOut, IDS_DNSNAME, pszName);
1060
1061 pQueryResults = NULL;
1062 Status = DnsQuery_W(pszName,
1063 wType,
1065 NULL,
1066 (PDNS_RECORD *)&pQueryResults,
1067 NULL);
1068 if (Status != ERROR_SUCCESS)
1069 {
1071 {
1073 }
1074 else if (Status == DNS_INFO_NO_RECORDS)
1075 {
1077 }
1078 return;
1079 }
1080
1081 pThisRecord = pQueryResults;
1082 while (pThisRecord != NULL)
1083 {
1084 pNextRecord = pThisRecord->pNext;
1085
1086 ConResPrintf(StdOut, IDS_DNSRECORDNAME, pThisRecord->pName);
1087 ConResPrintf(StdOut, IDS_DNSRECORDTYPE, pThisRecord->wType);
1088 ConResPrintf(StdOut, IDS_DNSRECORDTTL, pThisRecord->dwTtl);
1089 ConResPrintf(StdOut, IDS_DNSRECORDLENGTH, pThisRecord->wDataLength);
1090
1091 switch (pThisRecord->Flags.S.Section)
1092 {
1093 case DnsSectionQuestion:
1095 break;
1096
1097 case DnsSectionAnswer:
1099 break;
1100
1103 break;
1104
1107 break;
1108 }
1109
1110 switch (pThisRecord->wType)
1111 {
1112 case DNS_TYPE_A:
1113 Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
1114 RtlIpv4AddressToStringW(&Addr4, szBuffer);
1115 ConResPrintf(StdOut, IDS_DNSTYPEA, szBuffer);
1116 break;
1117
1118 case DNS_TYPE_NS:
1119 ConResPrintf(StdOut, IDS_DNSTYPENS, pThisRecord->Data.NS.pNameHost);
1120 break;
1121
1122 case DNS_TYPE_CNAME:
1123 ConResPrintf(StdOut, IDS_DNSTYPECNAME, pThisRecord->Data.CNAME.pNameHost);
1124 break;
1125
1126 case DNS_TYPE_SOA:
1128 pThisRecord->Data.SOA.pNamePrimaryServer,
1129 pThisRecord->Data.SOA.pNameAdministrator,
1130 pThisRecord->Data.SOA.dwSerialNo);
1132 pThisRecord->Data.SOA.dwRefresh,
1133 pThisRecord->Data.SOA.dwRetry,
1134 pThisRecord->Data.SOA.dwExpire,
1135 pThisRecord->Data.SOA.dwDefaultTtl);
1136 break;
1137
1138 case DNS_TYPE_PTR:
1139 ConResPrintf(StdOut, IDS_DNSTYPEPTR, pThisRecord->Data.PTR.pNameHost);
1140 break;
1141
1142 case DNS_TYPE_MX:
1144 pThisRecord->Data.MX.pNameExchange,
1145 pThisRecord->Data.MX.wPreference,
1146 pThisRecord->Data.MX.Pad);
1147 break;
1148
1149 case DNS_TYPE_AAAA:
1150 RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address, sizeof(IN6_ADDR));
1151 RtlIpv6AddressToStringW(&Addr6, szBuffer);
1153 break;
1154
1155 case DNS_TYPE_ATMA:
1157 break;
1158
1159 case DNS_TYPE_SRV:
1161 pThisRecord->Data.SRV.pNameTarget,
1162 pThisRecord->Data.SRV.wPriority,
1163 pThisRecord->Data.SRV.wWeight,
1164 pThisRecord->Data.SRV.wPort);
1165 break;
1166 }
1167 ConPuts(StdOut, L"\n\n");
1168
1169 pThisRecord = pNextRecord;
1170 }
1171
1173}
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
Status
Definition: gdiplustypes.h:25
LPTSTR GetRecordTypeName(WORD wType)
Definition: ipconfig.c:105
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: tcpip.h:126
u_long S_addr
Definition: tcpip.h:131
union in_addr::@1020 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:1861
#define DNS_ERROR_RCODE_NAME_ERROR
Definition: winerror.h:1850

Referenced by DisplayDns().

◆ DoFormatMessage()

VOID DoFormatMessage ( LONG  ErrorCode)

Definition at line 200 of file ipconfig.c.

201{
202 LPVOID lpMsgBuf;
203 //DWORD ErrorCode;
204
205 if (ErrorCode == 0)
207
211 NULL,
212 ErrorCode,
213 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
214 (LPTSTR) &lpMsgBuf,
215 0,
216 NULL))
217 {
218 _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
219 LocalFree(lpMsgBuf);
220 }
221}
#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:3795
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
CHAR * LPTSTR
Definition: xmlstorage.h:192

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

◆ FlushDns()

VOID FlushDns ( VOID  )

Definition at line 1024 of file ipconfig.c.

1025{
1027
1029 {
1031 }
1032 else
1033 {
1036 }
1037}
#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 224 of file ipconfig.c.

228{
229 HKEY hKey = NULL;
230 CHAR Path[256];
231 LPSTR PrePath = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
232 LPSTR PostPath = "\\Connection";
233 DWORD PathSize;
234 DWORD dwType;
235 DWORD dwDataSize;
236
237 /* don't overflow the buffer */
238 PathSize = strlen(PrePath) + strlen(lpClass) + strlen(PostPath) + 1;
239 if (PathSize >= 255)
240 return;
241
242 sprintf(Path, "%s%s%s", PrePath, lpClass, PostPath);
243
245 Path,
246 0,
247 KEY_READ,
248 &hKey) == ERROR_SUCCESS)
249 {
250 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
252 L"Name",
253 NULL,
254 &dwType,
255 (PBYTE)pszFriendlyName,
256 &dwDataSize);
257 }
258
259 if (hKey != NULL)
261}
PRTL_UNICODE_STRING_BUFFER Path
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
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(), and Renew().

◆ GetInterfaceFriendlyName()

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

Definition at line 264 of file ipconfig.c.

268{
269 HKEY hKey = NULL;
270 WCHAR Path[256];
271 LPWSTR PrePath = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
272 LPWSTR PostPath = L"\\Connection";
273 LPWSTR DevicePrefix = L"\\DEVICE\\TCPIP_";
274 DWORD PathSize;
275 DWORD dwType;
276 DWORD dwDataSize;
277
278 DWORD dwPrefixLength = wcslen(DevicePrefix);
279
280 /* don't overflow the buffer */
281 PathSize = wcslen(PrePath) + wcslen(lpDeviceName) - dwPrefixLength + wcslen(PostPath) + 1;
282 if (PathSize >= 255)
283 return;
284
285 swprintf(Path, L"%s%s%s", PrePath, &lpDeviceName[dwPrefixLength], PostPath);
286
288 Path,
289 0,
290 KEY_READ,
291 &hKey) == ERROR_SUCCESS)
292 {
293 dwDataSize = cchFriendlyNameLength * sizeof(WCHAR);
295 L"Name",
296 NULL,
297 &dwType,
298 (PBYTE)pszFriendlyName,
299 &dwDataSize);
300 }
301
302 if (hKey != NULL)
304}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
#define swprintf
Definition: precomp.h:40
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ GetRecordTypeName()

LPTSTR GetRecordTypeName ( WORD  wType)

Definition at line 105 of file ipconfig.c.

106{
107 static TCHAR szType[8];
108 INT i;
109
110 for (i = 0; ; i++)
111 {
112 if (TypeArray[i].pszRecordName == NULL)
113 break;
114
115 if (TypeArray[i].wRecordType == wType)
116 return TypeArray[i].pszRecordName;
117 }
118
119 _stprintf(szType, _T("%hu"), wType);
120
121 return szType;
122}
RECORDTYPE TypeArray[]
Definition: ipconfig.c:45
#define _stprintf
Definition: utility.h:124
LPTSTR pszRecordName
Definition: ipconfig.c:37
int32_t INT
Definition: typedefs.h:58
char TCHAR
Definition: xmlstorage.h:189

Referenced by DisplayDnsRecord().

◆ MatchWildcard()

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

Definition at line 767 of file ipconfig.c.

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

Referenced by Release(), and Renew().

◆ PrintAdapterDescription()

static VOID PrintAdapterDescription ( LPSTR  lpClass)
static

Definition at line 308 of file ipconfig.c.

309{
310 HKEY hBaseKey = NULL;
312 LPSTR lpKeyClass = NULL;
313 LPSTR lpConDesc = NULL;
314 LPTSTR lpPath = NULL;
315 TCHAR szPrePath[] = _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\");
316 DWORD dwType;
317 DWORD dwDataSize;
318 INT i;
319
321 szPrePath,
322 0,
323 KEY_READ,
324 &hBaseKey) != ERROR_SUCCESS)
325 {
326 return;
327 }
328
329 for (i = 0; ; i++)
330 {
331 DWORD PathSize;
332 LONG Status;
333 TCHAR szName[10];
334 DWORD NameLen = 9;
335
336 if ((Status = RegEnumKeyEx(hBaseKey,
337 i,
338 szName,
339 &NameLen,
340 NULL,
341 NULL,
342 NULL,
343 NULL)) != ERROR_SUCCESS)
344 {
346 {
348 lpConDesc = NULL;
349 goto CLEANUP;
350 }
351 else
352 continue;
353 }
354
355 PathSize = lstrlen(szPrePath) + lstrlen(szName) + 1;
356 lpPath = (LPTSTR)HeapAlloc(ProcessHeap,
357 0,
358 PathSize * sizeof(TCHAR));
359 if (lpPath == NULL)
360 goto CLEANUP;
361
362 wsprintf(lpPath, _T("%s%s"), szPrePath, szName);
363
364 //MessageBox(NULL, lpPath, NULL, 0);
365
367 lpPath,
368 0,
369 KEY_READ,
371 {
372 goto CLEANUP;
373 }
374
375 HeapFree(ProcessHeap, 0, lpPath);
376 lpPath = NULL;
377
379 "NetCfgInstanceId",
380 NULL,
381 &dwType,
382 NULL,
383 &dwDataSize) == ERROR_SUCCESS)
384 {
385 lpKeyClass = (LPSTR)HeapAlloc(ProcessHeap,
386 0,
387 dwDataSize);
388 if (lpKeyClass == NULL)
389 goto CLEANUP;
390
392 "NetCfgInstanceId",
393 NULL,
394 &dwType,
395 (PBYTE)lpKeyClass,
396 &dwDataSize) != ERROR_SUCCESS)
397 {
398 HeapFree(ProcessHeap, 0, lpKeyClass);
399 lpKeyClass = NULL;
400 continue;
401 }
402 }
403 else
404 continue;
405
406 if (!strcmp(lpClass, lpKeyClass))
407 {
408 HeapFree(ProcessHeap, 0, lpKeyClass);
409 lpKeyClass = NULL;
410
412 "DriverDesc",
413 NULL,
414 &dwType,
415 NULL,
416 &dwDataSize) == ERROR_SUCCESS)
417 {
418 lpConDesc = (LPSTR)HeapAlloc(ProcessHeap,
419 0,
420 dwDataSize);
421 if (lpConDesc != NULL)
422 {
424 "DriverDesc",
425 NULL,
426 &dwType,
427 (PBYTE)lpConDesc,
428 &dwDataSize) == ERROR_SUCCESS)
429 {
430 printf("%s", lpConDesc);
431 }
432
433 HeapFree(ProcessHeap, 0, lpConDesc);
434 lpConDesc = NULL;
435 }
436 }
437
438 break;
439 }
440 }
441
442CLEANUP:
443 if (hBaseKey != NULL)
444 RegCloseKey(hBaseKey);
445 if (hClassKey != NULL)
447 if (lpPath != NULL)
448 HeapFree(ProcessHeap, 0, lpPath);
449 if (lpKeyClass != NULL)
450 HeapFree(ProcessHeap, 0, lpKeyClass);
451}
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 HeapAlloc
Definition: compat.h:733
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define HeapFree(x, y, z)
Definition: compat.h:735
#define printf
Definition: freeldr.h:93
HANDLE ProcessHeap
Definition: ipconfig.c:43
long LONG
Definition: pedump.c:60
static const WCHAR szName[]
Definition: powrprof.c:45
#define lstrlen
Definition: winbase.h:3876
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegEnumKeyEx
Definition: winreg.h:510
#define wsprintf
Definition: winuser.h:5865

Referenced by ShowInfo().

◆ PrintAdapterTypeAndName()

static VOID PrintAdapterTypeAndName ( PIP_ADAPTER_INFO  pAdapterInfo)
static

Definition at line 484 of file ipconfig.c.

486{
487 WCHAR szFriendlyName[MAX_PATH];
488
489 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
490
491 switch (pAdapterInfo->Type)
492 {
494 ConResPrintf(StdOut, IDS_OTHER, szFriendlyName);
495 break;
496
498 ConResPrintf(StdOut, IDS_ETH, szFriendlyName);
499 break;
500
502 ConResPrintf(StdOut, IDS_TOKEN, szFriendlyName);
503 break;
504
505 case MIB_IF_TYPE_FDDI:
506 ConResPrintf(StdOut, IDS_FDDI, szFriendlyName);
507 break;
508
509 case MIB_IF_TYPE_PPP:
510 ConResPrintf(StdOut, IDS_PPP, szFriendlyName);
511 break;
512
514 ConResPrintf(StdOut, IDS_LOOP, szFriendlyName);
515 break;
516
517 case MIB_IF_TYPE_SLIP:
518 ConResPrintf(StdOut, IDS_SLIP, szFriendlyName);
519 break;
520
522 ConResPrintf(StdOut, IDS_WIFI, szFriendlyName);
523 break;
524
525 default:
526 ConResPrintf(StdOut, IDS_UNKNOWNADAPTER, szFriendlyName);
527 break;
528 }
529}
#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:224
#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

Referenced by ShowInfo().

◆ PrintMacAddr()

PCHAR PrintMacAddr ( PBYTE  Mac)

Definition at line 125 of file ipconfig.c.

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

Referenced by ShowInfo().

◆ PrintNodeType()

static VOID PrintNodeType ( _In_ UINT  NodeType)
static

Definition at line 455 of file ipconfig.c.

457{
458 switch (NodeType)
459 {
462 break;
463
466 break;
467
468 case MIXED_NODETYPE:
470 break;
471
472 case HYBRID_NODETYPE:
474 break;
475
476 default :
478 break;
479 }
480}
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 1040 of file ipconfig.c.

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

Referenced by wmain().

◆ Release()

VOID Release ( LPWSTR  pszAdapterName)

Definition at line 831 of file ipconfig.c.

833{
834 PIP_ADAPTER_INFO pAdapterInfo = NULL;
835 PIP_ADAPTER_INFO pAdapter = NULL;
836 ULONG adaptOutBufLen = 0;
837 ULONG ret = 0;
838 WCHAR szFriendlyName[MAX_PATH];
839 MIB_IFROW mibEntry;
840 IP_ADAPTER_INDEX_MAP AdapterMap;
842
844
845 /* call GetAdaptersInfo to obtain the adapter info */
846 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
848 {
850 return;
851 }
852
853 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
854 if (pAdapterInfo == NULL)
855 {
856 _tprintf(_T("memory allocation error"));
857 return;
858 }
859
860 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
861 if (ret != NO_ERROR)
862 {
864 goto done;
865 }
866
867 pAdapter = pAdapterInfo;
868
869 while (pAdapter)
870 {
871 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
872
873 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
874 {
876
877 mibEntry.dwIndex = pAdapter->Index;
878 GetIfEntry(&mibEntry);
879
882 {
883 if (pAdapter->DhcpEnabled)
884 {
885 if (strcmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0"))
886 {
887 BuildAdapterMap(&AdapterMap, pAdapter);
888
889 /* Call IpReleaseAddress to release the IP address on the specified adapter. */
890 ret = IpReleaseAddress(&AdapterMap);
891 if (ret != NO_ERROR)
892 {
893 ConResPrintf(StdOut, IDS_DHCPRELEASEERROR, szFriendlyName);
895 }
896 }
897 else
898 {
900 }
901 }
902 else
903 {
904 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
905 }
906 }
907 else
908 {
909 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
910 }
911 }
912
913 pAdapter = pAdapter->Next;
914 }
915
916 if (bFoundAdapter == FALSE)
917 {
919 }
920 else
921 {
923 }
924
925done:
926 if (pAdapterInfo)
927 HeapFree(ProcessHeap, 0, pAdapterInfo);
928}
#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 NO_ERROR
Definition: dderror.h:5
static BOOL bFoundAdapter
Definition: deskmon.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID ShowInfo(BOOL bShowHeader, BOOL bAll)
Definition: ipconfig.c:532
static VOID BuildAdapterMap(PIP_ADAPTER_INDEX_MAP pAdapterMap, PIP_ADAPTER_INFO pAdapterInfo)
Definition: ipconfig.c:814
static BOOL MatchWildcard(_In_ PWSTR pszExpression, _In_ PWSTR pszName)
Definition: ipconfig.c:767
DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
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
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
int ret
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185

◆ Renew()

VOID Renew ( LPWSTR  pszAdapterName)

Definition at line 931 of file ipconfig.c.

933{
934 PIP_ADAPTER_INFO pAdapterInfo = NULL;
935 PIP_ADAPTER_INFO pAdapter = NULL;
936 ULONG adaptOutBufLen = 0;
937 ULONG ret = 0;
938 WCHAR szFriendlyName[MAX_PATH];
939 MIB_IFROW mibEntry;
940 IP_ADAPTER_INDEX_MAP AdapterMap;
942
944
945 /* call GetAdaptersInfo to obtain the adapter info */
946 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
948 {
950 return;
951 }
952
953 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
954 if (pAdapterInfo == NULL)
955 {
956 _tprintf(_T("memory allocation error"));
957 return;
958 }
959
960 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
961 if (ret != NO_ERROR)
962 {
964 goto done;
965 }
966
967 pAdapter = pAdapterInfo;
968
969 while (pAdapter)
970 {
971 GetAdapterFriendlyName(pAdapterInfo->AdapterName, MAX_PATH, szFriendlyName);
972
973 if ((pszAdapterName == NULL) || MatchWildcard(pszAdapterName, szFriendlyName))
974 {
976
977 mibEntry.dwIndex = pAdapter->Index;
978 GetIfEntry(&mibEntry);
979
982 {
983 if (pAdapter->DhcpEnabled)
984 {
985 BuildAdapterMap(&AdapterMap, pAdapter);
986
987 /* Call IpRenewAddress to renew the IP address on the specified adapter. */
988 ret = IpRenewAddress(&AdapterMap);
989 if (ret != NO_ERROR)
990 {
991 ConResPrintf(StdOut, IDS_DHCPRENEWERROR, szFriendlyName);
993 }
994 }
995 else
996 {
997 ConResPrintf(StdOut, IDS_DHCPNOTENABLED, szFriendlyName);
998 }
999 }
1000 else
1001 {
1002 ConResPrintf(StdOut, IDS_DHCPNOTCONNECTED, szFriendlyName);
1003 }
1004 }
1005
1006 pAdapter = pAdapter->Next;
1007 }
1008
1009 if (bFoundAdapter == FALSE)
1010 {
1012 }
1013 else
1014 {
1016 }
1017
1018done:
1019 if (pAdapterInfo)
1020 HeapFree(ProcessHeap, 0, pAdapterInfo);
1021}
#define IDS_DHCPRENEWERROR
Definition: resource.h:79
DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)

Referenced by wmain().

◆ ShowInfo()

VOID ShowInfo ( BOOL  bShowHeader,
BOOL  bAll 
)

Definition at line 532 of file ipconfig.c.

535{
536 MIB_IFROW mibEntry;
537 PIP_ADAPTER_INFO pAdapterInfo = NULL;
538 PIP_ADAPTER_INFO pAdapter = NULL;
539 ULONG adaptOutBufLen = 0;
540 PFIXED_INFO pFixedInfo = NULL;
541 ULONG netOutBufLen = 0;
542 PIP_PER_ADAPTER_INFO pPerAdapterInfo = NULL;
543 ULONG ulPerAdapterInfoLength = 0;
544 PSTR pszDomainName = NULL;
545 DWORD dwDomainNameSize = 0;
546 ULONG ret = 0;
547
548 GetComputerNameExA(ComputerNameDnsDomain,
549 NULL,
550 &dwDomainNameSize);
551 if (dwDomainNameSize > 0)
552 {
553 pszDomainName = HeapAlloc(ProcessHeap,
554 0,
555 dwDomainNameSize * sizeof(TCHAR));
556 if (pszDomainName != NULL)
557 GetComputerNameExA(ComputerNameDnsDomain,
558 pszDomainName,
559 &dwDomainNameSize);
560 }
561
562 /* call GetAdaptersInfo to obtain the adapter info */
563 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
565 {
566 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
567 if (pAdapterInfo == NULL)
568 goto done;
569
570 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
571 if (ret != NO_ERROR)
572 {
574 goto done;
575 }
576 }
577 else
578 {
579 if (ret != ERROR_NO_DATA)
580 {
582 goto done;
583 }
584 }
585
586 /* call GetNetworkParams to obtain the network info */
587 if (GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
588 {
589 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
590 if (pFixedInfo == NULL)
591 {
592 goto done;
593 }
594 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
595 {
597 goto done;
598 }
599 }
600 else
601 {
603 goto done;
604 }
605
606 pAdapter = pAdapterInfo;
607
608 if (bShowHeader)
610
611 if (bAll)
612 {
614 ConResPrintf(StdOut, IDS_PRIMARYDNSSUFFIX, (pszDomainName != NULL) ? pszDomainName : "");
615
616 PrintNodeType(pFixedInfo->NodeType);
617
618 if (pFixedInfo->EnableRouting)
620 else
622
623 if (pAdapter && pAdapter->HaveWins)
625 else
627
628 if (pszDomainName != NULL && pszDomainName[0] != 0)
629 {
630 ConResPrintf(StdOut, IDS_DNSSUFFIXLIST, pszDomainName);
632 }
633 else
634 {
636 }
637 }
638
639 while (pAdapter)
640 {
642
643 mibEntry.dwIndex = pAdapter->Index;
644 GetIfEntry(&mibEntry);
645
646 PrintAdapterTypeAndName(pAdapter);
647
648 if (GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength) == ERROR_BUFFER_OVERFLOW)
649 {
650 pPerAdapterInfo = (PIP_PER_ADAPTER_INFO)HeapAlloc(ProcessHeap, 0, ulPerAdapterInfoLength);
651 if (pPerAdapterInfo != NULL)
652 {
653 GetPerAdapterInfo(pAdapter->Index, pPerAdapterInfo, &ulPerAdapterInfoLength);
654 }
655 }
656
657 /* check if the adapter is connected to the media */
659 {
662 }
663 else
664 {
666 }
667
668 if (bAll)
669 {
672 printf("\n");
673
675
676 if (bConnected)
677 {
678 if (pAdapter->DhcpEnabled)
679 {
681
682 if (pPerAdapterInfo != NULL)
683 {
684 if (pPerAdapterInfo->AutoconfigEnabled)
686 else
688 }
689 }
690 else
691 {
693 }
694 }
695 }
696
697 if (!bConnected)
698 {
699 pAdapter = pAdapter->Next;
700 continue;
701 }
702
705
706 if (strcmp(pAdapter->GatewayList.IpAddress.String, "0.0.0.0"))
708 else
710
711 if (bAll)
712 {
713 PIP_ADDR_STRING pIPAddr;
714
715 if (pAdapter->DhcpEnabled)
717
719 pIPAddr = pFixedInfo->DnsServerList.Next;
720 while (pIPAddr)
721 {
722 ConResPrintf(StdOut, IDS_EMPTYLINE, pIPAddr ->IpAddress.String);
723 pIPAddr = pIPAddr->Next;
724 }
725
726 if (pAdapter->HaveWins)
727 {
730 }
731
732 if (pAdapter->DhcpEnabled && strcmp(pAdapter->DhcpServer.IpAddress.String, "255.255.255.255"))
733 {
734 PTSTR DateTimeString;
735 DateTimeString = timeToStr(pAdapter->LeaseObtained);
736 ConResPrintf(StdOut, IDS_LEASEOBTAINED, DateTimeString ? DateTimeString : _T("N/A"));
737 if (DateTimeString)
738 {
739 HeapFree(ProcessHeap, 0, DateTimeString);
740 }
741 DateTimeString = timeToStr(pAdapter->LeaseExpires);
742 ConResPrintf(StdOut, IDS_LEASEEXPIRES, DateTimeString ? DateTimeString : _T("N/A"));
743 if (DateTimeString)
744 {
745 HeapFree(ProcessHeap, 0, DateTimeString);
746 }
747 }
748 }
749
750 HeapFree(ProcessHeap, 0, pPerAdapterInfo);
751 pPerAdapterInfo = NULL;
752
753 pAdapter = pAdapter->Next;
754 }
755
756done:
757 if (pszDomainName)
758 HeapFree(ProcessHeap, 0, pszDomainName);
759 if (pFixedInfo)
760 HeapFree(ProcessHeap, 0, pFixedInfo);
761 if (pAdapterInfo)
762 HeapFree(ProcessHeap, 0, pAdapterInfo);
763}
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:137
static VOID PrintAdapterDescription(LPSTR lpClass)
Definition: ipconfig.c:308
PCHAR PrintMacAddr(PBYTE Mac)
Definition: ipconfig.c:125
static VOID PrintNodeType(_In_ UINT NodeType)
Definition: ipconfig.c:455
static VOID PrintAdapterTypeAndName(PIP_ADAPTER_INFO pAdapterInfo)
Definition: ipconfig.c:484
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:284
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 137 of file ipconfig.c.

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

Referenced by ShowInfo().

◆ Usage()

VOID Usage ( VOID  )

Definition at line 1210 of file ipconfig.c.

1211{
1213}
#define IDS_USAGE
Definition: resource.h:3

◆ wmain()

int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 1215 of file ipconfig.c.

1216{
1217 BOOL DoUsage=FALSE;
1218 BOOL DoAll=FALSE;
1219 BOOL DoRelease=FALSE;
1220 BOOL DoRenew=FALSE;
1221 BOOL DoFlushdns=FALSE;
1222 BOOL DoRegisterdns=FALSE;
1223 BOOL DoDisplaydns=FALSE;
1224 BOOL DoShowclassid=FALSE;
1225 BOOL DoSetclassid=FALSE;
1226
1227 /* Initialize the Console Standard Streams */
1229
1232
1233 /* Parse command line for options we have been given. */
1234 if ((argc > 1) && (argv[1][0]=='/' || argv[1][0]=='-'))
1235 {
1236 if (!_tcsicmp(&argv[1][1], _T("?")))
1237 {
1238 DoUsage = TRUE;
1239 }
1240 else if (!_tcsnicmp(&argv[1][1], _T("ALL"), _tcslen(&argv[1][1])))
1241 {
1242 DoAll = TRUE;
1243 }
1244 else if (!_tcsnicmp(&argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1])))
1245 {
1246 DoRelease = TRUE;
1247 }
1248 else if (!_tcsnicmp(&argv[1][1], _T("RENEW"), _tcslen(&argv[1][1])))
1249 {
1250 DoRenew = TRUE;
1251 }
1252 else if (!_tcsnicmp(&argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1])))
1253 {
1254 DoFlushdns = TRUE;
1255 }
1256 else if (!_tcsnicmp(&argv[1][1], _T("FLUSHREGISTERDNS"), _tcslen(&argv[1][1])))
1257 {
1258 DoRegisterdns = TRUE;
1259 }
1260 else if (!_tcsnicmp(&argv[1][1], _T("DISPLAYDNS"), _tcslen(&argv[1][1])))
1261 {
1262 DoDisplaydns = TRUE;
1263 }
1264 else if (!_tcsnicmp(&argv[1][1], _T("SHOWCLASSID"), _tcslen(&argv[1][1])))
1265 {
1266 DoShowclassid = TRUE;
1267 }
1268 else if (!_tcsnicmp(&argv[1][1], _T("SETCLASSID"), _tcslen(&argv[1][1])))
1269 {
1270 DoSetclassid = TRUE;
1271 }
1272 }
1273
1274 switch (argc)
1275 {
1276 case 1: /* Default behaviour if no options are given*/
1278 break;
1279 case 2: /* Process all the options that take no parameters */
1280 if (DoUsage)
1281 Usage();
1282 else if (DoAll)
1283 ShowInfo(TRUE, TRUE);
1284 else if (DoRelease)
1285 Release(NULL);
1286 else if (DoRenew)
1287 Renew(NULL);
1288 else if (DoFlushdns)
1289 FlushDns();
1290 else if (DoRegisterdns)
1291 RegisterDns();
1292 else if (DoDisplaydns)
1293 DisplayDns();
1294 else
1295 Usage();
1296 break;
1297 case 3: /* Process all the options that can have 1 parameter */
1298 if (DoRelease)
1299 Release(argv[2]);
1300 else if (DoRenew)
1301 Renew(argv[2]);
1302 else if (DoShowclassid)
1303 _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
1304 else if (DoSetclassid)
1305 _tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n"));
1306 else
1307 Usage();
1308 break;
1309 case 4: /* Process all the options that can have 2 parameters */
1310 if (DoSetclassid)
1311 _tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n"));
1312 else
1313 Usage();
1314 break;
1315 default:
1316 Usage();
1317 }
1318
1319 return 0;
1320}
static int argc
Definition: ServiceArgs.c:12
#define ConInitStdStreams()
Definition: fc.c:13
_In_ BOOLEAN Release
Definition: cdrom.h:920
#define GetProcessHeap()
Definition: compat.h:736
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
VOID Renew(LPWSTR pszAdapterName)
Definition: ipconfig.c:931
VOID RegisterDns(VOID)
Definition: ipconfig.c:1040
VOID FlushDns(VOID)
Definition: ipconfig.c:1024
HINSTANCE hInstance
Definition: ipconfig.c:42
VOID DisplayDns(VOID)
Definition: ipconfig.c:1176
#define argv
Definition: mplay32.c:18
#define GetModuleHandle
Definition: winbase.h:3827
#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 42 of file ipconfig.c.

Referenced by wmain().

◆ ProcessHeap

HANDLE ProcessHeap
  • Internal Headers *‍/

Definition at line 43 of file ipconfig.c.

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

◆ TypeArray

RECORDTYPE TypeArray[]

Definition at line 45 of file ipconfig.c.

Referenced by GetRecordTypeName().