VirtualBox

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

Last change on this file since 61644 was 55401, checked in by vboxsync, 10 years ago

added a couple of missing Id headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: netif.h 55401 2015-04-23 10:03:17Z vboxsync $ */
2/** @file
3 * Main - Network Interfaces.
4 */
5
6/*
7 * Copyright (C) 2008-2012 Oracle Corporation
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
18#ifndef ___netif_h
19#define ___netif_h
20
21#include <iprt/cdefs.h>
22#include <iprt/types.h>
23#include <iprt/net.h>
24/** @todo r=bird: The inlined code below that drags in asm.h here. I doubt
25 * speed is very important here, so move it into a .cpp file, please. */
26#include <iprt/asm.h>
27
28#ifndef RT_OS_WINDOWS
29# include <arpa/inet.h>
30# include <stdio.h>
31#endif /* !RT_OS_WINDOWS */
32
33#define VBOXNET_IPV4ADDR_DEFAULT 0x0138A8C0 /* 192.168.56.1 */
34#define VBOXNET_IPV4MASK_DEFAULT "255.255.255.0"
35
36#define VBOXNET_MAX_SHORT_NAME 50
37
38#if 1
39/**
40 * Encapsulation type.
41 */
42typedef enum NETIFTYPE
43{
44 NETIF_T_UNKNOWN,
45 NETIF_T_ETHERNET,
46 NETIF_T_PPP,
47 NETIF_T_SLIP
48} NETIFTYPE;
49
50/**
51 * Current state of the interface.
52 */
53typedef enum NETIFSTATUS
54{
55 NETIF_S_UNKNOWN,
56 NETIF_S_UP,
57 NETIF_S_DOWN
58} NETIFSTATUS;
59
60/**
61 * Host Network Interface Information.
62 */
63typedef struct NETIFINFO
64{
65 NETIFINFO *pNext;
66 RTNETADDRIPV4 IPAddress;
67 RTNETADDRIPV4 IPNetMask;
68 RTNETADDRIPV6 IPv6Address;
69 RTNETADDRIPV6 IPv6NetMask;
70 BOOL bDhcpEnabled;
71 BOOL bIsDefault;
72 RTMAC MACAddress;
73 NETIFTYPE enmMediumType;
74 NETIFSTATUS enmStatus;
75 uint32_t uSpeedMbits;
76 RTUUID Uuid;
77 char szShortName[VBOXNET_MAX_SHORT_NAME];
78 char szName[1];
79} NETIFINFO;
80
81/** Pointer to a network interface info. */
82typedef NETIFINFO *PNETIFINFO;
83/** Pointer to a const network interface info. */
84typedef NETIFINFO const *PCNETIFINFO;
85#endif
86
87int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
88int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
89int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
90int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
91int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pcszName = NULL);
92int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId, IProgress **aProgress);
93int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
94int NetIfGetConfigByName(PNETIFINFO pInfo);
95int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
96int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
97int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
98int NetIfAdpCtlOut(const char * pcszName, const char * pcszCmd, char *pszBuffer, size_t cBufSize);
99
100DECLINLINE(Bstr) composeIPv6Address(PRTNETADDRIPV6 aAddrPtr)
101{
102 char szTmp[8*5] = "";
103
104 if (aAddrPtr->s.Lo || aAddrPtr->s.Hi)
105 RTStrPrintf(szTmp, sizeof(szTmp),
106 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
107 "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
108 aAddrPtr->au8[0], aAddrPtr->au8[1],
109 aAddrPtr->au8[2], aAddrPtr->au8[3],
110 aAddrPtr->au8[4], aAddrPtr->au8[5],
111 aAddrPtr->au8[6], aAddrPtr->au8[7],
112 aAddrPtr->au8[8], aAddrPtr->au8[9],
113 aAddrPtr->au8[10], aAddrPtr->au8[11],
114 aAddrPtr->au8[12], aAddrPtr->au8[13],
115 aAddrPtr->au8[14], aAddrPtr->au8[15]);
116 return Bstr(szTmp);
117}
118
119DECLINLINE(ULONG) composeIPv6PrefixLenghFromAddress(PRTNETADDRIPV6 aAddrPtr)
120{
121 int res = ASMBitFirstClear(aAddrPtr, sizeof(RTNETADDRIPV6)*8);
122 return res != -1 ? res : 128;
123}
124
125DECLINLINE(int) prefixLength2IPv6Address(ULONG cPrefix, PRTNETADDRIPV6 aAddrPtr)
126{
127 if (cPrefix > 128)
128 return VERR_INVALID_PARAMETER;
129 if (!aAddrPtr)
130 return VERR_INVALID_PARAMETER;
131
132 RT_ZERO(*aAddrPtr);
133
134 ASMBitSetRange(aAddrPtr, 0, cPrefix);
135
136 return VINF_SUCCESS;
137}
138
139DECLINLINE(Bstr) composeHardwareAddress(PRTMAC aMacPtr)
140{
141 char szTmp[6*3];
142
143 RTStrPrintf(szTmp, sizeof(szTmp),
144 "%02x:%02x:%02x:%02x:%02x:%02x",
145 aMacPtr->au8[0], aMacPtr->au8[1],
146 aMacPtr->au8[2], aMacPtr->au8[3],
147 aMacPtr->au8[4], aMacPtr->au8[5]);
148 return Bstr(szTmp);
149}
150
151DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
152{
153 /* Get the index from the name */
154 Utf8Str strTmp = bstrIfName;
155 const char *pszIfName = strTmp.c_str();
156 int iInstance = 0;
157 size_t iPos = strcspn(pszIfName, "0123456789");
158 if (pszIfName[iPos])
159 iInstance = RTStrToUInt32(pszIfName + iPos);
160
161 in_addr tmp;
162#if defined(RT_OS_WINDOWS)
163 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
164#else
165 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
166#endif
167 char *addr = inet_ntoa(tmp);
168 return Bstr(addr);
169}
170
171#endif /* !___netif_h */
172/* 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