VirtualBox

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

Last change on this file since 11977 was 11938, checked in by vboxsync, 17 years ago

Additions/Win/VBoxService to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: VBoxVMInfoNet.cpp 11938 2008-09-01 16:10:51Z 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 DWORD dwCurIface = 0;
29
30 SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
31 if (sd == SOCKET_ERROR)
32 {
33 Log(("vboxVMInfoThread: Failed to get a socket: Error %d\n", WSAGetLastError()));
34 return -1;
35 }
36
37 INTERFACE_INFO InterfaceList[20];
38 unsigned long nBytesReturned;
39 if ( WSAIoctl(sd, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList,
40 sizeof(InterfaceList), &nBytesReturned, 0, 0)
41 == SOCKET_ERROR)
42 {
43 Log(("vboxVMInfoThread: Failed calling WSAIoctl: Error: %d\n", WSAGetLastError()));
44 return -1;
45 }
46
47 int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
48 Log(("vboxVMInfoThread: There are %d interfaces:\n", nNumInterfaces-1));
49
50 dwCurIface = 0;
51
52 for (int i = 0; i < nNumInterfaces; ++i)
53 {
54 if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
55 continue;
56
57 sockaddr_in *pAddress;
58 pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress);
59 Log((" %s", inet_ntoa(pAddress->sin_addr)));
60
61 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
62 Log((" has bcast %s", inet_ntoa(pAddress->sin_addr)));
63
64 pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask);
65 Log((" and netmask %s", inet_ntoa(pAddress->sin_addr)));
66
67 Log((" Iface is "));
68 u_long nFlags = InterfaceList[i].iiFlags;
69 if (nFlags & IFF_UP) Log(("up"));
70 else Log(("down"));
71 if (nFlags & IFF_POINTTOPOINT) Log((", is point-to-point"));
72 Log((", and can do: "));
73 if (nFlags & IFF_BROADCAST) Log(("bcast " ));
74 if (nFlags & IFF_MULTICAST) Log(("multicast "));
75 Log(("\n"));
76
77 /** @todo Add more information & storage here! */
78 }
79
80 closesocket(sd);
81
82 return 0;
83}
84
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette