VirtualBox

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

Last change on this file since 78501 was 77804, checked in by vboxsync, 6 years ago

NetAdp/Win: (bugref:9409) Store host-only adapter configuration in extra data. Create missing adapters when listing/creating/removing adapters.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: netif.h 77804 2019-03-20 08:05:37Z vboxsync $ */
2/** @file
3 * Main - Network Interfaces.
4 */
5
6/*
7 * Copyright (C) 2008-2019 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 MAIN_INCLUDED_netif_h
19#define MAIN_INCLUDED_netif_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/cdefs.h>
25#include <iprt/types.h>
26#include <iprt/net.h>
27/** @todo r=bird: The inlined code below that drags in asm.h here. I doubt
28 * speed is very important here, so move it into a .cpp file, please. */
29#include <iprt/asm.h>
30
31#ifndef RT_OS_WINDOWS
32# include <arpa/inet.h>
33# include <stdio.h>
34#endif /* !RT_OS_WINDOWS */
35
36#define VBOXNET_IPV4ADDR_DEFAULT 0x0138A8C0 /* 192.168.56.1 */
37#define VBOXNET_IPV4MASK_DEFAULT "255.255.255.0"
38
39#define VBOXNET_MAX_SHORT_NAME 50
40
41#if 1
42/**
43 * Encapsulation type.
44 * @note Must match HostNetworkInterfaceMediumType_T exactly.
45 * @todo r=bird: Why are we duplicating HostNetworkInterfaceMediumType_T here?!?
46 */
47typedef enum NETIFTYPE
48{
49 NETIF_T_UNKNOWN,
50 NETIF_T_ETHERNET,
51 NETIF_T_PPP,
52 NETIF_T_SLIP
53} NETIFTYPE;
54
55/**
56 * Current state of the interface.
57 * @note Must match HostNetworkInterfaceStatus_T exactly.
58 * @todo r=bird: Why are we duplicating HostNetworkInterfaceStatus_T here?!?
59 */
60typedef enum NETIFSTATUS
61{
62 NETIF_S_UNKNOWN,
63 NETIF_S_UP,
64 NETIF_S_DOWN
65} NETIFSTATUS;
66
67/**
68 * Host Network Interface Information.
69 */
70typedef struct NETIFINFO
71{
72 NETIFINFO *pNext;
73 RTNETADDRIPV4 IPAddress;
74 RTNETADDRIPV4 IPNetMask;
75 RTNETADDRIPV6 IPv6Address;
76 RTNETADDRIPV6 IPv6NetMask;
77 BOOL fDhcpEnabled;
78 BOOL fIsDefault;
79 BOOL fWireless;
80 RTMAC MACAddress;
81 NETIFTYPE enmMediumType;
82 NETIFSTATUS enmStatus;
83 uint32_t uSpeedMbits;
84 RTUUID Uuid;
85 char szShortName[VBOXNET_MAX_SHORT_NAME];
86 char szName[1];
87} NETIFINFO;
88
89/** Pointer to a network interface info. */
90typedef NETIFINFO *PNETIFINFO;
91/** Pointer to a const network interface info. */
92typedef NETIFINFO const *PCNETIFINFO;
93#endif
94
95int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
96int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
97int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface *pIf, const Utf8Str &aOldIPV6Address, const Utf8Str &aIPV6Address, ULONG aIPV6MaskPrefixLength);
98int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
99#if defined(RT_OS_WINDOWS)
100int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, IN_BSTR bstrName = NULL);
101#else /* !defined(RT_OS_WINDOWS) */
102int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL);
103#endif /* !defined(RT_OS_WINDOWS) */
104int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress);
105int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
106int NetIfGetConfigByName(PNETIFINFO pInfo);
107int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
108int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
109int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
110int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
111
112DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
113{
114 /* Get the index from the name */
115 Utf8Str strTmp = bstrIfName;
116 const char *pcszIfName = strTmp.c_str();
117 int iInstance = 0;
118 size_t iPos = strcspn(pcszIfName, "0123456789");
119 if (pcszIfName[iPos])
120 iInstance = RTStrToUInt32(pcszIfName + iPos);
121
122 in_addr tmp;
123#if defined(RT_OS_WINDOWS)
124 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
125#else
126 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
127#endif
128 char *addr = inet_ntoa(tmp);
129 return Bstr(addr);
130}
131
132#endif /* !MAIN_INCLUDED_netif_h */
133/* 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