1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| BOOL CSelectHostsDlg::AddNetwork(BYTE nIpFromA, BYTE nIpFromB, BYTE nIpFromC, BYTE nIpFromD, BYTE nIpToA, BYTE nIpToB, BYTE nIpToC, BYTE nIpToD)
{
try
{
BYTE n;
CString csAddress;
if (nIpFromA == nIpToA)
{
// Address range is inside a single class A network
if (nIpFromB == nIpToB)
{
// Address range is inside a single class B network
if (nIpFromC == nIpToC)
{
// Address range is inside a single class C network
for (n=nIpFromD; n<=nIpToD; n++)
{
csAddress.Format( _T( "%u.%u.%u.%u"), nIpFromA, nIpFromB, nIpFromC, n);
m_pComputerList->AddTail(csAddress);
}
return TRUE;
}
// Address range is over mulitple class C networks
for (n=nIpFromC; n<=nIpToC; n++)
{
if (n==nIpFromC)
{
// First class C, add only from first specified address
if (!AddNetwork( nIpFromA, nIpFromB, n, nIpFromD, nIpFromA, nIpFromB, n, MAX_IP_RANGE))
return FALSE;
}
else
{
if (n==nIpToC)
{
// Last class C, add only to last specified address
if (!AddNetwork( nIpFromA, nIpFromB, n, 0, nIpFromA, nIpFromB, n, nIpToD))
return FALSE;
}
else
{
// Full class C
if (!AddNetwork( nIpFromA, nIpFromB, n, 0, nIpFromA, nIpFromB, n, MAX_IP_RANGE))
return FALSE;
}
}
}
return TRUE;
}
// Address range is over mulitple class B networks
for (n=nIpFromB; n<=nIpToB; n++)
{
if (n==nIpFromB)
{
// First class B, add only from first specified address
if (!AddNetwork( nIpFromA, n, nIpFromC, nIpFromD, nIpFromA, n, MAX_IP_RANGE, MAX_IP_RANGE))
return FALSE;
}
else
{
if (n==nIpToB)
{
// Last class B, add only to last specified address
if (!AddNetwork( nIpFromA, n, 0, 0, nIpFromA, n, nIpToC, nIpToD))
return FALSE;
}
else
{
// Full class B
if (!AddNetwork( nIpFromA, n, 0, 0, nIpFromA, n, MAX_IP_RANGE, MAX_IP_RANGE))
return FALSE;
}
}
}
return TRUE;
}
// Address range is over mulitple class A networks
for (n=nIpFromA; n<=nIpToA; n++)
{
if (n==nIpFromA)
{
// First class A, add only from first specified address
if (!AddNetwork( n, nIpFromB, nIpFromC, nIpFromD, n, MAX_IP_RANGE, MAX_IP_RANGE, MAX_IP_RANGE))
return FALSE;
}
else
{
if (n==nIpToA)
{
// Last class A, add only to last specified address
if (!AddNetwork( n, 0, 0, 0, n, nIpToB, nIpToC, nIpToD))
return FALSE;
}
else
{
// Full class A
if (!AddNetwork( n, 0, 0, 0, n, MAX_IP_RANGE, MAX_IP_RANGE, MAX_IP_RANGE))
return FALSE;
}
}
}
return TRUE;
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return FALSE;
}
} |
Partager