Sync to trunk (r46918)
[reactos.git] / base / applications / network / ipconfig / ipconfig.c
1 /*
2 * PROJECT: ReactOS ipconfig utility
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: apps/utils/net/ipconfig/ipconfig.c
5 * PURPOSE: Display IP info for net adapters
6 * PROGRAMMERS: Copyright 2005 - 2006 Ged Murphy (gedmurphy@gmail.com)
7 */
8 /*
9 * TODO:
10 * fix renew / release
11 * implement flushdns, registerdns, displaydns, showclassid, setclassid
12 * allow globbing on adapter names
13 */
14
15 #define WIN32_LEAN_AND_MEAN
16 #include <windows.h>
17 #include <stdio.h>
18 #include <tchar.h>
19 #include <time.h>
20 #include <iphlpapi.h>
21 #include "resource.h"
22
23 #define GUID_LEN 40
24
25 HINSTANCE hInstance;
26 HANDLE ProcessHeap;
27
28
29 LPTSTR GetNodeTypeName(UINT NodeType)
30 {
31 static TCHAR szNode[14];
32
33 switch (NodeType)
34 {
35 case 1:
36 if (!LoadString(hInstance, IDS_BCAST, szNode, sizeof(szNode)))
37 return NULL;
38 break;
39
40 case 2:
41 if (!LoadString(hInstance, IDS_P2P, szNode, sizeof(szNode)))
42 return NULL;
43 break;
44
45 case 4:
46 if (!LoadString(hInstance, IDS_MIXED, szNode, sizeof(szNode)))
47 return NULL;
48 break;
49
50 case 8:
51 if (!LoadString(hInstance, IDS_HYBRID, szNode, sizeof(szNode)))
52 return NULL;
53 break;
54
55 default :
56 if (!LoadString(hInstance, IDS_UNKNOWN, szNode, sizeof(szNode)))
57 return NULL;
58 break;
59 }
60
61 return szNode;
62 }
63
64
65 LPTSTR GetInterfaceTypeName(UINT InterfaceType)
66 {
67 static TCHAR szIntType[25];
68
69 switch (InterfaceType)
70 {
71 case MIB_IF_TYPE_OTHER:
72 if (!LoadString(hInstance, IDS_OTHER, szIntType, sizeof(szIntType)))
73 return NULL;
74 break;
75
76 case MIB_IF_TYPE_ETHERNET:
77 if (!LoadString(hInstance, IDS_ETH, szIntType, sizeof(szIntType)))
78 return NULL;
79 break;
80
81 case MIB_IF_TYPE_TOKENRING:
82 if (!LoadString(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType)))
83 return NULL;
84 break;
85
86 case MIB_IF_TYPE_FDDI:
87 if (!LoadString(hInstance, IDS_FDDI, szIntType, sizeof(szIntType)))
88 return NULL;
89 break;
90
91 case MIB_IF_TYPE_PPP:
92 if (!LoadString(hInstance, IDS_PPP, szIntType, sizeof(szIntType)))
93 return NULL;
94 break;
95
96 case MIB_IF_TYPE_LOOPBACK:
97 if (!LoadString(hInstance, IDS_LOOP, szIntType, sizeof(szIntType)))
98 return NULL;
99 break;
100
101 case MIB_IF_TYPE_SLIP:
102 if (!LoadString(hInstance, IDS_SLIP, szIntType, sizeof(szIntType)))
103 return NULL;
104 break;
105
106 default:
107 if (!LoadString(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType)))
108 return NULL;
109 break;
110 }
111
112 return szIntType;
113 }
114
115
116 /* print MAC address */
117 PTCHAR PrintMacAddr(PBYTE Mac)
118 {
119 static TCHAR MacAddr[20];
120
121 _stprintf(MacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"),
122 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
123
124 return MacAddr;
125 }
126
127
128 VOID DoFormatMessage(LONG ErrorCode)
129 {
130 LPVOID lpMsgBuf;
131 //DWORD ErrorCode;
132
133 if (ErrorCode == 0)
134 ErrorCode = GetLastError();
135
136 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
137 FORMAT_MESSAGE_FROM_SYSTEM |
138 FORMAT_MESSAGE_IGNORE_INSERTS,
139 NULL,
140 ErrorCode,
141 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
142 (LPTSTR) &lpMsgBuf,
143 0,
144 NULL))
145 {
146 _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
147 LocalFree(lpMsgBuf);
148 }
149 }
150
151
152 LPTSTR GetConnectionType(LPTSTR lpClass)
153 {
154 HKEY hKey = NULL;
155 LPTSTR ConType = NULL;
156 TCHAR Path[256];
157 LPTSTR PrePath = _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\");
158 LPTSTR PostPath = _T("\\Connection");
159 DWORD PathSize;
160 DWORD dwType;
161 DWORD dwDataSize;
162
163 /* don't overflow the buffer */
164 PathSize = lstrlen(PrePath) + lstrlen(lpClass) + lstrlen(PostPath) + 1;
165 if (PathSize >= 255)
166 return NULL;
167
168 wsprintf(Path, _T("%s%s%s"), PrePath, lpClass, PostPath);
169
170 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
171 Path,
172 0,
173 KEY_READ,
174 &hKey) == ERROR_SUCCESS)
175 {
176 if(RegQueryValueEx(hKey,
177 _T("Name"),
178 NULL,
179 &dwType,
180 NULL,
181 &dwDataSize) == ERROR_SUCCESS)
182 {
183 ConType = (LPTSTR)HeapAlloc(ProcessHeap,
184 0,
185 dwDataSize);
186 if (ConType)
187 {
188 if(RegQueryValueEx(hKey,
189 _T("Name"),
190 NULL,
191 &dwType,
192 (PBYTE)ConType,
193 &dwDataSize) != ERROR_SUCCESS)
194 {
195 HeapFree(ProcessHeap,
196 0,
197 ConType);
198
199 ConType = NULL;
200 }
201 }
202 }
203 }
204
205 if (hKey != NULL)
206 RegCloseKey(hKey);
207
208 return ConType;
209 }
210
211
212 LPTSTR GetConnectionDescription(LPTSTR lpClass)
213 {
214 HKEY hBaseKey = NULL;
215 HKEY hClassKey = NULL;
216 LPTSTR lpKeyClass = NULL;
217 LPTSTR lpConDesc = NULL;
218 LPTSTR lpPath = NULL;
219 TCHAR szPrePath[] = _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\");
220 DWORD dwType;
221 DWORD dwDataSize;
222 INT i;
223
224 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
225 szPrePath,
226 0,
227 KEY_READ,
228 &hBaseKey) != ERROR_SUCCESS)
229 {
230 return NULL;
231 }
232
233 for (i=0; ; i++)
234 {
235 DWORD PathSize;
236 LONG Status;
237 TCHAR szName[10];
238 DWORD NameLen = 9;
239
240 if ((Status = RegEnumKeyEx(hBaseKey,
241 i,
242 szName,
243 &NameLen,
244 NULL,
245 NULL,
246 NULL,
247 NULL)) != ERROR_SUCCESS)
248 {
249 if (Status == ERROR_NO_MORE_ITEMS)
250 {
251 DoFormatMessage(Status);
252 lpConDesc = NULL;
253 goto CLEANUP;
254 }
255 else
256 continue;
257 }
258
259 PathSize = lstrlen(szPrePath) + lstrlen(szName) + 1;
260 lpPath = (LPTSTR)HeapAlloc(ProcessHeap,
261 0,
262 PathSize * sizeof(TCHAR));
263 if (lpPath == NULL)
264 goto CLEANUP;
265
266 wsprintf(lpPath, _T("%s%s"), szPrePath, szName);
267
268 //MessageBox(NULL, lpPath, NULL, 0);
269
270 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
271 lpPath,
272 0,
273 KEY_READ,
274 &hClassKey) != ERROR_SUCCESS)
275 {
276 goto CLEANUP;
277 }
278
279 HeapFree(ProcessHeap, 0, lpPath);
280 lpPath = NULL;
281
282 if(RegQueryValueEx(hClassKey,
283 _T("NetCfgInstanceId"),
284 NULL,
285 &dwType,
286 NULL,
287 &dwDataSize) == ERROR_SUCCESS)
288 {
289 lpKeyClass = (LPTSTR)HeapAlloc(ProcessHeap,
290 0,
291 dwDataSize);
292 if (lpKeyClass == NULL)
293 goto CLEANUP;
294
295 if(RegQueryValueEx(hClassKey,
296 _T("NetCfgInstanceId"),
297 NULL,
298 &dwType,
299 (PBYTE)lpKeyClass,
300 &dwDataSize) != ERROR_SUCCESS)
301 {
302 lpKeyClass = NULL;
303 HeapFree(ProcessHeap, 0, lpKeyClass);
304 continue;
305 }
306 }
307 else
308 continue;
309
310 if (!lstrcmp(lpClass, lpKeyClass))
311 {
312 HeapFree(ProcessHeap, 0, lpKeyClass);
313 lpKeyClass = NULL;
314
315 if(RegQueryValueEx(hClassKey,
316 _T("DriverDesc"),
317 NULL,
318 &dwType,
319 NULL,
320 &dwDataSize) == ERROR_SUCCESS)
321 {
322 lpConDesc = (LPTSTR)HeapAlloc(ProcessHeap,
323 0,
324 dwDataSize);
325 if (lpConDesc == NULL)
326 goto CLEANUP;
327
328 if(RegQueryValueEx(hClassKey,
329 _T("DriverDesc"),
330 NULL,
331 &dwType,
332 (PBYTE)lpConDesc,
333 &dwDataSize) != ERROR_SUCCESS)
334 {
335 lpConDesc = NULL;
336 goto CLEANUP;
337 }
338 }
339 else
340 lpConDesc = NULL;
341
342 break;
343 }
344 }
345
346 CLEANUP:
347 if (hBaseKey != NULL)
348 RegCloseKey(hBaseKey);
349 if (hClassKey != NULL)
350 RegCloseKey(hClassKey);
351 if (lpConDesc != NULL)
352 HeapFree(ProcessHeap, 0, lpPath);
353 if (lpConDesc != NULL)
354 HeapFree(ProcessHeap, 0, lpKeyClass);
355
356 return lpConDesc;
357 }
358
359
360 VOID ShowInfo(BOOL bAll)
361 {
362 PIP_ADAPTER_INFO pAdapterInfo = NULL;
363 PIP_ADAPTER_INFO pAdapter = NULL;
364 ULONG adaptOutBufLen = 0;
365 PFIXED_INFO pFixedInfo = NULL;
366 ULONG netOutBufLen = 0;
367 ULONG ret = 0;
368
369 /* call GetAdaptersInfo to obtain the adapter info */
370 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
371 if (ret == ERROR_BUFFER_OVERFLOW)
372 {
373 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
374 if (pAdapterInfo == NULL)
375 return;
376
377 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
378 if (ret != NO_ERROR)
379 {
380 DoFormatMessage(0);
381 HeapFree(ProcessHeap, 0, pAdapterInfo);
382 return;
383 }
384 }
385 else
386 {
387 if( ERROR_NO_DATA != ret )
388 {
389 DoFormatMessage(0);
390 return;
391 }
392 }
393
394 /* call GetNetworkParams to obtain the network info */
395 if(GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
396 {
397 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
398 if (pFixedInfo == NULL)
399 {
400 if (pAdapterInfo)
401 HeapFree(ProcessHeap, 0, pAdapterInfo);
402 return;
403 }
404 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
405 {
406 DoFormatMessage(0);
407 if (pAdapterInfo)
408 HeapFree(ProcessHeap, 0, pAdapterInfo);
409 HeapFree(ProcessHeap, 0, pFixedInfo);
410 return;
411 }
412 }
413 else
414 {
415 if (pAdapterInfo)
416 HeapFree(ProcessHeap, 0, pAdapterInfo);
417 DoFormatMessage(0);
418 return;
419 }
420
421 pAdapter = pAdapterInfo;
422
423 _tprintf(_T("\nReactOS IP Configuration\n\n"));
424 if (bAll)
425 {
426 _tprintf(_T("\tHost Name . . . . . . . . . . . . : %s\n"), pFixedInfo->HostName);
427 _tprintf(_T("\tPrimary DNS Suffix. . . . . . . . : \n"));
428 _tprintf(_T("\tNode Type . . . . . . . . . . . . : %s\n"), GetNodeTypeName(pFixedInfo->NodeType));
429 if (pFixedInfo->EnableRouting)
430 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : Yes\n"));
431 else
432 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : No\n"));
433 if (pAdapter && pAdapter->HaveWins)
434 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : Yes\n"));
435 else
436 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : No\n"));
437 _tprintf(_T("\tDNS Suffix Search List. . . . . . : %s\n"), pFixedInfo->DomainName);
438 }
439
440 while (pAdapter)
441 {
442 LPTSTR IntType, myConType;
443
444 IntType = GetInterfaceTypeName(pAdapter->Type);
445 myConType = GetConnectionType(pAdapter->AdapterName);
446
447 _tprintf(_T("\n%s %s: \n\n"), IntType , myConType);
448
449 if (myConType != NULL) HeapFree(ProcessHeap, 0, myConType);
450
451 /* check if the adapter is connected to the media */
452 if (_tcscmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0") == 0)
453 {
454 _tprintf(_T("\tMedia State . . . . . . . . . . . : Media disconnected\n"));
455 pAdapter = pAdapter->Next;
456 continue;
457 }
458
459 _tprintf(_T("\tConnection-specific DNS Suffix. . : %s\n"), pFixedInfo->DomainName);
460
461 if (bAll)
462 {
463 LPTSTR lpDesc = GetConnectionDescription(pAdapter->AdapterName);
464 _tprintf(_T("\tDescription . . . . . . . . . . . : %s\n"), lpDesc);
465 HeapFree(ProcessHeap, 0, lpDesc);
466 _tprintf(_T("\tPhysical Address. . . . . . . . . : %s\n"), PrintMacAddr(pAdapter->Address));
467 if (pAdapter->DhcpEnabled)
468 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : Yes\n"));
469 else
470 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : No\n"));
471 _tprintf(_T("\tAutoconfiguration Enabled . . . . : \n"));
472 }
473
474 _tprintf(_T("\tIP Address. . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpAddress.String);
475 _tprintf(_T("\tSubnet Mask . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpMask.String);
476 if (pAdapter->GatewayList.IpAddress.String[0] != '0')
477 _tprintf(_T("\tDefault Gateway . . . . . . . . . : %s\n"), pAdapter->GatewayList.IpAddress.String);
478 else
479 _tprintf(_T("\tDefault Gateway . . . . . . . . . :\n"));
480
481 if (bAll)
482 {
483 PIP_ADDR_STRING pIPAddr;
484
485 if (pAdapter->DhcpEnabled)
486 _tprintf(_T("\tDHCP Server . . . . . . . . . . . : %s\n"), pAdapter->DhcpServer.IpAddress.String);
487
488 _tprintf(_T("\tDNS Servers . . . . . . . . . . . : "));
489 _tprintf(_T("%s\n"), pFixedInfo->DnsServerList.IpAddress.String);
490 pIPAddr = pFixedInfo->DnsServerList.Next;
491 while (pIPAddr)
492 {
493 _tprintf(_T("\t\t\t\t\t %s\n"), pIPAddr ->IpAddress.String );
494 pIPAddr = pIPAddr->Next;
495 }
496
497 if (pAdapter->HaveWins)
498 {
499 _tprintf(_T("\tPrimary WINS Server . . . . . . . : %s\n"), pAdapter->PrimaryWinsServer.IpAddress.String);
500 _tprintf(_T("\tSecondard WINS Server . . . . . . : %s\n"), pAdapter->SecondaryWinsServer.IpAddress.String);
501 }
502
503 if (pAdapter->DhcpEnabled)
504 {
505 _tprintf(_T("\tLease Obtained. . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseObtained)));
506 _tprintf(_T("\tLease Expires . . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseExpires)));
507 }
508 }
509 _tprintf(_T("\n"));
510
511 pAdapter = pAdapter->Next;
512
513 }
514
515 HeapFree(ProcessHeap, 0, pFixedInfo);
516 if (pAdapterInfo)
517 HeapFree(ProcessHeap, 0, pAdapterInfo);
518 }
519
520 VOID Release(LPTSTR Index)
521 {
522 IP_ADAPTER_INDEX_MAP AdapterInfo;
523 DWORD ret;
524 DWORD i;
525
526 /* if interface is not given, query GetInterfaceInfo */
527 if (Index == NULL)
528 {
529 PIP_INTERFACE_INFO pInfo = NULL;
530 ULONG ulOutBufLen = 0;
531
532 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
533 {
534 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
535 if (pInfo == NULL)
536 return;
537
538 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
539 {
540 for (i = 0; i < pInfo->NumAdapters; i++)
541 {
542 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
543 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
544
545 /* Call IpReleaseAddress to release the IP address on the specified adapter. */
546 if ((ret = IpReleaseAddress(&AdapterInfo)) != NO_ERROR)
547 {
548 _tprintf(_T("\nAn error occured while releasing interface %S : \n"), AdapterInfo.Name);
549 DoFormatMessage(ret);
550 }
551 }
552
553 HeapFree(ProcessHeap, 0, pInfo);
554 }
555 else
556 {
557 DoFormatMessage(0);
558 HeapFree(ProcessHeap, 0, pInfo);
559 return;
560 }
561 }
562 else
563 {
564 DoFormatMessage(0);
565 return;
566 }
567 }
568 else
569 {
570 ;
571 /* FIXME:
572 * we need to be able to release connections by name with support for globbing
573 * i.e. ipconfig /release Eth* will release all cards starting with Eth...
574 * ipconfig /release *con* will release all cards with 'con' in their name
575 */
576 }
577 }
578
579
580
581
582 VOID Renew(LPTSTR Index)
583 {
584 IP_ADAPTER_INDEX_MAP AdapterInfo;
585 DWORD i;
586
587 /* if interface is not given, query GetInterfaceInfo */
588 if (Index == NULL)
589 {
590 PIP_INTERFACE_INFO pInfo;
591 ULONG ulOutBufLen = 0;
592
593 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO));
594 if (pInfo == NULL)
595 {
596 _tprintf(_T("memory allocation error"));
597 return;
598 }
599
600 /* Make an initial call to GetInterfaceInfo to get
601 * the necessary size into the ulOutBufLen variable */
602 if ( GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
603 {
604 HeapFree(ProcessHeap, 0, pInfo);
605 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
606 if (pInfo == NULL)
607 {
608 _tprintf(_T("memory allocation error"));
609 return;
610 }
611 }
612
613 /* Make a second call to GetInterfaceInfo to get the actual data we want */
614 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
615 {
616 for (i = 0; i < pInfo->NumAdapters; i++)
617 {
618 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
619 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
620
621
622 /* Call IpRenewAddress to renew the IP address on the specified adapter. */
623 if (IpRenewAddress(&AdapterInfo) != NO_ERROR)
624 {
625 _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*"));
626 DoFormatMessage(0);
627 }
628 }
629 }
630 else
631 {
632 _tprintf(_T("\nGetInterfaceInfo failed : "));
633 DoFormatMessage(0);
634 }
635
636 HeapFree(ProcessHeap, 0, pInfo);
637 }
638 else
639 {
640 ;
641 /* FIXME:
642 * we need to be able to renew connections by name with support for globbing
643 * i.e. ipconfig /renew Eth* will renew all cards starting with Eth...
644 * ipconfig /renew *con* will renew all cards with 'con' in their name
645 */
646 }
647 }
648
649
650
651 VOID Usage(VOID)
652 {
653 HRSRC hRes;
654 LPTSTR lpUsage;
655 DWORD Size;
656
657 LPTSTR lpName = (LPTSTR)MAKEINTRESOURCE((IDS_USAGE >> 4) + 1);
658
659 hRes = FindResource(hInstance,
660 lpName,
661 RT_STRING);
662 if (hRes != NULL)
663 {
664 if ((Size = SizeofResource(hInstance,
665 hRes)))
666 {
667 lpUsage = (LPTSTR)HeapAlloc(ProcessHeap,
668 0,
669 Size);
670 if (lpUsage == NULL)
671 return;
672
673 if (LoadString(hInstance,
674 IDS_USAGE,
675 lpUsage,
676 Size))
677 {
678 _tprintf(_T("%s"), lpUsage);
679 }
680 }
681 }
682
683
684 }
685
686 int main(int argc, char *argv[])
687 {
688 BOOL DoUsage=FALSE;
689 BOOL DoAll=FALSE;
690 BOOL DoRelease=FALSE;
691 BOOL DoRenew=FALSE;
692 BOOL DoFlushdns=FALSE;
693 BOOL DoRegisterdns=FALSE;
694 BOOL DoDisplaydns=FALSE;
695 BOOL DoShowclassid=FALSE;
696 BOOL DoSetclassid=FALSE;
697
698 hInstance = GetModuleHandle(NULL);
699 ProcessHeap = GetProcessHeap();
700
701 /* Parse command line for options we have been given. */
702 if ( (argc > 1)&&(argv[1][0]=='/' || argv[1][0]=='-') )
703 {
704 if( !_tcsicmp( &argv[1][1], _T("?") ))
705 {
706 DoUsage = TRUE;
707 }
708 else if( !_tcsnicmp( &argv[1][1], _T("ALL"), _tcslen(&argv[1][1]) ))
709 {
710 DoAll = TRUE;
711 }
712 else if( !_tcsnicmp( &argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1]) ))
713 {
714 DoRelease = TRUE;
715 }
716 else if( ! _tcsnicmp( &argv[1][1], _T("RENEW"), _tcslen(&argv[1][1]) ))
717 {
718 DoRenew = TRUE;
719 }
720 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1]) ))
721 {
722 DoFlushdns = TRUE;
723 }
724 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHREGISTERDNS"), _tcslen(&argv[1][1]) ))
725 {
726 DoRegisterdns = TRUE;
727 }
728 else if( ! _tcsnicmp( &argv[1][1], _T("DISPLAYDNS"), _tcslen(&argv[1][1]) ))
729 {
730 DoDisplaydns = TRUE;
731 }
732 else if( ! _tcsnicmp( &argv[1][1], _T("SHOWCLASSID"), _tcslen(&argv[1][1]) ))
733 {
734 DoShowclassid = TRUE;
735 }
736 else if( ! _tcsnicmp( &argv[1][1], _T("SETCLASSID"), _tcslen(&argv[1][1]) ))
737 {
738 DoSetclassid = TRUE;
739 }
740 }
741
742 switch (argc)
743 {
744 case 1: /* Default behaviour if no options are given*/
745 ShowInfo(FALSE);
746 break;
747 case 2: /* Process all the options that take no parameters */
748 if (DoUsage)
749 Usage();
750 else if (DoAll)
751 ShowInfo(TRUE);
752 else if (DoRelease)
753 Release(NULL);
754 else if (DoRenew)
755 Renew(NULL);
756 else if (DoFlushdns)
757 _tprintf(_T("\nSorry /flushdns is not implemented yet\n"));
758 else if (DoRegisterdns)
759 _tprintf(_T("\nSorry /registerdns is not implemented yet\n"));
760 else if (DoDisplaydns)
761 _tprintf(_T("\nSorry /displaydns is not implemented yet\n"));
762 else
763 Usage();
764 break;
765 case 3: /* Process all the options that can have 1 parameter */
766 if (DoRelease)
767 _tprintf(_T("\nSorry /release [adapter] is not implemented yet\n"));
768 //Release(argv[2]);
769 else if (DoRenew)
770 _tprintf(_T("\nSorry /renew [adapter] is not implemented yet\n"));
771 else if (DoShowclassid)
772 _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
773 else if (DoSetclassid)
774 _tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n"));
775 else
776 Usage();
777 break;
778 case 4: /* Process all the options that can have 2 parameters */
779 if (DoSetclassid)
780 _tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n"));
781 else
782 Usage();
783 break;
784 default:
785 Usage();
786 }
787
788 return 0;
789 }
790