VirtualBox

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

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

Comment.

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