1 | /* $Id: netif.h 72979 2018-07-08 14:22:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Main - Network Interfaces.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2017 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 | * @note Must match HostNetworkInterfaceMediumType_T exactly.
|
---|
42 | * @todo r=bird: Why are we duplicating HostNetworkInterfaceMediumType_T here?!?
|
---|
43 | */
|
---|
44 | typedef enum NETIFTYPE
|
---|
45 | {
|
---|
46 | NETIF_T_UNKNOWN,
|
---|
47 | NETIF_T_ETHERNET,
|
---|
48 | NETIF_T_PPP,
|
---|
49 | NETIF_T_SLIP
|
---|
50 | } NETIFTYPE;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Current state of the interface.
|
---|
54 | * @note Must match HostNetworkInterfaceStatus_T exactly.
|
---|
55 | * @todo r=bird: Why are we duplicating HostNetworkInterfaceStatus_T here?!?
|
---|
56 | */
|
---|
57 | typedef enum NETIFSTATUS
|
---|
58 | {
|
---|
59 | NETIF_S_UNKNOWN,
|
---|
60 | NETIF_S_UP,
|
---|
61 | NETIF_S_DOWN
|
---|
62 | } NETIFSTATUS;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Host Network Interface Information.
|
---|
66 | */
|
---|
67 | typedef struct NETIFINFO
|
---|
68 | {
|
---|
69 | NETIFINFO *pNext;
|
---|
70 | RTNETADDRIPV4 IPAddress;
|
---|
71 | RTNETADDRIPV4 IPNetMask;
|
---|
72 | RTNETADDRIPV6 IPv6Address;
|
---|
73 | RTNETADDRIPV6 IPv6NetMask;
|
---|
74 | BOOL fDhcpEnabled;
|
---|
75 | BOOL fIsDefault;
|
---|
76 | BOOL fWireless;
|
---|
77 | RTMAC MACAddress;
|
---|
78 | NETIFTYPE enmMediumType;
|
---|
79 | NETIFSTATUS enmStatus;
|
---|
80 | uint32_t uSpeedMbits;
|
---|
81 | RTUUID Uuid;
|
---|
82 | char szShortName[VBOXNET_MAX_SHORT_NAME];
|
---|
83 | char szName[1];
|
---|
84 | } NETIFINFO;
|
---|
85 |
|
---|
86 | /** Pointer to a network interface info. */
|
---|
87 | typedef NETIFINFO *PNETIFINFO;
|
---|
88 | /** Pointer to a const network interface info. */
|
---|
89 | typedef NETIFINFO const *PCNETIFINFO;
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
|
---|
93 | int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
|
---|
94 | int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
|
---|
95 | int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
|
---|
96 | int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL);
|
---|
97 | int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, IN_GUID aId, IProgress **aProgress);
|
---|
98 | int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
|
---|
99 | int NetIfGetConfigByName(PNETIFINFO pInfo);
|
---|
100 | int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
|
---|
101 | int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
|
---|
102 | int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
|
---|
103 | int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
|
---|
104 |
|
---|
105 | DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
|
---|
106 | {
|
---|
107 | /* Get the index from the name */
|
---|
108 | Utf8Str strTmp = bstrIfName;
|
---|
109 | const char *pcszIfName = strTmp.c_str();
|
---|
110 | int iInstance = 0;
|
---|
111 | size_t iPos = strcspn(pcszIfName, "0123456789");
|
---|
112 | if (pcszIfName[iPos])
|
---|
113 | iInstance = RTStrToUInt32(pcszIfName + iPos);
|
---|
114 |
|
---|
115 | in_addr tmp;
|
---|
116 | #if defined(RT_OS_WINDOWS)
|
---|
117 | tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
|
---|
118 | #else
|
---|
119 | tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
|
---|
120 | #endif
|
---|
121 | char *addr = inet_ntoa(tmp);
|
---|
122 | return Bstr(addr);
|
---|
123 | }
|
---|
124 |
|
---|
125 | #endif /* !___netif_h */
|
---|
126 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|