VirtualBox

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

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

#3569: IPv4 static ip config for unix platforms + darwin NetIfList update

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