VirtualBox

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

Last change on this file since 90828 was 85264, checked in by vboxsync, 4 years ago

Main/NetIf-generic.cpp: Made NetIfAdpCtl() return failure when the exit code is non-zero or it terminated abnormally (judging from the error messages, this is what the callers expects). Tried to untangle status code mess in NetIfCreateHostOnlyNetworkInterface(), adding missing error handling for popen() and adjusting some of the copy&paste error messages a little. NetIfRemoveHostOnlyNetworkInterface() should not call i_notifyComplete on an uninitialized progress object, and the return of Progress::init() is not a vbox status code that this function can return unconverted. createObject can fail. bugref:9790

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: netif.h 85264 2020-07-12 00:56:45Z vboxsync $ */
2/** @file
3 * Main - Network Interfaces.
4 */
5
6/*
7 * Copyright (C) 2008-2020 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#ifdef RT_OS_WINDOWS
100int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
101 IN_BSTR bstrName = NULL);
102#else
103int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
104 const char *pszName = NULL);
105#endif
106int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress);
107int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
108int NetIfGetConfigByName(PNETIFINFO pInfo);
109int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
110int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
111int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
112int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
113
114DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
115{
116 /* Get the index from the name */
117 Utf8Str strTmp = bstrIfName;
118 const char *pcszIfName = strTmp.c_str();
119 size_t iPos = strcspn(pcszIfName, "0123456789");
120 uint32_t uInstance = 0;
121 if (pcszIfName[iPos])
122 uInstance = RTStrToUInt32(pcszIfName + iPos);
123
124 in_addr tmp;
125#if defined(RT_OS_WINDOWS)
126 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (uInstance << 16);
127#else
128 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (uInstance << 16);
129#endif
130 char *addr = inet_ntoa(tmp);
131 return Bstr(addr);
132}
133
134#endif /* !MAIN_INCLUDED_netif_h */
135/* 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