VirtualBox

source: vbox/trunk/src/VBox/Main/include/netif.h@ 28770

Last change on this file since 28770 was 25841, checked in by vboxsync, 15 years ago

VBoxNet (host-only): Revised version of r56609, GUI now uses proper defaults too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/** @file
2 * Main - Network Interfaces.
3 */
4
5/*
6 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 */
20
21#ifndef ___netif_h
22#define ___netif_h
23
24#include <iprt/cdefs.h>
25#include <iprt/types.h>
26#include <iprt/net.h>
27#include <iprt/asm.h>
28
29#ifndef RT_OS_WINDOWS
30#include <arpa/inet.h>
31#include <stdio.h>
32#endif /* RT_OS_WINDOWS */
33
34#define VBOXNET_IPV4ADDR_DEFAULT 0x0138A8C0 /* 192.168.56.1 */
35#define VBOXNET_IPV4MASK_DEFAULT "255.255.255.0"
36
37#define VBOXNET_MAX_SHORT_NAME 50
38
39#if 1
40/**
41 * Encapsulation type.
42 */
43typedef enum NETIFTYPE
44{
45 NETIF_T_UNKNOWN,
46 NETIF_T_ETHERNET,
47 NETIF_T_PPP,
48 NETIF_T_SLIP
49} NETIFTYPE;
50
51/**
52 * Current state of the interface.
53 */
54typedef enum NETIFSTATUS
55{
56 NETIF_S_UNKNOWN,
57 NETIF_S_UP,
58 NETIF_S_DOWN
59} NETIFSTATUS;
60
61/**
62 * Host Network Interface Information.
63 */
64typedef struct NETIFINFO
65{
66 NETIFINFO *pNext;
67 RTNETADDRIPV4 IPAddress;
68 RTNETADDRIPV4 IPNetMask;
69 RTNETADDRIPV6 IPv6Address;
70 RTNETADDRIPV6 IPv6NetMask;
71 BOOL bDhcpEnabled;
72 RTMAC MACAddress;
73 NETIFTYPE enmMediumType;
74 NETIFSTATUS enmStatus;
75 RTUUID Uuid;
76 char szShortName[VBOXNET_MAX_SHORT_NAME];
77 char szName[1];
78} NETIFINFO;
79
80/** Pointer to a network interface info. */
81typedef NETIFINFO *PNETIFINFO;
82/** Pointer to a const network interface info. */
83typedef NETIFINFO const *PCNETIFINFO;
84#endif
85
86int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
87int NetIfEnableStaticIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
88int NetIfEnableStaticIpConfigV6(VirtualBox *pVbox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
89int NetIfEnableDynamicIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf);
90int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress);
91int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVbox, IN_GUID aId, IProgress **aProgress);
92int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
93int NetIfGetConfigByName(PNETIFINFO pInfo);
94int NetIfDhcpRediscover(VirtualBox *pVbox, HostNetworkInterface * pIf);
95
96DECLINLINE(Bstr) composeIPv6Address(PRTNETADDRIPV6 aAddrPtr)
97{
98 char szTmp[8*5] = "";
99
100 if (aAddrPtr->s.Lo || aAddrPtr->s.Hi)
101 RTStrPrintf(szTmp, sizeof(szTmp),
102 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
103 "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
104 aAddrPtr->au8[0], aAddrPtr->au8[1],
105 aAddrPtr->au8[2], aAddrPtr->au8[3],
106 aAddrPtr->au8[4], aAddrPtr->au8[5],
107 aAddrPtr->au8[6], aAddrPtr->au8[7],
108 aAddrPtr->au8[8], aAddrPtr->au8[9],
109 aAddrPtr->au8[10], aAddrPtr->au8[11],
110 aAddrPtr->au8[12], aAddrPtr->au8[13],
111 aAddrPtr->au8[14], aAddrPtr->au8[15]);
112 return Bstr(szTmp);
113}
114
115DECLINLINE(ULONG) composeIPv6PrefixLenghFromAddress(PRTNETADDRIPV6 aAddrPtr)
116{
117 int res = ASMBitFirstClear(aAddrPtr, sizeof(RTNETADDRIPV6)*8);
118 return res != -1 ? res : 128;
119}
120
121DECLINLINE(int) prefixLength2IPv6Address(ULONG cPrefix, PRTNETADDRIPV6 aAddrPtr)
122{
123 if(cPrefix > 128)
124 return VERR_INVALID_PARAMETER;
125 if(!aAddrPtr)
126 return VERR_INVALID_PARAMETER;
127
128 memset(aAddrPtr, 0, sizeof(RTNETADDRIPV6));
129
130 ASMBitSetRange(aAddrPtr, 0, cPrefix);
131
132 return VINF_SUCCESS;
133}
134
135DECLINLINE(Bstr) composeHardwareAddress(PRTMAC aMacPtr)
136{
137 char szTmp[6*3];
138
139 RTStrPrintf(szTmp, sizeof(szTmp),
140 "%02x:%02x:%02x:%02x:%02x:%02x",
141 aMacPtr->au8[0], aMacPtr->au8[1],
142 aMacPtr->au8[2], aMacPtr->au8[3],
143 aMacPtr->au8[4], aMacPtr->au8[5]);
144 return Bstr(szTmp);
145}
146
147DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
148{
149 /* Get the index from the name */
150 int iInstance;
151 if (sscanf(Utf8Str(bstrIfName).raw(), "vboxnet%d", &iInstance) != 1)
152 return Bstr("0.0.0.0");
153
154 in_addr tmp;
155#if defined(RT_OS_WINDOWS)
156 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
157#else
158 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
159#endif
160 char *addr = inet_ntoa(tmp);
161 return Bstr(addr);
162}
163
164#endif /* ___netif_h */
165/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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