VirtualBox

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

Last change on this file since 72098 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: netif.h 69500 2017-10-28 15:14:05Z 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 */
42typedef enum NETIFTYPE
43{
44 NETIF_T_UNKNOWN,
45 NETIF_T_ETHERNET,
46 NETIF_T_PPP,
47 NETIF_T_SLIP
48} NETIFTYPE;
49
50/**
51 * Current state of the interface.
52 */
53typedef enum NETIFSTATUS
54{
55 NETIF_S_UNKNOWN,
56 NETIF_S_UP,
57 NETIF_S_DOWN
58} NETIFSTATUS;
59
60/**
61 * Host Network Interface Information.
62 */
63typedef struct NETIFINFO
64{
65 NETIFINFO *pNext;
66 RTNETADDRIPV4 IPAddress;
67 RTNETADDRIPV4 IPNetMask;
68 RTNETADDRIPV6 IPv6Address;
69 RTNETADDRIPV6 IPv6NetMask;
70 BOOL fDhcpEnabled;
71 BOOL fIsDefault;
72 BOOL fWireless;
73 RTMAC MACAddress;
74 NETIFTYPE enmMediumType;
75 NETIFSTATUS enmStatus;
76 uint32_t uSpeedMbits;
77 RTUUID Uuid;
78 char szShortName[VBOXNET_MAX_SHORT_NAME];
79 char szName[1];
80} NETIFINFO;
81
82/** Pointer to a network interface info. */
83typedef NETIFINFO *PNETIFINFO;
84/** Pointer to a const network interface info. */
85typedef NETIFINFO const *PCNETIFINFO;
86#endif
87
88int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
89int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
90int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
91int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
92int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL);
93int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, IN_GUID aId, IProgress **aProgress);
94int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
95int NetIfGetConfigByName(PNETIFINFO pInfo);
96int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
97int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
98int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
99int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
100
101DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
102{
103 /* Get the index from the name */
104 Utf8Str strTmp = bstrIfName;
105 const char *pcszIfName = strTmp.c_str();
106 int iInstance = 0;
107 size_t iPos = strcspn(pcszIfName, "0123456789");
108 if (pcszIfName[iPos])
109 iInstance = RTStrToUInt32(pcszIfName + iPos);
110
111 in_addr tmp;
112#if defined(RT_OS_WINDOWS)
113 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
114#else
115 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
116#endif
117 char *addr = inet_ntoa(tmp);
118 return Bstr(addr);
119}
120
121#endif /* !___netif_h */
122/* 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