VirtualBox

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

最後變更 在這個檔案從12250是 11982,由 vboxsync 提交於 16 年 前

All: license header changes for 2.0 (OSE headers, add Sun GPL/LGPL disclaimer)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 2.1 KB
 
1/* $Id: VBoxVMInfoNet.cpp 11982 2008-09-02 13:09:44Z 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 int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
39 Log(("vboxVMInfoThread: There are %d interfaces:\n", nNumInterfaces-1));
40
41 dwCurIface = 0;
42
43 for (int i = 0; i < nNumInterfaces; ++i)
44 {
45 if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
46 continue;
47
48 sockaddr_in *pAddress;
49 pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress);
50 Log((" %s", inet_ntoa(pAddress->sin_addr)));
51
52 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
53 Log((" has bcast %s", inet_ntoa(pAddress->sin_addr)));
54
55 pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask);
56 Log((" and netmask %s", inet_ntoa(pAddress->sin_addr)));
57
58 Log((" Iface is "));
59 u_long nFlags = InterfaceList[i].iiFlags;
60 if (nFlags & IFF_UP) Log(("up"));
61 else Log(("down"));
62 if (nFlags & IFF_POINTTOPOINT) Log((", is point-to-point"));
63 Log((", and can do: "));
64 if (nFlags & IFF_BROADCAST) Log(("bcast " ));
65 if (nFlags & IFF_MULTICAST) Log(("multicast "));
66 Log(("\n"));
67
68 /** @todo Add more information & storage here! */
69 }
70
71 closesocket(sd);
72
73 return 0;
74}
75
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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