VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp@ 52134

Last change on this file since 52134 was 52134, checked in by vboxsync, 10 years ago

NDIS6: Cumulative commit containing async send, unload race fix (intnet), missing offload fix, basic vboxnetadp6.sys (#7231)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: VBoxNetAdpInstall.cpp 52134 2014-07-22 17:39:46Z vboxsync $ */
2/** @file
3 * NetAdpInstall - VBoxNetAdp installer command line tool.
4 */
5
6/*
7 * Copyright (C) 2009-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <VBox/VBoxNetCfg-win.h>
19#include <VBox/VBoxDrvCfg-win.h>
20#include <stdio.h>
21
22#include <devguid.h>
23
24#ifdef NDIS60
25#define VBOX_NETADP_INF L"VBoxNetAdp6.inf"
26#else /* !NDIS60 */
27#define VBOX_NETADP_INF L"VBoxNetAdp.inf"
28#endif /* !NDIS60 */
29
30static VOID winNetCfgLogger(LPCSTR szString)
31{
32 printf("%s\n", szString);
33}
34
35static int VBoxNetAdpInstall(void)
36{
37 VBoxNetCfgWinSetLogging(winNetCfgLogger);
38
39 HRESULT hr = CoInitialize(NULL);
40 if (SUCCEEDED(hr))
41 {
42 printf("adding host-only interface..\n");
43
44 DWORD dwErr = ERROR_SUCCESS;
45 WCHAR MpInf[MAX_PATH];
46
47 if (!GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL))
48 dwErr = GetLastError();
49
50 if (dwErr == ERROR_SUCCESS)
51 {
52 GUID guid;
53 BSTR name, errMsg;
54
55 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg);
56 if (SUCCEEDED(hr))
57 {
58 ULONG ip, mask;
59 hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask);
60 if (SUCCEEDED(hr))
61 {
62 /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip,
63 * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */
64 ip = ip | (1 << 24);
65 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
66 if (SUCCEEDED(hr))
67 {
68 printf("installation successful\n");
69 }
70 else
71 printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr);
72 }
73 else
74 printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr);
75 }
76 else
77 printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr);
78 }
79 else
80 {
81 printf("GetFullPathNameW failed: winEr = %d\n", dwErr);
82 hr = HRESULT_FROM_WIN32(dwErr);
83
84 }
85 CoUninitialize();
86 }
87 else
88 printf("Error initializing COM (0x%x)\n", hr);
89
90 VBoxNetCfgWinSetLogging(NULL);
91
92 return SUCCEEDED(hr) ? 0 : 1;
93}
94
95static int VBoxNetAdpUninstall(void)
96{
97 VBoxNetCfgWinSetLogging(winNetCfgLogger);
98
99 printf("uninstalling all host-only interfaces..\n");
100
101 HRESULT hr = CoInitialize(NULL);
102 if (SUCCEEDED(hr))
103 {
104 hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(L"sun_VBoxNetAdp");
105 if (SUCCEEDED(hr))
106 {
107 hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", L"sun_VBoxNetAdp", 0/* could be SUOI_FORCEDELETE */);
108 if (SUCCEEDED(hr))
109 {
110 printf("uninstallation successful\n");
111 }
112 else
113 printf("uninstalled successfully, but failed to remove infs\n");
114 }
115 else
116 printf("uninstall failed, hr = 0x%x\n", hr);
117 CoUninitialize();
118 }
119 else
120 printf("Error initializing COM (0x%x)\n", hr);
121
122 VBoxNetCfgWinSetLogging(NULL);
123
124 return SUCCEEDED(hr) ? 0 : 1;
125}
126
127static int VBoxNetAdpUpdate(void)
128{
129 VBoxNetCfgWinSetLogging(winNetCfgLogger);
130
131 printf("uninstalling all host-only interfaces..\n");
132
133 HRESULT hr = CoInitialize(NULL);
134 if (SUCCEEDED(hr))
135 {
136 BOOL fRebootRequired = FALSE;
137 hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(VBOX_NETADP_INF, &fRebootRequired);
138 if (SUCCEEDED(hr))
139 {
140 if (fRebootRequired)
141 printf("!!REBOOT REQUIRED!!\n");
142 printf("updated successfully\n");
143 }
144 else
145 printf("update failed, hr = 0x%x\n", hr);
146
147 CoUninitialize();
148 }
149 else
150 printf("Error initializing COM (0x%x)\n", hr);
151
152 VBoxNetCfgWinSetLogging(NULL);
153
154 return SUCCEEDED(hr) ? 0 : 1;
155}
156
157static int VBoxNetAdpDisable(void)
158{
159 VBoxNetCfgWinSetLogging(winNetCfgLogger);
160
161 printf("disabling all host-only interfaces..\n");
162
163 HRESULT hr = CoInitialize(NULL);
164 if (SUCCEEDED(hr))
165 {
166 hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(L"sun_VBoxNetAdp", VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
167 if (SUCCEEDED(hr))
168 {
169 printf("disabling successful\n");
170 }
171 else
172 printf("disable failed, hr = 0x%x\n", hr);
173
174 CoUninitialize();
175 }
176 else
177 printf("Error initializing COM (0x%x)\n", hr);
178
179 VBoxNetCfgWinSetLogging(NULL);
180
181 return SUCCEEDED(hr) ? 0 : 1;
182}
183
184static int VBoxNetAdpEnable(void)
185{
186 VBoxNetCfgWinSetLogging(winNetCfgLogger);
187
188 printf("enabling all host-only interfaces..\n");
189
190 HRESULT hr = CoInitialize(NULL);
191 if (SUCCEEDED(hr))
192 {
193 hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(L"sun_VBoxNetAdp", VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE);
194 if (SUCCEEDED(hr))
195 {
196 printf("enabling successful\n");
197 }
198 else
199 printf("enabling failed, hr = 0x%x\n", hr);
200
201 CoUninitialize();
202 }
203 else
204 printf("Error initializing COM (0x%x)\n", hr);
205
206 VBoxNetCfgWinSetLogging(NULL);
207
208 return SUCCEEDED(hr) ? 0 : 1;
209}
210
211static void printUsage(void)
212{
213 printf("host-only network adapter configuration tool\n"
214 " Usage: VBoxNetAdpInstall [cmd]\n"
215 " cmd can be one of the following values:\n"
216 " i - install a new host-only interface (default command)\n"
217 " u - uninstall all host-only interfaces\n"
218 " a - update the host-only driver\n"
219 " d - disable all host-only interfaces\n"
220 " e - enable all host-only interfaces\n"
221 " h - print this message\n");
222}
223
224int __cdecl main(int argc, char **argv)
225{
226 if (argc < 2)
227 return VBoxNetAdpInstall();
228 if (argc > 2)
229 {
230 printUsage();
231 return 1;
232 }
233
234 if (!strcmp(argv[1], "i"))
235 return VBoxNetAdpInstall();
236 if (!strcmp(argv[1], "u"))
237 return VBoxNetAdpUninstall();
238 if (!strcmp(argv[1], "a"))
239 return VBoxNetAdpUpdate();
240 if (!strcmp(argv[1], "d"))
241 return VBoxNetAdpDisable();
242 if (!strcmp(argv[1], "e"))
243 return VBoxNetAdpEnable();
244
245 printUsage();
246 return !strcmp(argv[1], "h");
247}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette