VirtualBox

source: vbox/trunk/src/VBox/Main/generic/NetIf-generic.cpp@ 17882

Last change on this file since 17882 was 17835, checked in by vboxsync, 16 years ago

NetIf/win: DhcpRediscover

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: NetIf-generic.cpp 17835 2009-03-13 15:18:59Z 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
34static int NetIfAdpCtl(HostNetworkInterface * pIf, char *pszAddr, char *pszMask)
35{
36 const char *args[] = { NULL, NULL, pszAddr, NULL, NULL, NULL };
37 if (pszMask)
38 {
39 args[3] = "netmask";
40 args[4] = pszMask;
41 }
42
43 char szAdpCtl[RTPATH_MAX];
44 int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME));
45 if (RT_FAILURE(rc))
46 {
47 LogRel(("NetIfAdpCtl: failed to get program path, rc=%Vrc.\n", rc));
48 return rc;
49 }
50 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME);
51 args[0] = szAdpCtl;
52 Bstr interfaceName;
53 pIf->COMGETTER(Name)(interfaceName.asOutParam());
54 Utf8Str strName(interfaceName);
55 args[1] = strName;
56 if (!RTPathExists(szAdpCtl))
57 {
58 LogRel(("NetIfAdpCtl: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n",
59 szAdpCtl));
60 return VERR_FILE_NOT_FOUND;
61 }
62
63 RTPROCESS pid;
64 rc = RTProcCreate(szAdpCtl, args, RTENV_DEFAULT, 0, &pid);
65 if (RT_SUCCESS(rc))
66 {
67 RTPROCSTATUS Status;
68 rc = RTProcWait(pid, 0, &Status);
69 if ( RT_SUCCESS(rc)
70 && Status.iStatus == 0
71 && Status.enmReason == RTPROCEXITREASON_NORMAL)
72 return VINF_SUCCESS;
73 }
74 else
75 LogRel(("NetIfAdpCtl: failed to create process for %.\n",
76 szAdpCtl));
77 return rc;
78}
79
80int NetIfEnableStaticIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf, ULONG ip, ULONG mask)
81{
82 char szAddress[16]; /* 4*3 + 3*1 + 1 */
83 char szNetMask[16]; /* 4*3 + 3*1 + 1 */
84 uint8_t *pu8Addr = (uint8_t *)&ip;
85 uint8_t *pu8Mask = (uint8_t *)&mask;
86 RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d",
87 pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]);
88 RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d",
89 pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]);
90 return NetIfAdpCtl(pIf, szAddress, szNetMask);
91}
92
93int NetIfEnableStaticIpConfigV6(VirtualBox *vBox, HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
94{
95 char szAddress[5*8 + 1 + 5 + 1];
96 RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d",
97 aIPV6Address, aIPV6MaskPrefixLength);
98 return NetIfAdpCtl(pIf, szAddress, NULL);
99}
100
101int NetIfEnableDynamicIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf)
102{
103 return VERR_NOT_IMPLEMENTED;
104}
105
106int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
107{
108 return VERR_NOT_IMPLEMENTED;
109}
110
111int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVbox, IN_GUID aId, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
112{
113 return VERR_NOT_IMPLEMENTED;
114}
115
116int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *)
117{
118 return VERR_NOT_IMPLEMENTED;
119}
120
121int NetIfDhcpRediscover(VirtualBox *pVbox, HostNetworkInterface * pIf)
122{
123 return VERR_NOT_IMPLEMENTED;
124}
125
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