VirtualBox

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

Last change on this file since 37808 was 36184, checked in by vboxsync, 14 years ago

rework NetFlt/Adp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: VBoxNetAdpInstall.cpp 36184 2011-03-07 10:57:04Z vboxsync $ */
2/** @file
3 * NetAdpInstall - VBoxNetAdp installer command line tool
4 */
5
6/*
7 * Copyright (C) 2009 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 <stdio.h>
20
21#define VBOX_NETADP_INF L".\\VBoxNetAdp.inf"
22
23static VOID winNetCfgLogger (LPCSTR szString)
24{
25 printf("%s", szString);
26}
27
28static int VBoxNetAdpInstall()
29{
30 int r = 1;
31 VBoxNetCfgWinSetLogging(winNetCfgLogger);
32
33 HRESULT hr = CoInitialize(NULL);
34 if(hr == S_OK)
35 {
36#if 0 //ndef DEBUG_misha
37 printf("not implemented yet, please use device manager for Host-Only net interface installation.. sorry :( \n");
38#else
39 GUID guid;
40 BSTR name, errMsg;
41 printf("adding host-only interface..\n");
42 DWORD WinEr;
43 WCHAR MpInf[MAX_PATH];
44 GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL);
45 WinEr = GetLastError();
46 if(WinEr == ERROR_SUCCESS)
47 {
48 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg);
49 if(hr == S_OK)
50 {
51 ULONG ip, mask;
52 hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask);
53 if(hr == S_OK)
54 {
55 /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip,
56 * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */
57 ip = ip | (1 << 24);
58 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
59 if(hr != S_OK)
60 {
61 printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr);
62 }
63 else
64 {
65 r = 0;
66 }
67 }
68 else
69 {
70 printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr);
71 }
72 }
73 else
74 {
75 printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr);
76 }
77 }
78 else
79 {
80 printf("GetFullPathNameW failed: winEr = %d\n", WinEr);
81 }
82#endif
83
84 CoUninitialize();
85 }
86 else
87 {
88 wprintf(L"Error initializing COM (0x%x)\n", hr);
89 }
90
91 VBoxNetCfgWinSetLogging(NULL);
92
93 return r;
94}
95
96int __cdecl main(int argc, char **argv)
97{
98 return VBoxNetAdpInstall();
99}
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