Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / SystemNet / Net / PeerToPeer / SystemNetHelpers.cs / 1 / SystemNetHelpers.cs
namespace System.Net.PeerToPeer { using System; using System.Net; using System.Net.Sockets; using System.Collections.Generic; using System.Text; using System.Security.Permissions; internal static class SystemNetHelpers { internal const int IPv6AddressSize = 28; internal const int IPv4AddressSize = 16; internal static byte[] SOCKADDRFromIPEndPoint(IPEndPoint ipEndPoint) { byte[] buffer = new byte[ipEndPoint.AddressFamily == AddressFamily.InterNetworkV6 ? IPv6AddressSize : IPv4AddressSize]; #if BIGENDIAN buffer[0] = unchecked((byte)((int)family>>8)); buffer[1] = unchecked((byte)((int)family )); #else buffer[0] = unchecked((byte)((int)ipEndPoint.AddressFamily)); buffer[1] = unchecked((byte)((int)ipEndPoint.AddressFamily >> 8)); #endif if (ipEndPoint.AddressFamily == AddressFamily.InterNetworkV6) { buffer[2] = (byte)(ipEndPoint.Port >> 8); buffer[3] = (byte)ipEndPoint.Port; buffer[4] = (byte)0; buffer[5] = (byte)0; buffer[6] = (byte)0; buffer[7] = (byte)0; long scope = ipEndPoint.Address.ScopeId; buffer[24] = (byte)scope; buffer[25] = (byte)(scope >> 8); buffer[26] = (byte)(scope >> 16); buffer[27] = (byte)(scope >> 24); byte[] addressBytes = ipEndPoint.Address.GetAddressBytes(); for (int i = 0; i < addressBytes.Length; i++) { buffer[8 + i] = addressBytes[i]; } } else { buffer[2] = unchecked((byte)(ipEndPoint.Port >> 8)); buffer[3] = unchecked((byte)(ipEndPoint.Port)); byte[] addressBytes = ipEndPoint.Address.GetAddressBytes(); for (int i = 0; i < addressBytes.Length; i++) { buffer[4 + i] = addressBytes[i]; } } return buffer; } internal static IPEndPoint IPEndPointFromSOCKADDRBuffer(byte[] buffer) { IPAddress ip = null; int addressFamily = 0; #if BIGENDIAN addressFamily = buffer[1] + ((int)buffer[0] << 8); #else addressFamily = buffer[0] + ((int)buffer[1] << 8); #endif //Get port int port = buffer[3] + ((int)buffer[2] << 8); if ((AddressFamily)addressFamily == AddressFamily.InterNetwork) { byte[] v4bytes = new byte[] { buffer[4], buffer[5], buffer[6], buffer[7] }; ip = new IPAddress(v4bytes); } else if ((AddressFamily)addressFamily == AddressFamily.InterNetworkV6) { byte[] v6Bytes = new byte[16]; for (int i = 0; i < 16; i++) v6Bytes[i] = buffer[8 + i]; long scope = ((long)(long)buffer[24] + ((long)buffer[25] << 8) + ((long)buffer[26] << 16) + ((long)buffer[27] << 24)); ip = new IPAddress(v6Bytes); ip.ScopeId = scope; } return new IPEndPoint(ip, port); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Net.PeerToPeer { using System; using System.Net; using System.Net.Sockets; using System.Collections.Generic; using System.Text; using System.Security.Permissions; internal static class SystemNetHelpers { internal const int IPv6AddressSize = 28; internal const int IPv4AddressSize = 16; internal static byte[] SOCKADDRFromIPEndPoint(IPEndPoint ipEndPoint) { byte[] buffer = new byte[ipEndPoint.AddressFamily == AddressFamily.InterNetworkV6 ? IPv6AddressSize : IPv4AddressSize]; #if BIGENDIAN buffer[0] = unchecked((byte)((int)family>>8)); buffer[1] = unchecked((byte)((int)family )); #else buffer[0] = unchecked((byte)((int)ipEndPoint.AddressFamily)); buffer[1] = unchecked((byte)((int)ipEndPoint.AddressFamily >> 8)); #endif if (ipEndPoint.AddressFamily == AddressFamily.InterNetworkV6) { buffer[2] = (byte)(ipEndPoint.Port >> 8); buffer[3] = (byte)ipEndPoint.Port; buffer[4] = (byte)0; buffer[5] = (byte)0; buffer[6] = (byte)0; buffer[7] = (byte)0; long scope = ipEndPoint.Address.ScopeId; buffer[24] = (byte)scope; buffer[25] = (byte)(scope >> 8); buffer[26] = (byte)(scope >> 16); buffer[27] = (byte)(scope >> 24); byte[] addressBytes = ipEndPoint.Address.GetAddressBytes(); for (int i = 0; i < addressBytes.Length; i++) { buffer[8 + i] = addressBytes[i]; } } else { buffer[2] = unchecked((byte)(ipEndPoint.Port >> 8)); buffer[3] = unchecked((byte)(ipEndPoint.Port)); byte[] addressBytes = ipEndPoint.Address.GetAddressBytes(); for (int i = 0; i < addressBytes.Length; i++) { buffer[4 + i] = addressBytes[i]; } } return buffer; } internal static IPEndPoint IPEndPointFromSOCKADDRBuffer(byte[] buffer) { IPAddress ip = null; int addressFamily = 0; #if BIGENDIAN addressFamily = buffer[1] + ((int)buffer[0] << 8); #else addressFamily = buffer[0] + ((int)buffer[1] << 8); #endif //Get port int port = buffer[3] + ((int)buffer[2] << 8); if ((AddressFamily)addressFamily == AddressFamily.InterNetwork) { byte[] v4bytes = new byte[] { buffer[4], buffer[5], buffer[6], buffer[7] }; ip = new IPAddress(v4bytes); } else if ((AddressFamily)addressFamily == AddressFamily.InterNetworkV6) { byte[] v6Bytes = new byte[16]; for (int i = 0; i < 16; i++) v6Bytes[i] = buffer[8 + i]; long scope = ((long)(long)buffer[24] + ((long)buffer[25] << 8) + ((long)buffer[26] << 16) + ((long)buffer[27] << 24)); ip = new IPAddress(v6Bytes); ip.ScopeId = scope; } return new IPEndPoint(ip, port); } } } // 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
- WizardStepBase.cs
- KeyedQueue.cs
- AudioFormatConverter.cs
- InitializationEventAttribute.cs
- LoginUtil.cs
- TimelineGroup.cs
- SafeHandles.cs
- FillRuleValidation.cs
- OdbcTransaction.cs
- DependentTransaction.cs
- NetCodeGroup.cs
- httpapplicationstate.cs
- StaticTextPointer.cs
- PrtCap_Reader.cs
- InfoCardX509Validator.cs
- pingexception.cs
- GridItemProviderWrapper.cs
- EventSinkActivity.cs
- MasterPage.cs
- ContentValidator.cs
- MailWebEventProvider.cs
- ResourceAttributes.cs
- IpcClientChannel.cs
- Int64AnimationBase.cs
- RoutedPropertyChangedEventArgs.cs
- CodeExpressionStatement.cs
- BamlRecordReader.cs
- CheckBoxPopupAdapter.cs
- DBAsyncResult.cs
- SettingsBase.cs
- ViewBox.cs
- DataProtection.cs
- RandomNumberGenerator.cs
- XmlImplementation.cs
- TableDesigner.cs
- PagerSettings.cs
- ProxyWebPartManager.cs
- MenuCommand.cs
- BamlCollectionHolder.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- ConsumerConnectionPoint.cs
- GridViewCancelEditEventArgs.cs
- AndMessageFilterTable.cs
- SqlConnectionManager.cs
- DataServiceProcessingPipelineEventArgs.cs
- PlainXmlDeserializer.cs
- ComplexType.cs
- XPathAxisIterator.cs
- AutomationElement.cs
- ReceiveActivityDesigner.cs
- AffineTransform3D.cs
- NamespaceCollection.cs
- TypedElement.cs
- FontFamily.cs
- InvokeGenerator.cs
- IsolatedStorageSecurityState.cs
- DelegatingStream.cs
- Update.cs
- CommandLibraryHelper.cs
- RegexCapture.cs
- ObservableCollection.cs
- DrawingContextWalker.cs
- PermissionSetEnumerator.cs
- NumberSubstitution.cs
- HttpRuntimeSection.cs
- Slider.cs
- RawTextInputReport.cs
- BuildProvider.cs
- SqlParameter.cs
- SecurityIdentifierElementCollection.cs
- AccessedThroughPropertyAttribute.cs
- TextElement.cs
- ButtonPopupAdapter.cs
- TokenCreationParameter.cs
- StylusDevice.cs
- XmlWriter.cs
- UnmanagedHandle.cs
- _SslState.cs
- CodeAttributeArgumentCollection.cs
- Serializer.cs
- IpcPort.cs
- ProcessMessagesAsyncResult.cs
- CollectionContainer.cs
- XmlHierarchyData.cs
- ClientCultureInfo.cs
- RotateTransform.cs
- filewebresponse.cs
- ColumnHeaderCollectionEditor.cs
- ReflectTypeDescriptionProvider.cs
- XmlUtf8RawTextWriter.cs
- CompiledAction.cs
- ConnectionPoolManager.cs
- RijndaelManaged.cs
- recordstatefactory.cs
- ScrollChrome.cs
- AttributeEmitter.cs
- AsyncStreamReader.cs
- BindingOperations.cs
- ProfilePropertyNameValidator.cs
- MultiDataTrigger.cs