[ntoskrnl/cc]
[reactos.git] / reactos / 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 == NULL)
187 return NULL;
188
189 if(RegQueryValueEx(hKey,
190 _T("Name"),
191 NULL,
192 &dwType,
193 (PBYTE)ConType,
194 &dwDataSize) != ERROR_SUCCESS)
195 {
196 ConType = NULL;
197 }
198 }
199 }
200
201 if (hKey != NULL)
202 RegCloseKey(hKey);
203
204 return ConType;
205 }
206
207
208 LPTSTR GetConnectionDescription(LPTSTR lpClass)
209 {
210 HKEY hBaseKey = NULL;
211 HKEY hClassKey = NULL;
212 LPTSTR lpKeyClass = NULL;
213 LPTSTR lpConDesc = NULL;
214 LPTSTR lpPath = NULL;
215 TCHAR szPrePath[] = _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\");
216 DWORD dwType;
217 DWORD dwDataSize;
218 INT i;
219
220 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
221 szPrePath,
222 0,
223 KEY_READ,
224 &hBaseKey) != ERROR_SUCCESS)
225 {
226 return NULL;
227 }
228
229 for (i=0; ; i++)
230 {
231 DWORD PathSize;
232 LONG Status;
233 TCHAR szName[10];
234 DWORD NameLen = 9;
235
236 if ((Status = RegEnumKeyEx(hBaseKey,
237 i,
238 szName,
239 &NameLen,
240 NULL,
241 NULL,
242 NULL,
243 NULL)) != ERROR_SUCCESS)
244 {
245 if (Status == ERROR_NO_MORE_ITEMS)
246 {
247 DoFormatMessage(Status);
248 lpConDesc = NULL;
249 goto CLEANUP;
250 }
251 else
252 continue;
253 }
254
255 PathSize = lstrlen(szPrePath) + lstrlen(szName) + 1;
256 lpPath = (LPTSTR)HeapAlloc(ProcessHeap,
257 0,
258 PathSize * sizeof(TCHAR));
259 if (lpPath == NULL)
260 goto CLEANUP;
261
262 wsprintf(lpPath, _T("%s%s"), szPrePath, szName);
263
264 //MessageBox(NULL, lpPath, NULL, 0);
265
266 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
267 lpPath,
268 0,
269 KEY_READ,
270 &hClassKey) != ERROR_SUCCESS)
271 {
272 goto CLEANUP;
273 }
274
275 HeapFree(ProcessHeap, 0, lpPath);
276 lpPath = NULL;
277
278 if(RegQueryValueEx(hClassKey,
279 _T("NetCfgInstanceId"),
280 NULL,
281 &dwType,
282 NULL,
283 &dwDataSize) == ERROR_SUCCESS)
284 {
285 lpKeyClass = (LPTSTR)HeapAlloc(ProcessHeap,
286 0,
287 dwDataSize);
288 if (lpKeyClass == NULL)
289 goto CLEANUP;
290
291 if(RegQueryValueEx(hClassKey,
292 _T("NetCfgInstanceId"),
293 NULL,
294 &dwType,
295 (PBYTE)lpKeyClass,
296 &dwDataSize) != ERROR_SUCCESS)
297 {
298 lpKeyClass = NULL;
299 HeapFree(ProcessHeap, 0, lpKeyClass);
300 continue;
301 }
302 }
303 else
304 continue;
305
306 if (!lstrcmp(lpClass, lpKeyClass))
307 {
308 HeapFree(ProcessHeap, 0, lpKeyClass);
309 lpKeyClass = NULL;
310
311 if(RegQueryValueEx(hClassKey,
312 _T("DriverDesc"),
313 NULL,
314 &dwType,
315 NULL,
316 &dwDataSize) == ERROR_SUCCESS)
317 {
318 lpConDesc = (LPTSTR)HeapAlloc(ProcessHeap,
319 0,
320 dwDataSize);
321 if (lpConDesc == NULL)
322 goto CLEANUP;
323
324 if(RegQueryValueEx(hClassKey,
325 _T("DriverDesc"),
326 NULL,
327 &dwType,
328 (PBYTE)lpConDesc,
329 &dwDataSize) != ERROR_SUCCESS)
330 {
331 lpConDesc = NULL;
332 goto CLEANUP;
333 }
334 }
335 else
336 lpConDesc = NULL;
337
338 break;
339 }
340 }
341
342 CLEANUP:
343 if (hBaseKey != NULL)
344 RegCloseKey(hBaseKey);
345 if (hClassKey != NULL)
346 RegCloseKey(hClassKey);
347 if (lpConDesc != NULL)
348 HeapFree(ProcessHeap, 0, lpPath);
349 if (lpConDesc != NULL)
350 HeapFree(ProcessHeap, 0, lpKeyClass);
351
352 return lpConDesc;
353 }
354
355
356 VOID ShowInfo(BOOL bAll)
357 {
358 PIP_ADAPTER_INFO pAdapterInfo = NULL;
359 PIP_ADAPTER_INFO pAdapter = NULL;
360 ULONG adaptOutBufLen = 0;
361 PFIXED_INFO pFixedInfo = NULL;
362 ULONG netOutBufLen = 0;
363 ULONG ret = 0;
364
365 /* call GetAdaptersInfo to obtain the adapter info */
366 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
367 if (ret == ERROR_BUFFER_OVERFLOW)
368 {
369 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
370 if (pAdapterInfo == NULL)
371 return;
372
373 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
374 if (ret != NO_ERROR)
375 {
376 DoFormatMessage(0);
377 HeapFree(ProcessHeap, 0, pAdapterInfo);
378 return;
379 }
380 }
381 else
382 {
383 if( ERROR_NO_DATA != ret )
384 {
385 DoFormatMessage(0);
386 return;
387 }
388 }
389
390 /* call GetNetworkParams to obtain the network info */
391 if(GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
392 {
393 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
394 if (pFixedInfo == NULL)
395 {
396 if (pAdapterInfo)
397 HeapFree(ProcessHeap, 0, pAdapterInfo);
398 return;
399 }
400 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
401 {
402 DoFormatMessage(0);
403 if (pAdapterInfo)
404 HeapFree(ProcessHeap, 0, pAdapterInfo);
405 HeapFree(ProcessHeap, 0, pFixedInfo);
406 return;
407 }
408 }
409 else
410 {
411 if (pAdapterInfo)
412 HeapFree(ProcessHeap, 0, pAdapterInfo);
413 DoFormatMessage(0);
414 return;
415 }
416
417 pAdapter = pAdapterInfo;
418
419 _tprintf(_T("\nReactOS IP Configuration\n\n"));
420 if (bAll)
421 {
422 _tprintf(_T("\tHost Name . . . . . . . . . . . . : %s\n"), pFixedInfo->HostName);
423 _tprintf(_T("\tPrimary DNS Suffix. . . . . . . . : \n"));
424 _tprintf(_T("\tNode Type . . . . . . . . . . . . : %s\n"), GetNodeTypeName(pFixedInfo->NodeType));
425 if (pFixedInfo->EnableRouting)
426 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : Yes\n"));
427 else
428 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : No\n"));
429 if (pAdapter && pAdapter->HaveWins)
430 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : Yes\n"));
431 else
432 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : No\n"));
433 _tprintf(_T("\tDNS Suffix Search List. . . . . . : %s\n"), pFixedInfo->DomainName);
434 }
435
436 while (pAdapter)
437 {
438 LPTSTR IntType, myConType;
439
440 IntType = GetInterfaceTypeName(pAdapter->Type);
441 myConType = GetConnectionType(pAdapter->AdapterName);
442
443 _tprintf(_T("\n%s %s: \n\n"), IntType , myConType);
444
445 if (myConType != NULL) HeapFree(ProcessHeap, 0, myConType);
446
447 /* check if the adapter is connected to the media */
448 if (_tcscmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0") == 0)
449 {
450 _tprintf(_T("\tMedia State . . . . . . . . . . . : Media disconnected\n"));
451 pAdapter = pAdapter->Next;
452 continue;
453 }
454
455 _tprintf(_T("\tConnection-specific DNS Suffix. . : %s\n"), pFixedInfo->DomainName);
456
457 if (bAll)
458 {
459 _tprintf(_T("\tDescription . . . . . . . . . . . : %s\n"), GetConnectionDescription(pAdapter->AdapterName));
460 _tprintf(_T("\tPhysical Address. . . . . . . . . : %s\n"), PrintMacAddr(pAdapter->Address));
461 if (pAdapter->DhcpEnabled)
462 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : Yes\n"));
463 else
464 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : No\n"));
465 _tprintf(_T("\tAutoconfiguration Enabled . . . . : \n"));
466 }
467
468 _tprintf(_T("\tIP Address. . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpAddress.String);
469 _tprintf(_T("\tSubnet Mask . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpMask.String);
470 if (pAdapter->GatewayList.IpAddress.String[0] != '0')
471 _tprintf(_T("\tDefault Gateway . . . . . . . . . : %s\n"), pAdapter->GatewayList.IpAddress.String);
472 else
473 _tprintf(_T("\tDefault Gateway . . . . . . . . . :\n"));
474
475 if (bAll)
476 {
477 PIP_ADDR_STRING pIPAddr;
478
479 if (pAdapter->DhcpEnabled)
480 _tprintf(_T("\tDHCP Server . . . . . . . . . . . : %s\n"), pAdapter->DhcpServer.IpAddress.String);
481
482 _tprintf(_T("\tDNS Servers . . . . . . . . . . . : "));
483 _tprintf(_T("%s\n"), pFixedInfo->DnsServerList.IpAddress.String);
484 pIPAddr = pFixedInfo->DnsServerList.Next;
485 while (pIPAddr)
486 {
487 _tprintf(_T("\t\t\t\t\t %s\n"), pIPAddr ->IpAddress.String );
488 pIPAddr = pIPAddr->Next;
489 }
490
491 if (pAdapter->HaveWins)
492 {
493 _tprintf(_T("\tPrimary WINS Server . . . . . . . : %s\n"), pAdapter->PrimaryWinsServer.IpAddress.String);
494 _tprintf(_T("\tSecondard WINS Server . . . . . . : %s\n"), pAdapter->SecondaryWinsServer.IpAddress.String);
495 }
496
497 if (pAdapter->DhcpEnabled)
498 {
499 _tprintf(_T("\tLease Obtained. . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseObtained)));
500 _tprintf(_T("\tLease Expires . . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseExpires)));
501 }
502 }
503 _tprintf(_T("\n"));
504
505 pAdapter = pAdapter->Next;
506
507 }
508
509 HeapFree(ProcessHeap, 0, pFixedInfo);
510 if (pAdapterInfo)
511 HeapFree(ProcessHeap, 0, pAdapterInfo);
512 }
513
514 VOID Release(LPTSTR Index)
515 {
516 IP_ADAPTER_INDEX_MAP AdapterInfo;
517 DWORD ret;
518 DWORD i;
519
520 /* if interface is not given, query GetInterfaceInfo */
521 if (Index == NULL)
522 {
523 PIP_INTERFACE_INFO pInfo = NULL;
524 ULONG ulOutBufLen = 0;
525
526 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
527 {
528 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
529 if (pInfo == NULL)
530 return;
531
532 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
533 {
534 for (i = 0; i < pInfo->NumAdapters; i++)
535 {
536 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
537 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
538
539 /* Call IpReleaseAddress to release the IP address on the specified adapter. */
540 if ((ret = IpReleaseAddress(&AdapterInfo)) != NO_ERROR)
541 {
542 _tprintf(_T("\nAn error occured while releasing interface %S : \n"), AdapterInfo.Name);
543 DoFormatMessage(ret);
544 }
545 }
546
547 HeapFree(ProcessHeap, 0, pInfo);
548 }
549 else
550 {
551 DoFormatMessage(0);
552 HeapFree(ProcessHeap, 0, pInfo);
553 return;
554 }
555 }
556 else
557 {
558 DoFormatMessage(0);
559 return;
560 }
561 }
562 else
563 {
564 ;
565 /* FIXME:
566 * we need to be able to release connections by name with support for globbing
567 * i.e. ipconfig /release Eth* will release all cards starting with Eth...
568 * ipconfig /release *con* will release all cards with 'con' in their name
569 */
570 }
571 }
572
573
574
575
576 VOID Renew(LPTSTR Index)
577 {
578 IP_ADAPTER_INDEX_MAP AdapterInfo;
579 DWORD i;
580
581 /* if interface is not given, query GetInterfaceInfo */
582 if (Index == NULL)
583 {
584 PIP_INTERFACE_INFO pInfo;
585 ULONG ulOutBufLen = 0;
586
587 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO));
588 if (pInfo == NULL)
589 {
590 _tprintf(_T("memory allocation error"));
591 return;
592 }
593
594 /* Make an initial call to GetInterfaceInfo to get
595 * the necessary size into the ulOutBufLen variable */
596 if ( GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
597 {
598 HeapFree(ProcessHeap, 0, pInfo);
599 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
600 if (pInfo == NULL)
601 {
602 _tprintf(_T("memory allocation error"));
603 return;
604 }
605 }
606
607 /* Make a second call to GetInterfaceInfo to get the actual data we want */
608 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
609 {
610 for (i = 0; i < pInfo->NumAdapters; i++)
611 {
612 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
613 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
614
615
616 /* Call IpRenewAddress to renew the IP address on the specified adapter. */
617 if (IpRenewAddress(&AdapterInfo) != NO_ERROR)
618 {
619 _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*"));
620 DoFormatMessage(0);
621 }
622 }
623 }
624 else
625 {
626 _tprintf(_T("\nGetInterfaceInfo failed : "));
627 DoFormatMessage(0);
628 }
629
630 HeapFree(ProcessHeap, 0, pInfo);
631 }
632 else
633 {
634 ;
635 /* FIXME:
636 * we need to be able to renew connections by name with support for globbing
637 * i.e. ipconfig /renew Eth* will renew all cards starting with Eth...
638 * ipconfig /renew *con* will renew all cards with 'con' in their name
639 */
640 }
641 }
642
643
644
645 VOID Usage(VOID)
646 {
647 HRSRC hRes;
648 LPTSTR lpUsage;
649 DWORD Size;
650
651 LPTSTR lpName = (LPTSTR)MAKEINTRESOURCE((IDS_USAGE >> 4) + 1);
652
653 hRes = FindResource(hInstance,
654 lpName,
655 RT_STRING);
656 if (hRes != NULL)
657 {
658 if ((Size = SizeofResource(hInstance,
659 hRes)))
660 {
661 lpUsage = (LPTSTR)HeapAlloc(ProcessHeap,
662 0,
663 Size);
664 if (lpUsage == NULL)
665 return;
666
667 if (LoadString(hInstance,
668 IDS_USAGE,
669 lpUsage,
670 Size))
671 {
672 _tprintf(_T("%s"), lpUsage);
673 }
674 }
675 }
676
677
678 }
679
680 int main(int argc, char *argv[])
681 {
682 BOOL DoUsage=FALSE;
683 BOOL DoAll=FALSE;
684 BOOL DoRelease=FALSE;
685 BOOL DoRenew=FALSE;
686 BOOL DoFlushdns=FALSE;
687 BOOL DoRegisterdns=FALSE;
688 BOOL DoDisplaydns=FALSE;
689 BOOL DoShowclassid=FALSE;
690 BOOL DoSetclassid=FALSE;
691
692 hInstance = GetModuleHandle(NULL);
693 ProcessHeap = GetProcessHeap();
694
695 /* Parse command line for options we have been given. */
696 if ( (argc > 1)&&(argv[1][0]=='/') )
697 {
698 if( !_tcsicmp( &argv[1][1], _T("?") ))
699 {
700 DoUsage = TRUE;
701 }
702 else if( !_tcsnicmp( &argv[1][1], _T("ALL"), _tcslen(&argv[1][1]) ))
703 {
704 DoAll = TRUE;
705 }
706 else if( !_tcsnicmp( &argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1]) ))
707 {
708 DoRelease = TRUE;
709 }
710 else if( ! _tcsnicmp( &argv[1][1], _T("RENEW"), _tcslen(&argv[1][1]) ))
711 {
712 DoRenew = TRUE;
713 }
714 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1]) ))
715 {
716 DoFlushdns = TRUE;
717 }
718 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHREGISTERDNS"), _tcslen(&argv[1][1]) ))
719 {
720 DoRegisterdns = TRUE;
721 }
722 else if( ! _tcsnicmp( &argv[1][1], _T("DISPLAYDNS"), _tcslen(&argv[1][1]) ))
723 {
724 DoDisplaydns = TRUE;
725 }
726 else if( ! _tcsnicmp( &argv[1][1], _T("SHOWCLASSID"), _tcslen(&argv[1][1]) ))
727 {
728 DoShowclassid = TRUE;
729 }
730 else if( ! _tcsnicmp( &argv[1][1], _T("SETCLASSID"), _tcslen(&argv[1][1]) ))
731 {
732 DoSetclassid = TRUE;
733 }
734 }
735
736 switch (argc)
737 {
738 case 1: /* Default behaviour if no options are given*/
739 ShowInfo(FALSE);
740 break;
741 case 2: /* Process all the options that take no parameters */
742 if (DoUsage)
743 Usage();
744 else if (DoAll)
745 ShowInfo(TRUE);
746 else if (DoRelease)
747 Release(NULL);
748 else if (DoRenew)
749 Renew(NULL);
750 else if (DoFlushdns)
751 _tprintf(_T("\nSorry /flushdns is not implemented yet\n"));
752 else if (DoRegisterdns)
753 _tprintf(_T("\nSorry /registerdns is not implemented yet\n"));
754 else if (DoDisplaydns)
755 _tprintf(_T("\nSorry /displaydns is not implemented yet\n"));
756 else
757 Usage();
758 break;
759 case 3: /* Process all the options that can have 1 parameter */
760 if (DoRelease)
761 _tprintf(_T("\nSorry /release [adapter] is not implemented yet\n"));
762 //Release(argv[2]);
763 else if (DoRenew)
764 _tprintf(_T("\nSorry /renew [adapter] is not implemented yet\n"));
765 else if (DoShowclassid)
766 _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
767 else if (DoSetclassid)
768 _tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n"));
769 else
770 Usage();
771 break;
772 case 4: /* Process all the options that can have 2 parameters */
773 if (DoSetclassid)
774 _tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n"));
775 else
776 Usage();
777 break;
778 default:
779 Usage();
780 }
781
782 return 0;
783 }
784