VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxService/VBoxVMInfoNet.cpp@ 13483

Last change on this file since 13483 was 13462, checked in by vboxsync, 16 years ago

fix headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: VBoxVMInfoNet.cpp 13462 2008-10-22 06:46:45Z vboxsync $ */
2/** @file
3 * VBoxVMInfoNet - Network information for the host.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "VBoxService.h"
23#include "VBoxVMInfo.h"
24#include "VBoxVMInfoNet.h"
25
26int vboxVMInfoNet(VBOXINFORMATIONCONTEXT* a_pCtx)
27{
28 SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
29 if (sd == SOCKET_ERROR)
30 {
31 Log(("vboxVMInfoThread: Failed to get a socket: Error %d\n", WSAGetLastError()));
32 return -1;
33 }
34
35 INTERFACE_INFO InterfaceList[20];
36 unsigned long nBytesReturned;
37 if ( WSAIoctl(sd, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList,
38 sizeof(InterfaceList), &nBytesReturned, 0, 0)
39 == SOCKET_ERROR)
40 {
41 Log(("vboxVMInfoThread: Failed calling WSAIoctl: Error: %d\n", WSAGetLastError()));
42 return -1;
43 }
44
45 char szPropPath [_MAX_PATH+1] = {0};
46 char szTemp [_MAX_PATH+1] = {0};
47 int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
48 int iCurIface = 0;
49
50 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/Count");
51 vboxVMInfoWritePropInt(a_pCtx, szPropPath, (nNumInterfaces > 1 ? nNumInterfaces-1 : 0));
52
53 /* Later: Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */
54
55 for (int i = 0; i < nNumInterfaces; ++i)
56 {
57 if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
58 continue;
59
60 sockaddr_in *pAddress;
61 pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress);
62 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/IP", iCurIface);
63 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
64
65 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
66 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Broadcast", iCurIface);
67 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
68
69 pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask);
70 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Netmask", iCurIface);
71 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
72
73 u_long nFlags = InterfaceList[i].iiFlags;
74 if (nFlags & IFF_UP)
75 RTStrPrintf(szTemp, sizeof(szTemp), "Up");
76 else
77 RTStrPrintf(szTemp, sizeof(szTemp), "Down");
78
79 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/Status", iCurIface);
80 vboxVMInfoWriteProp(a_pCtx, szPropPath, szTemp);
81
82 iCurIface++;
83 }
84
85 closesocket(sd);
86
87 return 0;
88}
89
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