Esempio n. 1
0
        //private void DataReceived(object o)
        private void DataSocket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                var reader = args.GetDataReader();

                byte[] data = new byte[reader.UnconsumedBufferLength];
                args.GetDataReader().ReadBytes(data);

                this.socket = sender;

                var dhcpRequest = new DHCPRequest(data, socket, this);
                //ccDHCP = new clsDHCP();


                //data is now in the structure
                //get the msg type
                OnDataReceived(this, dhcpRequest);
                var msgType = dhcpRequest.GetMsgType();
                switch (msgType)
                {
                case DHCPMsgType.DHCPDISCOVER:
                    OnDiscover(this, dhcpRequest);
                    break;

                case DHCPMsgType.DHCPREQUEST:
                    OnRequest(this, dhcpRequest);
                    break;

                case DHCPMsgType.DHCPDECLINE:
                    OnDecline(this, dhcpRequest);
                    break;

                case DHCPMsgType.DHCPRELEASE:
                    OnReleased(this, dhcpRequest);
                    break;

                case DHCPMsgType.DHCPINFORM:
                    OnInform(this, dhcpRequest);
                    break;
                    //default:
                    //    Console.WriteLine("Unknown DHCP message: " + (int)MsgTyp + " (" + MsgTyp.ToString() + ")");
                    //    break;
                }
            }
            catch (Exception ex)
            {
                if (UnhandledException != null)
                {
                    UnhandledException(this, ex);
                }
            }
        }
Esempio n. 2
0
        private void DataReceived(object o)
        {
            var data = (byte[])o;

            try
            {
                //var dhcpRequest = new DHCPRequest(data, socket, this);
                //ccDHCP = new clsDHCP();
                DHCPRequest dhcpRequest = new DHCPRequest(data, udp, this);


                //data is now in the structure
                //get the msg type
                OnDataReceived(dhcpRequest);
                var msgType = dhcpRequest.GetMsgType();
                Util.log(String.Format("Message type: {0}", msgType.ToString()));
                switch (msgType)
                {
                case DHCPMsgType.DHCPDISCOVER:
                    OnDiscover(dhcpRequest);
                    break;

                case DHCPMsgType.DHCPREQUEST:
                    OnRequest(dhcpRequest);
                    break;

                case DHCPMsgType.DHCPDECLINE:
                    OnDecline(dhcpRequest);
                    break;

                case DHCPMsgType.DHCPRELEASE:
                    OnReleased(dhcpRequest);
                    break;

                case DHCPMsgType.DHCPINFORM:
                    OnInform(dhcpRequest);
                    break;
                    //default:
                    //    Console.WriteLine("Unknown DHCP message: " + (int)MsgTyp + " (" + MsgTyp.ToString() + ")");
                    //    break;
                }
            }
            catch (Exception ex)
            {
                Util.log(ex.Message);
                Util.log(ex.StackTrace);
                if (UnhandledException != null)
                {
                    UnhandledException(ex);
                }
            }
        }