VirtualBox

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

Last change on this file since 100108 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: netif.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Main - Network Interfaces.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_netif_h
29#define MAIN_INCLUDED_netif_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36#include <iprt/net.h>
37/** @todo r=bird: The inlined code below that drags in asm.h here. I doubt
38 * speed is very important here, so move it into a .cpp file, please. */
39#include <iprt/asm.h>
40
41#ifndef RT_OS_WINDOWS
42# include <arpa/inet.h>
43# include <stdio.h>
44#endif /* !RT_OS_WINDOWS */
45
46#define VBOXNET_IPV4ADDR_DEFAULT 0x0138A8C0 /* 192.168.56.1 */
47#define VBOXNET_IPV4MASK_DEFAULT "255.255.255.0"
48
49#define VBOXNET_MAX_SHORT_NAME 50
50
51#if 1
52/**
53 * Encapsulation type.
54 * @note Must match HostNetworkInterfaceMediumType_T exactly.
55 * @todo r=bird: Why are we duplicating HostNetworkInterfaceMediumType_T here?!?
56 */
57typedef enum NETIFTYPE
58{
59 NETIF_T_UNKNOWN,
60 NETIF_T_ETHERNET,
61 NETIF_T_PPP,
62 NETIF_T_SLIP
63} NETIFTYPE;
64
65/**
66 * Current state of the interface.
67 * @note Must match HostNetworkInterfaceStatus_T exactly.
68 * @todo r=bird: Why are we duplicating HostNetworkInterfaceStatus_T here?!?
69 */
70typedef enum NETIFSTATUS
71{
72 NETIF_S_UNKNOWN,
73 NETIF_S_UP,
74 NETIF_S_DOWN
75} NETIFSTATUS;
76
77/**
78 * Host Network Interface Information.
79 */
80typedef struct NETIFINFO
81{
82 NETIFINFO *pNext;
83 RTNETADDRIPV4 IPAddress;
84 RTNETADDRIPV4 IPNetMask;
85 RTNETADDRIPV6 IPv6Address;
86 RTNETADDRIPV6 IPv6NetMask;
87 BOOL fDhcpEnabled;
88 BOOL fIsDefault;
89 BOOL fWireless;
90 RTMAC MACAddress;
91 NETIFTYPE enmMediumType;
92 NETIFSTATUS enmStatus;
93 uint32_t uSpeedMbits;
94 RTUUID Uuid;
95 char szShortName[VBOXNET_MAX_SHORT_NAME];
96 char szName[1];
97} NETIFINFO;
98
99/** Pointer to a network interface info. */
100typedef NETIFINFO *PNETIFINFO;
101/** Pointer to a const network interface info. */
102typedef NETIFINFO const *PCNETIFINFO;
103#endif
104
105int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
106int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
107int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface *pIf, const Utf8Str &aOldIPV6Address, const Utf8Str &aIPV6Address, ULONG aIPV6MaskPrefixLength);
108int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
109#ifdef RT_OS_WINDOWS
110int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
111 IN_BSTR bstrName = NULL);
112#else
113int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
114 const char *pszName = NULL);
115#endif
116int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress);
117int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
118int NetIfGetConfigByName(PNETIFINFO pInfo);
119int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
120int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
121int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
122int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
123
124DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
125{
126 /* Get the index from the name */
127 Utf8Str strTmp = bstrIfName;
128 const char *pcszIfName = strTmp.c_str();
129 size_t iPos = strcspn(pcszIfName, "0123456789");
130 uint32_t uInstance = 0;
131 if (pcszIfName[iPos])
132 uInstance = RTStrToUInt32(pcszIfName + iPos);
133
134 in_addr tmp;
135#if defined(RT_OS_WINDOWS)
136 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (uInstance << 16);
137#else
138 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (uInstance << 16);
139#endif
140 char *addr = inet_ntoa(tmp);
141 return Bstr(addr);
142}
143
144#endif /* !MAIN_INCLUDED_netif_h */
145/* 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