Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / NetworkInformation / SystemIPv4InterfaceProperties.cs / 1305376 / SystemIPv4InterfaceProperties.cs
///
/// Provides support for ip configuation information and statistics.
///
///
namespace System.Net.NetworkInformation {
using System.Net;
using System.Net.Sockets;
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
using Microsoft.Win32;
internal class SystemIPv4InterfaceProperties:IPv4InterfaceProperties{
//these are only valid for ipv4 interfaces
bool haveWins = false;
bool dhcpEnabled = false;
bool routingEnabled = false;
bool autoConfigEnabled = false;
bool autoConfigActive = false;
uint index = 0;
uint mtu = 0;
//ipv4 addresses only
GatewayIPAddressInformationCollection gatewayAddresses = null;
IPAddressCollection dhcpAddresses = null;
IPAddressCollection winsServerAddresses = null;
internal IPAddressCollection dnsAddresses = null;
/*
// Consider removing.
internal SystemIPv4InterfaceProperties(){
}
*/
internal SystemIPv4InterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
{
index = ipAdapterInfo.index;
routingEnabled = fixedInfo.EnableRouting;
dhcpEnabled = ipAdapterInfo.dhcpEnabled;
haveWins = ipAdapterInfo.haveWins;
gatewayAddresses = ipAdapterInfo.gatewayList.ToIPGatewayAddressCollection();
dhcpAddresses = ipAdapterInfo.dhcpServer.ToIPAddressCollection();
IPAddressCollection primaryWinsServerAddresses = ipAdapterInfo.primaryWinsServer.ToIPAddressCollection();
IPAddressCollection secondaryWinsServerAddresses = ipAdapterInfo.secondaryWinsServer.ToIPAddressCollection();
//concat the winsserver addresses
winsServerAddresses = new IPAddressCollection();
foreach (IPAddress address in primaryWinsServerAddresses){
winsServerAddresses.InternalAdd(address);
}
foreach (IPAddress address in secondaryWinsServerAddresses){
winsServerAddresses.InternalAdd(address);
}
SystemIPv4InterfaceStatistics s = new SystemIPv4InterfaceStatistics(index);
mtu = (uint)s.Mtu;
if(ComNetOS.IsWin2K){
GetPerAdapterInfo(ipAdapterInfo.index);
}
else{
dnsAddresses = fixedInfo.DnsAddresses;
}
}
internal IPAddressCollection DnsAddresses{
get { return dnsAddresses; }
}
/// Only valid for Ipv4 Uses WINS for name resolution.
public override bool UsesWins{get {return haveWins;}}
public override bool IsDhcpEnabled{
get { return dhcpEnabled; }
}
public override bool IsForwardingEnabled{get {return routingEnabled;}} //proto
/// Auto configuration of an ipv4 address for a client
/// on a network where a DHCP server
/// isn't available.
public override bool IsAutomaticPrivateAddressingEnabled{
get{
return autoConfigEnabled;
}
} // proto
public override bool IsAutomaticPrivateAddressingActive{
get{
return autoConfigActive;
}
}
/// Specifies the Maximum transmission unit in bytes. Uses GetIFEntry.
//We cache this to be consistent across all platforms
public override int Mtu{
get {
return (int) mtu;
}
}
public override int Index{
get {
return (int) index;
}
}
/// IP Address of the default gateway.
internal GatewayIPAddressInformationCollection GetGatewayAddresses(){
return gatewayAddresses;
}
/// IP address of the DHCP sever.
internal IPAddressCollection GetDhcpServerAddresses(){
return dhcpAddresses;
}
/// IP addresses of the WINS servers.
internal IPAddressCollection GetWinsServersAddresses(){
return winsServerAddresses;
}
private void GetPerAdapterInfo(uint index) {
if (index != 0){
uint size = 0;
SafeLocalFree buffer = null;
uint result = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index,SafeLocalFree.Zero,ref size);
while (result == IpHelperErrors.ErrorBufferOverflow) {
try {
//now we allocate the buffer and read the network parameters.
buffer = SafeLocalFree.LocalAlloc((int)size);
result = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index,buffer,ref size);
if ( result == IpHelperErrors.Success ) {
IpPerAdapterInfo ipPerAdapterInfo = (IpPerAdapterInfo)Marshal.PtrToStructure(buffer.DangerousGetHandle(),typeof(IpPerAdapterInfo));
autoConfigEnabled = ipPerAdapterInfo.autoconfigEnabled;
autoConfigActive = ipPerAdapterInfo.autoconfigActive;
//get dnsAddresses
dnsAddresses = ipPerAdapterInfo.dnsServerList.ToIPAddressCollection();
}
}
finally {
if(dnsAddresses == null){
dnsAddresses = new IPAddressCollection();
}
if (buffer != null)
buffer.Close();
}
}
if(dnsAddresses == null){
dnsAddresses = new IPAddressCollection();
}
if (result != IpHelperErrors.Success) {
throw new NetworkInformationException((int)result);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
///
/// Provides support for ip configuation information and statistics.
///
///
namespace System.Net.NetworkInformation {
using System.Net;
using System.Net.Sockets;
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
using Microsoft.Win32;
internal class SystemIPv4InterfaceProperties:IPv4InterfaceProperties{
//these are only valid for ipv4 interfaces
bool haveWins = false;
bool dhcpEnabled = false;
bool routingEnabled = false;
bool autoConfigEnabled = false;
bool autoConfigActive = false;
uint index = 0;
uint mtu = 0;
//ipv4 addresses only
GatewayIPAddressInformationCollection gatewayAddresses = null;
IPAddressCollection dhcpAddresses = null;
IPAddressCollection winsServerAddresses = null;
internal IPAddressCollection dnsAddresses = null;
/*
// Consider removing.
internal SystemIPv4InterfaceProperties(){
}
*/
internal SystemIPv4InterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
{
index = ipAdapterInfo.index;
routingEnabled = fixedInfo.EnableRouting;
dhcpEnabled = ipAdapterInfo.dhcpEnabled;
haveWins = ipAdapterInfo.haveWins;
gatewayAddresses = ipAdapterInfo.gatewayList.ToIPGatewayAddressCollection();
dhcpAddresses = ipAdapterInfo.dhcpServer.ToIPAddressCollection();
IPAddressCollection primaryWinsServerAddresses = ipAdapterInfo.primaryWinsServer.ToIPAddressCollection();
IPAddressCollection secondaryWinsServerAddresses = ipAdapterInfo.secondaryWinsServer.ToIPAddressCollection();
//concat the winsserver addresses
winsServerAddresses = new IPAddressCollection();
foreach (IPAddress address in primaryWinsServerAddresses){
winsServerAddresses.InternalAdd(address);
}
foreach (IPAddress address in secondaryWinsServerAddresses){
winsServerAddresses.InternalAdd(address);
}
SystemIPv4InterfaceStatistics s = new SystemIPv4InterfaceStatistics(index);
mtu = (uint)s.Mtu;
if(ComNetOS.IsWin2K){
GetPerAdapterInfo(ipAdapterInfo.index);
}
else{
dnsAddresses = fixedInfo.DnsAddresses;
}
}
internal IPAddressCollection DnsAddresses{
get { return dnsAddresses; }
}
/// Only valid for Ipv4 Uses WINS for name resolution.
public override bool UsesWins{get {return haveWins;}}
public override bool IsDhcpEnabled{
get { return dhcpEnabled; }
}
public override bool IsForwardingEnabled{get {return routingEnabled;}} //proto
/// Auto configuration of an ipv4 address for a client
/// on a network where a DHCP server
/// isn't available.
public override bool IsAutomaticPrivateAddressingEnabled{
get{
return autoConfigEnabled;
}
} // proto
public override bool IsAutomaticPrivateAddressingActive{
get{
return autoConfigActive;
}
}
/// Specifies the Maximum transmission unit in bytes. Uses GetIFEntry.
//We cache this to be consistent across all platforms
public override int Mtu{
get {
return (int) mtu;
}
}
public override int Index{
get {
return (int) index;
}
}
/// IP Address of the default gateway.
internal GatewayIPAddressInformationCollection GetGatewayAddresses(){
return gatewayAddresses;
}
/// IP address of the DHCP sever.
internal IPAddressCollection GetDhcpServerAddresses(){
return dhcpAddresses;
}
/// IP addresses of the WINS servers.
internal IPAddressCollection GetWinsServersAddresses(){
return winsServerAddresses;
}
private void GetPerAdapterInfo(uint index) {
if (index != 0){
uint size = 0;
SafeLocalFree buffer = null;
uint result = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index,SafeLocalFree.Zero,ref size);
while (result == IpHelperErrors.ErrorBufferOverflow) {
try {
//now we allocate the buffer and read the network parameters.
buffer = SafeLocalFree.LocalAlloc((int)size);
result = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index,buffer,ref size);
if ( result == IpHelperErrors.Success ) {
IpPerAdapterInfo ipPerAdapterInfo = (IpPerAdapterInfo)Marshal.PtrToStructure(buffer.DangerousGetHandle(),typeof(IpPerAdapterInfo));
autoConfigEnabled = ipPerAdapterInfo.autoconfigEnabled;
autoConfigActive = ipPerAdapterInfo.autoconfigActive;
//get dnsAddresses
dnsAddresses = ipPerAdapterInfo.dnsServerList.ToIPAddressCollection();
}
}
finally {
if(dnsAddresses == null){
dnsAddresses = new IPAddressCollection();
}
if (buffer != null)
buffer.Close();
}
}
if(dnsAddresses == null){
dnsAddresses = new IPAddressCollection();
}
if (result != IpHelperErrors.Success) {
throw new NetworkInformationException((int)result);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ToolStripItemImageRenderEventArgs.cs
- HtmlInputText.cs
- FamilyCollection.cs
- XmlJsonWriter.cs
- WebPartTransformerAttribute.cs
- VideoDrawing.cs
- Style.cs
- loginstatus.cs
- DictionaryGlobals.cs
- CaseExpr.cs
- Matrix.cs
- NetCodeGroup.cs
- ScriptReferenceEventArgs.cs
- SqlSelectClauseBuilder.cs
- TemplatedAdorner.cs
- ParagraphVisual.cs
- XsltLoader.cs
- DataGridViewTextBoxColumn.cs
- LineServices.cs
- HttpCookie.cs
- TemplateBuilder.cs
- NativeMethodsCLR.cs
- Transform3DGroup.cs
- BamlRecordHelper.cs
- OLEDB_Util.cs
- InkCanvas.cs
- BufferedConnection.cs
- PermissionRequestEvidence.cs
- CodeAccessPermission.cs
- XPathNodePointer.cs
- AssemblyHash.cs
- TableStyle.cs
- LambdaCompiler.Unary.cs
- FacetDescriptionElement.cs
- SmiGettersStream.cs
- DefaultAsyncDataDispatcher.cs
- OpCodes.cs
- RichTextBox.cs
- StateWorkerRequest.cs
- ZoneLinkButton.cs
- WhitespaceRule.cs
- TraceFilter.cs
- SimpleTypesSurrogate.cs
- XmlValidatingReaderImpl.cs
- PerfService.cs
- Rule.cs
- XmlSchemaComplexType.cs
- CompositeDataBoundControl.cs
- TypeSystem.cs
- NamespaceCollection.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- ViewBox.cs
- ScopeElement.cs
- CodeArrayCreateExpression.cs
- ListBox.cs
- FontStyle.cs
- MailSettingsSection.cs
- BindableAttribute.cs
- HtmlInputPassword.cs
- MetadataItemSerializer.cs
- FontClient.cs
- UnsafeNativeMethodsPenimc.cs
- CommonObjectSecurity.cs
- WebPartConnection.cs
- EUCJPEncoding.cs
- BitmapEffect.cs
- StatusBarPanel.cs
- SqlTopReducer.cs
- DbSetClause.cs
- linebase.cs
- DataReceivedEventArgs.cs
- PerformanceCounterPermission.cs
- XmlAttributeAttribute.cs
- Padding.cs
- SQLInt32.cs
- EntityModelBuildProvider.cs
- ProcessProtocolHandler.cs
- CodeDomLoader.cs
- TypedReference.cs
- HttpRuntimeSection.cs
- JapaneseCalendar.cs
- HttpSessionStateBase.cs
- AddInActivator.cs
- FaultFormatter.cs
- ConstraintManager.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- DashStyles.cs
- SequenceFullException.cs
- DbProviderFactory.cs
- EntitySetRetriever.cs
- DispatchWrapper.cs
- Drawing.cs
- Soap.cs
- Matrix3D.cs
- MappingException.cs
- NativeActivityFaultContext.cs
- AutomationIdentifier.cs
- ComboBoxRenderer.cs
- DataGridHelper.cs
- MessageSecurityVersion.cs