VirtualBox

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

Last change on this file since 67954 was 67566, checked in by vboxsync, 7 years ago

dropped composeIPv6Address() and composeHardwareAddress()

  • 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 67566 2017-06-22 15:42:31Z vboxsync $ */
2/** @file
3 * Main - Network Interfaces.
4 */
5
6/*
7 * Copyright (C) 2008-2016 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 bDhcpEnabled;
71 BOOL bIsDefault;
72 RTMAC MACAddress;
73 NETIFTYPE enmMediumType;
74 NETIFSTATUS enmStatus;
75 uint32_t uSpeedMbits;
76 RTUUID Uuid;
77 char szShortName[VBOXNET_MAX_SHORT_NAME];
78 char szName[1];
79} NETIFINFO;
80
81/** Pointer to a network interface info. */
82typedef NETIFINFO *PNETIFINFO;
83/** Pointer to a const network interface info. */
84typedef NETIFINFO const *PCNETIFINFO;
85#endif
86
87int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list);
88int NetIfEnableStaticIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask);
89int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
90int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
91int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL);
92int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, IN_GUID aId, IProgress **aProgress);
93int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
94int NetIfGetConfigByName(PNETIFINFO pInfo);
95int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState);
96int NetIfGetLinkSpeed(const char *pcszIfName, uint32_t *puMbits);
97int NetIfDhcpRediscover(VirtualBox *pVBox, HostNetworkInterface * pIf);
98int NetIfAdpCtlOut(const char *pszName, const char *pszCmd, char *pszBuffer, size_t cBufSize);
99
100DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName)
101{
102 /* Get the index from the name */
103 Utf8Str strTmp = bstrIfName;
104 const char *pcszIfName = strTmp.c_str();
105 int iInstance = 0;
106 size_t iPos = strcspn(pcszIfName, "0123456789");
107 if (pcszIfName[iPos])
108 iInstance = RTStrToUInt32(pcszIfName + iPos);
109
110 in_addr tmp;
111#if defined(RT_OS_WINDOWS)
112 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
113#else
114 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16);
115#endif
116 char *addr = inet_ntoa(tmp);
117 return Bstr(addr);
118}
119
120#endif /* !___netif_h */
121/* 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