VirtualBox

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

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

Number of interfaces.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/* $Id: VBoxVMInfoNet.cpp 12393 2008-09-11 07:25:47Z 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 DWORD dwCurIface = 0;
20
21 SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
22 if (sd == SOCKET_ERROR)
23 {
24 Log(("vboxVMInfoThread: Failed to get a socket: Error %d\n", WSAGetLastError()));
25 return -1;
26 }
27
28 INTERFACE_INFO InterfaceList[20];
29 unsigned long nBytesReturned;
30 if ( WSAIoctl(sd, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList,
31 sizeof(InterfaceList), &nBytesReturned, 0, 0)
32 == SOCKET_ERROR)
33 {
34 Log(("vboxVMInfoThread: Failed calling WSAIoctl: Error: %d\n", WSAGetLastError()));
35 return -1;
36 }
37
38 char szPropPath [_MAX_PATH+1] = {0};
39 char szTemp [_MAX_PATH+1] = {0};
40 int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
41
42 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/Count");
43 vboxVMInfoWritePropInt(a_pCtx, szPropPath, (nNumInterfaces > 1 ? nNumInterfaces-1 : 0));
44
45 dwCurIface = 0;
46
47 for (int i = 0; i < nNumInterfaces; ++i)
48 {
49 if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
50 continue;
51
52 sockaddr_in *pAddress;
53 pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress);
54 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/IP", i);
55 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
56
57 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
58 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Broadcast", i);
59 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
60
61 pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask);
62 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Netmask", i);
63 vboxVMInfoWriteProp(a_pCtx, szPropPath, inet_ntoa(pAddress->sin_addr));
64
65 u_long nFlags = InterfaceList[i].iiFlags;
66 if (nFlags & IFF_UP)
67 RTStrPrintf(szTemp, sizeof(szTemp), "Up");
68 else
69 RTStrPrintf(szTemp, sizeof(szTemp), "Down");
70
71 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/Status", i);
72 vboxVMInfoWriteProp(a_pCtx, szPropPath, szTemp);
73 }
74
75 closesocket(sd);
76
77 return 0;
78}
79
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