public static CriticalAllocHandleSocketAddressList FromAddressList(ICollection<IPAddress> addresses)
 {
     if (addresses == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addresses");
     }
     int count = addresses.Count;
     CriticalAllocHandleSocketAddress[] addressArray = new CriticalAllocHandleSocketAddress[50];
     SocketAddressList structure = new SocketAddressList(new System.ServiceModel.Channels.SocketAddress[50], count);
     int index = 0;
     foreach (IPAddress address in addresses)
     {
         if (index == 50)
         {
             break;
         }
         addressArray[index] = CriticalAllocHandleSocketAddress.FromIPAddress(address);
         structure.Addresses[index].InitializeFromCriticalAllocHandleSocketAddress(addressArray[index]);
         index++;
     }
     CriticalAllocHandleSocketAddressList list2 = FromSize(Marshal.SizeOf(structure));
     list2.count = count;
     list2.socketHandles = addressArray;
     Marshal.StructureToPtr(structure, (IntPtr) list2, false);
     return list2;
 }
        public static CriticalAllocHandleSocketAddressList FromAddressList(ICollection <IPAddress> addresses)
        {
            if (addresses == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addresses");
            }
            int count = addresses.Count;

            CriticalAllocHandleSocketAddress[] addressArray = new CriticalAllocHandleSocketAddress[50];
            SocketAddressList structure = new SocketAddressList(new System.ServiceModel.Channels.SocketAddress[50], count);
            int index = 0;

            foreach (IPAddress address in addresses)
            {
                if (index == 50)
                {
                    break;
                }
                addressArray[index] = CriticalAllocHandleSocketAddress.FromIPAddress(address);
                structure.Addresses[index].InitializeFromCriticalAllocHandleSocketAddress(addressArray[index]);
                index++;
            }
            CriticalAllocHandleSocketAddressList list2 = FromSize(Marshal.SizeOf(structure));

            list2.count         = count;
            list2.socketHandles = addressArray;
            Marshal.StructureToPtr(structure, (IntPtr)list2, false);
            return(list2);
        }
        public static CriticalAllocHandleSocketAddressList FromAddressList(ICollection <IPAddress> addresses)
        {
            if (addresses == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addresses");
            }
            int count = addresses.Count;

            CriticalAllocHandleSocketAddress[] socketHandles = new CriticalAllocHandleSocketAddress[SocketAddressList.maxAddresses];
            SocketAddressList socketAddressList = new SocketAddressList(new SocketAddress[SocketAddressList.maxAddresses], count);
            int i = 0;

            foreach (IPAddress address in addresses)
            {
                if (i == SocketAddressList.maxAddresses)
                {
                    break;                                      // due to Marshalling fixed sized array of SocketAddresses.
                }
                socketHandles[i] = CriticalAllocHandleSocketAddress.FromIPAddress(address);
                socketAddressList.Addresses[i].InitializeFromCriticalAllocHandleSocketAddress(socketHandles[i]);
                ++i;
            }

            int size = Marshal.SizeOf(socketAddressList);
            CriticalAllocHandleSocketAddressList result = CriticalAllocHandleSocketAddressList.FromSize(size);

            result.count         = count;
            result.socketHandles = socketHandles;
            Marshal.StructureToPtr(socketAddressList, result, false);
            return(result);
        }
예제 #4
0
        public static CriticalAllocHandleSocketAddress FromIPAddress(IPAddress input)
        {
            if (input == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("input");
            }
            CriticalAllocHandleSocketAddress address = null;

            address = FromSize(Marshal.SizeOf(typeof(System.ServiceModel.Channels.sockaddr_in6)));
            System.ServiceModel.Channels.sockaddr_in6 structure = new System.ServiceModel.Channels.sockaddr_in6(input);
            Marshal.StructureToPtr(structure, (IntPtr)address, false);
            return(address);
        }
        public static new CriticalAllocHandleSocketAddress FromSize(int size)
        {
            CriticalAllocHandleSocketAddress result = new CriticalAllocHandleSocketAddress();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                result.SetHandle(Marshal.AllocHGlobal(size));
                result.size = size;
            }
            return(result);
        }
 public static CriticalAllocHandleSocketAddress FromSize(int size)
 {
     CriticalAllocHandleSocketAddress address = new CriticalAllocHandleSocketAddress();
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         address.SetHandle(Marshal.AllocHGlobal(size));
         address.size = size;
     }
     return address;
 }
        public static CriticalAllocHandleSocketAddress FromIPAddress(IPAddress input)
        {
            if (input == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("input");
            }

            CriticalAllocHandleSocketAddress result = null;
            int size = Marshal.SizeOf(typeof(sockaddr_in6));

            result = CriticalAllocHandleSocketAddress.FromSize(size);
            sockaddr_in6 sa = new sockaddr_in6(input);

            Marshal.StructureToPtr(sa, (IntPtr)result, false);
            return(result);
        }
 public void InitializeFromCriticalAllocHandleSocketAddress(CriticalAllocHandleSocketAddress sockAddr)
 {
     this.sockAddr       = (IntPtr)sockAddr;
     this.sockAddrLength = sockAddr.Size;
 }
 public void InitializeFromCriticalAllocHandleSocketAddress(CriticalAllocHandleSocketAddress sockAddr)
 {
     this.sockAddr = (IntPtr) sockAddr;
     this.sockAddrLength = sockAddr.Size;
 }