1 | /* $Id: NetIf-generic.cpp 17997 2009-03-17 07:56:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - Generic NetIf implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include <VBox/err.h>
|
---|
23 | #include <VBox/log.h>
|
---|
24 | #include <iprt/process.h>
|
---|
25 | #include <iprt/env.h>
|
---|
26 | #include <iprt/path.h>
|
---|
27 | #include <iprt/param.h>
|
---|
28 |
|
---|
29 | #include "HostNetworkInterfaceImpl.h"
|
---|
30 | #include "netif.h"
|
---|
31 |
|
---|
32 | #define VBOXNETADPCTL_NAME "VBoxNetAdpCtl"
|
---|
33 |
|
---|
34 | static int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const char *pszOption, const char *pszMask)
|
---|
35 | {
|
---|
36 | const char *args[] = { NULL, NULL, pszAddr, pszOption, pszMask, NULL };
|
---|
37 |
|
---|
38 | char szAdpCtl[RTPATH_MAX];
|
---|
39 | int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME));
|
---|
40 | if (RT_FAILURE(rc))
|
---|
41 | {
|
---|
42 | LogRel(("NetIfAdpCtl: failed to get program path, rc=%Vrc.\n", rc));
|
---|
43 | return rc;
|
---|
44 | }
|
---|
45 | strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME);
|
---|
46 | args[0] = szAdpCtl;
|
---|
47 | Bstr interfaceName;
|
---|
48 | pIf->COMGETTER(Name)(interfaceName.asOutParam());
|
---|
49 | Utf8Str strName(interfaceName);
|
---|
50 | args[1] = strName;
|
---|
51 | if (!RTPathExists(szAdpCtl))
|
---|
52 | {
|
---|
53 | LogRel(("NetIfAdpCtl: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n",
|
---|
54 | szAdpCtl));
|
---|
55 | return VERR_FILE_NOT_FOUND;
|
---|
56 | }
|
---|
57 |
|
---|
58 | RTPROCESS pid;
|
---|
59 | rc = RTProcCreate(szAdpCtl, args, RTENV_DEFAULT, 0, &pid);
|
---|
60 | if (RT_SUCCESS(rc))
|
---|
61 | {
|
---|
62 | RTPROCSTATUS Status;
|
---|
63 | rc = RTProcWait(pid, 0, &Status);
|
---|
64 | if ( RT_SUCCESS(rc)
|
---|
65 | && Status.iStatus == 0
|
---|
66 | && Status.enmReason == RTPROCEXITREASON_NORMAL)
|
---|
67 | return VINF_SUCCESS;
|
---|
68 | }
|
---|
69 | else
|
---|
70 | LogRel(("NetIfAdpCtl: failed to create process for %.\n",
|
---|
71 | szAdpCtl));
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask)
|
---|
76 | {
|
---|
77 | const char *pszOption, *pszMask;
|
---|
78 | char szAddress[16]; /* 4*3 + 3*1 + 1 */
|
---|
79 | char szNetMask[16]; /* 4*3 + 3*1 + 1 */
|
---|
80 | uint8_t *pu8Addr = (uint8_t *)&aNewIp;
|
---|
81 | uint8_t *pu8Mask = (uint8_t *)&aMask;
|
---|
82 | if (aNewIp == 0)
|
---|
83 | {
|
---|
84 | pu8Addr = (uint8_t *)&aOldIp;
|
---|
85 | pszOption = "remove";
|
---|
86 | pszMask = NULL;
|
---|
87 | }
|
---|
88 | else
|
---|
89 | {
|
---|
90 | pszOption = "netmask";
|
---|
91 | pszMask = szNetMask;
|
---|
92 | RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d",
|
---|
93 | pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]);
|
---|
94 | }
|
---|
95 | RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d",
|
---|
96 | pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]);
|
---|
97 | return NetIfAdpCtl(pIf, szAddress, pszOption, pszMask);
|
---|
98 | }
|
---|
99 |
|
---|
100 | int NetIfEnableStaticIpConfigV6(VirtualBox * /* vBox */, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
|
---|
101 | {
|
---|
102 | char szAddress[5*8 + 1 + 5 + 1];
|
---|
103 | if (Bstr(aIPV6Address).length())
|
---|
104 | {
|
---|
105 | RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d",
|
---|
106 | aIPV6Address, aIPV6MaskPrefixLength);
|
---|
107 | return NetIfAdpCtl(pIf, szAddress, NULL, NULL);
|
---|
108 | }
|
---|
109 | else
|
---|
110 | {
|
---|
111 | RTStrPrintf(szAddress, sizeof(szAddress), "%ls",
|
---|
112 | aOldIPV6Address);
|
---|
113 | return NetIfAdpCtl(pIf, szAddress, "remove", NULL);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | int NetIfEnableDynamicIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * /* pIf */)
|
---|
118 | {
|
---|
119 | return VERR_NOT_IMPLEMENTED;
|
---|
120 | }
|
---|
121 |
|
---|
122 | int NetIfCreateHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */)
|
---|
123 | {
|
---|
124 | return VERR_NOT_IMPLEMENTED;
|
---|
125 | }
|
---|
126 |
|
---|
127 | int NetIfRemoveHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IN_GUID /* aId */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */)
|
---|
128 | {
|
---|
129 | return VERR_NOT_IMPLEMENTED;
|
---|
130 | }
|
---|
131 |
|
---|
132 | int NetIfGetConfig(HostNetworkInterface * /* pIf */, NETIFINFO *)
|
---|
133 | {
|
---|
134 | return VERR_NOT_IMPLEMENTED;
|
---|
135 | }
|
---|
136 |
|
---|
137 | int NetIfDhcpRediscover(VirtualBox * /* pVbox */, HostNetworkInterface * /* pIf */)
|
---|
138 | {
|
---|
139 | return VERR_NOT_IMPLEMENTED;
|
---|
140 | }
|
---|
141 |
|
---|