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 | */
|
---|
47 | typedef 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 | */
|
---|
60 | typedef 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 | */
|
---|
70 | typedef 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. */
|
---|
90 | typedef NETIFINFO *PNETIFINFO;
|
---|
91 | /** Pointer to a const network interface info. */
|
---|
92 | typedef NETIFINFO const *PCNETIFINFO;
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
|
---|
96 | int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
|
---|
97 | int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface *pIf, const Utf8Str &aOldIPV6Address, const Utf8Str &aIPV6Address, ULONG aIPV6MaskPrefixLength);
|
---|
98 | int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
|
---|
99 | #ifdef RT_OS_WINDOWS
|
---|
100 | int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
|
---|
101 | IN_BSTR bstrName = NULL);
|
---|
102 | #else
|
---|
103 | int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress,
|
---|
104 | const char *pszName = NULL);
|
---|
105 | #endif
|
---|
106 | int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress);
|
---|
107 | int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
|
---|
108 | int NetIfGetConfigByName(PNETIFINFO pInfo);
|
---|
109 | int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
|
---|
110 | int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
|
---|
111 | int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
|
---|
112 | int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
|
---|
113 |
|
---|
114 | DECLINLINE(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: */
|
---|