Inheritance: UdpPlatform
Exemple #1
0
 public override int SendTo(byte[] buffer, int bytesToSend, UdpEndPoint endpoint) {
   try {
     return socket.SendTo(buffer, 0, bytesToSend, SocketFlags.None, DotNetPlatform.ConvertEndPoint(endpoint));
   }
   catch (SocketException exn) {
     HandleSocketException(exn);
     return -1;
   }
 }
Exemple #2
0
        public UdpAdpaterConnection(int userdata)
        {
            UdpLog.SetWriter(new UdpLog.Writer(UdpLogWriter));

            UdpPlatform udpPlatform = new DotNetPlatform();

            socket = new UdpSocket(udpPlatform);
            CreateStreamChannel(1, "Default.Udp.StreamChannel", true, 9);
            socket.Start(UdpEndPoint.Any, UdpSocketMode.Client);
            totalTime = 0L;
            beginTime = 0L;
        }
Exemple #3
0
  public override void Bind(UdpEndPoint ep) {
    try {
      error = null;
      socket.Bind(DotNetPlatform.ConvertEndPoint(ep));

      endpoint = DotNetPlatform.ConvertEndPoint(socket.LocalEndPoint);

      UdpLog.Info("Socket bound to {0}", endpoint);
    }
    catch (SocketException exn) {
      HandleSocketException(exn);
    }
  }
Exemple #4
0
 public override UdpIPv4Address[] ResolveHostAddresses(string host)
 {
     if (host == null)
     {
         throw new ArgumentNullException("host", "argument was null");
     }
     if (host.Length == 0)
     {
         throw new ArgumentException("host name was empty", "host");
     }
     return((from x in Dns.GetHostAddresses(host)
             select DotNetPlatform.ConvertAddress(x)).ToArray <UdpIPv4Address>());
 }
Exemple #5
0
  public DotNetSocket(DotNetPlatform platform) {
    this.platform = platform;

    try {
      socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
      socket.Blocking = false;

      SetConnReset(socket);
    }
    catch (SocketException exn) {
      HandleSocketException(exn);
    }

    recvEndPoint = new IPEndPoint(IPAddress.Any, 0);
  }
Exemple #6
0
    public DotNetSocket(DotNetPlatform platform)
    {
        this.platform = platform;

        try {
          socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
          socket.Blocking = false;

          SetConnReset(socket);
        }
        catch (SocketException exn) {
          HandleSocketException(exn);
        }

        recvEndPoint = new IPEndPoint(IPAddress.Any, 0);
    }
Exemple #7
0
  public override int RecvFrom(byte[] buffer, int bufferSize, ref UdpEndPoint endpoint) {
    try {
      int bytesReceived = socket.ReceiveFrom(buffer, 0, bufferSize, SocketFlags.None, ref recvEndPoint);

      if (bytesReceived > 0) {
        endpoint = DotNetPlatform.ConvertEndPoint(recvEndPoint);
        return bytesReceived;
      }
      else {
        return -1;
      }
    }
    catch (SocketException exn) {
      HandleSocketException(exn);
      return -1;
    }
  }
Exemple #8
0
 public override void Bind(UdpEndPoint ep)
 {
     try
     {
         this.error = null;
         this.socket.Bind(DotNetPlatform.ConvertEndPoint(ep));
         this.endpoint = DotNetPlatform.ConvertEndPoint(this.socket.LocalEndPoint);
         UdpLog.Info("Socket bound to {0}", new object[]
         {
             this.endpoint
         });
     }
     catch (SocketException exn)
     {
         this.HandleSocketException(exn);
     }
 }
        /// <summary>
        /// Create a Processor, indicating whether it is to be schema-aware.
        /// </summary>
        /// <param name="schemaAware">Set to true if the Processor is to be schema-aware.
        /// This requires the Saxon-SA product to be installed, with a valid license key.</param>
        /// <param name="loadLocally">This option has no effect at this release.</param>

        public Processor(bool schemaAware, bool loadLocally)
        {
            if (schemaAware)
            {
                //if (loadLocally) {
                //    Assembly asm = Assembly.Load("saxon8sa");
                //} else {
                //    try {
                //        int[] v = JVersion.getStructuredVersionNumber();
                //        AssemblyName asn = new AssemblyName();
                //        asn.Name = "saxon8sa";
                //        asn.Version = new Version(v[0], v[1], v[2], v[3]);
                //        //asn.Version = new Version(JVersion.getMajorVersion(), JVersion.getMinorVersion());
                //        asn.SetPublicKeyToken(new byte[] { 0xe1, 0xfd, 0xd0, 0x02, 0xd5, 0x08, 0x3f, 0xe6 });
                //        asn.CultureInfo = new CultureInfo("");
                //        Assembly asm = Assembly.Load(asn);
                //        // try to load the saxon8sa.dll assembly
                //        //Assembly asm = Assembly.Load("saxon8sa, Ver=" + JVersion.getProductVersion() + ".0.1, " +
                //        //    @"SN=e1fdd002d5083fe6, Loc=neutral");
                //    } catch (Exception e) {
                //        Console.WriteLine("Cannot load Saxon-SA software (assembly saxon8sa.dll version " +
                //            JVersion.getProductVersion() + ".0.1)");
                //        throw e;
                //    }
                //}
                config = JConfiguration.makeSchemaAwareConfiguration(null,
                                                                     DotNetPlatform.getSaxonSaFullyQualifiedClassName());
                //config = new com.saxonica.validate.SchemaAwareConfiguration();
                schemaManager = new SchemaManager(config);
            }
            else
            {
                config = new JConfiguration();
            }
            config.setURIResolver(new DotNetURIResolver(new XmlUrlResolver()));
            config.setCollectionURIResolver(new DotNetCollectionURIResolver());
        }
Exemple #10
0
    public override int RecvFrom(byte[] buffer, int bufferSize, ref UdpEndPoint endpoint)
    {
        int result;

        try
        {
            int num = this.socket.ReceiveFrom(buffer, 0, bufferSize, SocketFlags.None, ref this.recvEndPoint);
            if (num > 0)
            {
                endpoint = DotNetPlatform.ConvertEndPoint(this.recvEndPoint);
                result   = num;
            }
            else
            {
                result = -1;
            }
        }
        catch (SocketException exn)
        {
            this.HandleSocketException(exn);
            result = -1;
        }
        return(result);
    }
Exemple #11
0
 public override UdpIPv4Address GetBroadcastAddress()
 {
     return(new UdpIPv4Address(DotNetPlatform.FindBroadcastAddress(true).Address));
 }
Exemple #12
0
    private static IPAddress FindBroadcastAddress(bool strict)
    {
        NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
        NetworkInterface[] array = allNetworkInterfaces;
        int i = 0;

        while (i < array.Length)
        {
            NetworkInterface     networkInterface     = array[i];
            NetworkInterfaceType networkInterfaceType = networkInterface.NetworkInterfaceType;
            switch (networkInterfaceType)
            {
            case NetworkInterfaceType.FastEthernetFx:
            case NetworkInterfaceType.Wireless80211:
                goto IL_59;

            case (NetworkInterfaceType)70:
IL_31:
                if (networkInterfaceType != NetworkInterfaceType.Ethernet && networkInterfaceType != NetworkInterfaceType.Ethernet3Megabit && networkInterfaceType != NetworkInterfaceType.FastEthernetT && networkInterfaceType != NetworkInterfaceType.GigabitEthernet)
                {
                    goto IL_182;
                }
                goto IL_59;
            }
            goto IL_31;
IL_182:
            i++;
            continue;
IL_59:
            if (networkInterface.OperationalStatus == OperationalStatus.Up || networkInterface.OperationalStatus == OperationalStatus.Unknown)
            {
                IPInterfaceProperties iPProperties = networkInterface.GetIPProperties();
                if (!strict || DotNetPlatform.IsValidInterface(networkInterface, iPProperties))
                {
                    foreach (UnicastIPAddressInformation current in iPProperties.UnicastAddresses)
                    {
                        if (current.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            IPAddress result;
                            if (iPProperties.DhcpServerAddresses.Count == 0 && !strict)
                            {
                                byte[] addressBytes = current.Address.GetAddressBytes();
                                addressBytes[3] = 255;
                                result          = new IPAddress(addressBytes);
                                return(result);
                            }
                            byte[] addressBytes2 = iPProperties.DhcpServerAddresses[0].GetAddressBytes();
                            byte[] addressBytes3 = current.IPv4Mask.GetAddressBytes();
                            byte[] array2        = new byte[4];
                            for (int j = 0; j < addressBytes2.Length; j++)
                            {
                                array2[j] = ((addressBytes2[j] & addressBytes3[j]) | ~addressBytes3[j]);
                            }
                            result = new IPAddress(array2);
                            return(result);
                        }
                    }
                }
            }
            goto IL_182;
        }
        if (strict)
        {
            return(DotNetPlatform.FindBroadcastAddress(false));
        }
        return(IPAddress.Any);
    }
Exemple #13
0
 public static UdpEndPoint ConvertEndPoint(EndPoint endpoint)
 {
     return(DotNetPlatform.ConvertEndPoint((IPEndPoint)endpoint));
 }
Exemple #14
0
    private DotNetInterface ParseInterface(NetworkInterface n)
    {
        HashSet <UdpIPv4Address> hashSet  = new HashSet <UdpIPv4Address>(UdpIPv4Address.Comparer.Instance);
        HashSet <UdpIPv4Address> hashSet2 = new HashSet <UdpIPv4Address>(UdpIPv4Address.Comparer.Instance);
        HashSet <UdpIPv4Address> hashSet3 = new HashSet <UdpIPv4Address>(UdpIPv4Address.Comparer.Instance);
        IPInterfaceProperties    iPInterfaceProperties = null;

        try
        {
            iPInterfaceProperties = n.GetIPProperties();
        }
        catch
        {
            return(null);
        }
        if (iPInterfaceProperties != null)
        {
            try
            {
                foreach (GatewayIPAddressInformation current in iPInterfaceProperties.GatewayAddresses)
                {
                    try
                    {
                        if (current.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            hashSet.Add(DotNetPlatform.ConvertAddress(current.Address));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            try
            {
                foreach (IPAddress current2 in iPInterfaceProperties.DnsAddresses)
                {
                    try
                    {
                        if (current2.AddressFamily == AddressFamily.InterNetwork)
                        {
                            hashSet.Add(DotNetPlatform.ConvertAddress(current2));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            try
            {
                foreach (UnicastIPAddressInformation current3 in iPInterfaceProperties.UnicastAddresses)
                {
                    try
                    {
                        if (current3.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            UdpIPv4Address item = DotNetPlatform.ConvertAddress(current3.Address);
                            hashSet2.Add(item);
                            hashSet.Add(new UdpIPv4Address(item.Byte3, item.Byte2, item.Byte1, 1));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            try
            {
                foreach (MulticastIPAddressInformation current4 in iPInterfaceProperties.MulticastAddresses)
                {
                    try
                    {
                        if (current4.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            hashSet3.Add(DotNetPlatform.ConvertAddress(current4.Address));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            if (hashSet2.Count == 0 || hashSet.Count == 0)
            {
                return(null);
            }
        }
        return(new DotNetInterface(n, hashSet.ToArray <UdpIPv4Address>(), hashSet2.ToArray <UdpIPv4Address>(), hashSet3.ToArray <UdpIPv4Address>()));
    }
Exemple #15
0
    private static IPAddress FindBroadcastAddress(bool strict)
    {
        NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
        NetworkInterface[] array = allNetworkInterfaces;
        int i = 0;

        while (i < array.Length)
        {
            NetworkInterface     networkInterface     = array[i];
            NetworkInterfaceType networkInterfaceType = networkInterface.NetworkInterfaceType;
            switch (networkInterfaceType)
            {
            case NetworkInterfaceType.FastEthernetFx:
            case NetworkInterfaceType.Wireless80211:
                goto IL_59;

            default:
                if (networkInterfaceType == NetworkInterfaceType.Ethernet || networkInterfaceType == NetworkInterfaceType.Ethernet3Megabit || networkInterfaceType == NetworkInterfaceType.FastEthernetT || networkInterfaceType == NetworkInterfaceType.GigabitEthernet)
                {
                    goto IL_59;
                }
                break;
            }
IL_184:
            i++;
            continue;
IL_59:
            if (networkInterface.OperationalStatus == OperationalStatus.Up || networkInterface.OperationalStatus == OperationalStatus.Unknown)
            {
                IPInterfaceProperties ipproperties = networkInterface.GetIPProperties();
                if (!strict || DotNetPlatform.IsValidInterface(networkInterface, ipproperties))
                {
                    foreach (UnicastIPAddressInformation unicastIPAddressInformation in ipproperties.UnicastAddresses)
                    {
                        if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            if (ipproperties.DhcpServerAddresses.Count == 0 && !strict)
                            {
                                byte[] addressBytes = unicastIPAddressInformation.Address.GetAddressBytes();
                                addressBytes[3] = byte.MaxValue;
                                return(new IPAddress(addressBytes));
                            }
                            byte[] addressBytes2 = ipproperties.DhcpServerAddresses[0].GetAddressBytes();
                            byte[] addressBytes3 = unicastIPAddressInformation.IPv4Mask.GetAddressBytes();
                            byte[] array2        = new byte[4];
                            for (int j = 0; j < addressBytes2.Length; j++)
                            {
                                array2[j] = ((addressBytes2[j] & addressBytes3[j]) | ~addressBytes3[j]);
                            }
                            return(new IPAddress(array2));
                        }
                    }
                }
            }
            goto IL_184;
        }
        if (strict)
        {
            return(DotNetPlatform.FindBroadcastAddress(false));
        }
        return(IPAddress.Any);
    }