VirtualBox

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

Last change on this file since 17762 was 17722, checked in by vboxsync, 16 years ago

#3569: IPv6 static ip config for unix platforms + 'remove' option in helper.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: NetIf-generic.cpp 17722 2009-03-12 09:04:08Z 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 return rc;
47 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME);
48 args[0] = szAdpCtl;
49 Bstr interfaceName;
50 pIf->COMGETTER(Name)(interfaceName.asOutParam());
51 Utf8Str strName(interfaceName);
52 args[1] = strName;
53 if (!RTPathExists(szAdpCtl))
54 {
55 LogRel(("NetIf: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n",
56 szAdpCtl));
57 return VERR_FILE_NOT_FOUND;
58 }
59
60 RTPROCESS pid;
61 rc = RTProcCreate(VBOXNETADPCTL_NAME, args, RTENV_DEFAULT, 0, &pid);
62 if (RT_SUCCESS(rc))
63 {
64 RTPROCSTATUS Status;
65 rc = RTProcWait(pid, 0, &Status);
66 if ( RT_SUCCESS(rc)
67 && Status.iStatus == 0
68 && Status.enmReason == RTPROCEXITREASON_NORMAL)
69 return VINF_SUCCESS;
70 }
71 return rc;
72}
73
74int NetIfEnableStaticIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf, ULONG ip, ULONG mask)
75{
76 char szAddress[16]; /* 4*3 + 3*1 + 1 */
77 char szNetMask[16]; /* 4*3 + 3*1 + 1 */
78 uint8_t *pu8Addr = (uint8_t *)&ip;
79 uint8_t *pu8Mask = (uint8_t *)&mask;
80 RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d",
81 pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]);
82 RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d",
83 pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]);
84 return NetIfAdpCtl(pIf, szAddress, szNetMask);
85}
86
87int NetIfEnableStaticIpConfigV6(VirtualBox *vBox, HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
88{
89 char szAddress[5*8 + 1 + 5 + 1];
90 RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d",
91 aIPV6Address, aIPV6MaskPrefixLength);
92 return NetIfAdpCtl(pIf, szAddress, NULL);
93}
94
95int NetIfEnableDynamicIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf)
96{
97 return VERR_NOT_IMPLEMENTED;
98}
99
100int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
101{
102 return VERR_NOT_IMPLEMENTED;
103}
104
105int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVbox, IN_GUID aId, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
106{
107 return VERR_NOT_IMPLEMENTED;
108}
109
110int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *)
111{
112 return VERR_NOT_IMPLEMENTED;
113}
Note: See TracBrowser for help on using the repository browser.

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