Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /SocketX/Network.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download) (as text)
Wed Feb 10 18:21:00 2010 UTC (14 years, 2 months ago) by sho1get
File MIME type: text/x-c++src
File size: 1738 byte(s)


1 sho1get 11 #pragma once
2    
3     #include "stdafx.h"
4     #include "SocketX.h"
5    
6     //////////////////////////////////////////////////////////////////////////
7    
8     CNetwork::CNetwork()
9     {
10     }
11    
12     CNetwork::~CNetwork()
13     {
14     }
15    
16     BOOL CNetwork::GetIPv4List(DWORD &dwSize, DWORD dwMax, LPIPv4 lpList)
17     {
18     PMIB_IPADDRTABLE pIpAddrTable;
19     DWORD dwTbSize = 0;
20     DWORD dwRetVal = 0;
21    
22     // Get size
23     if (GetIpAddrTable(NULL, &dwTbSize, 0) == ERROR_INSUFFICIENT_BUFFER)
24     {
25     pIpAddrTable = (PMIB_IPADDRTABLE)malloc(dwTbSize);
26    
27     if (pIpAddrTable == NULL)
28     {
29     TRACE1("***** ERROR: malloc(%d) *****\n", GetLastError());
30     return FALSE;
31     }
32     }
33    
34     // Get data
35     if (GetIpAddrTable(pIpAddrTable, &dwTbSize, 0) == NO_ERROR)
36     {
37     if (pIpAddrTable->dwNumEntries > 0)
38     {
39     dwSize = pIpAddrTable->dwNumEntries < dwMax ?
40     pIpAddrTable->dwNumEntries : dwMax;
41    
42     for (UINT i = 0; i < (UINT)dwSize; i++)
43     {
44     lpList[i].dwIndex = pIpAddrTable->table[i].dwIndex;
45     lpList[i].dwAddress = pIpAddrTable->table[i].dwAddr;
46     lpList[i].dwNetMask = pIpAddrTable->table[i].dwMask;
47     lpList[i].dwBcastAddress = MakeBcastAddress(lpList[i].dwAddress, lpList[i].dwNetMask);
48     }
49     }
50     }
51    
52     free(pIpAddrTable);
53    
54     return TRUE;
55     }
56    
57     BOOL CNetwork::IsAvailable()
58     {
59     DWORD dwSize;
60     IPv4 list[2];
61    
62     if (!GetIPv4List(dwSize, 2, list))
63     {
64     return FALSE;
65     }
66    
67     // Is not connected to the network. Or just loopback
68     if ((dwSize < 1) || (dwSize == 1 && list[0].dwAddress == 0x0100007F))
69     {
70     return FALSE;
71     }
72    
73     return TRUE;
74     }
75    
76     DWORD CNetwork::MakeBcastAddress(DWORD dwAddress, DWORD dwNetMask)
77     {
78     return ((dwAddress & dwNetMask) | (~dwNetMask));
79     }
80    
81     //////////////////////////////////////////////////////////////////////////

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26