コード例 #1
0
ファイル: Socket.cs プロジェクト: LipkeGu/bootpd
        internal void OnDataReceived(byte[] data, IPEndPoint endpoint, SocketType type)
        {
            var evtargs = new DataReceivedEventArgs();
            evtargs.Type = type;
            evtargs.Data = data;
            evtargs.RemoteEndpoint = endpoint;

            if (this.DataReceived != null)
                this.DataReceived(this, evtargs);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: LipkeGu/bootpd
 internal abstract void DataReceived(object sender, DataReceivedEventArgs e);
コード例 #3
0
ファイル: TFTP.cs プロジェクト: LipkeGu/bootpd
        internal override void DataReceived(object sender, DataReceivedEventArgs e)
        {
            lock (this)
            {
                var request = new TFTPPacket(e.Data.Length, TFTPOPCodes.UNK, e.RemoteEndpoint);
                request.Data = e.Data;

                request.Type = SocketType.TFTP;

                switch (request.OPCode)
                {
                    case TFTPOPCodes.RRQ:
                        var rrq_thread = new Thread(new ParameterizedThreadStart(Handle_RRQ_Request));
                        rrq_thread.Start(request);
                        break;
                    case TFTPOPCodes.ERR:
                        this.Handle_Error_Request(request.ErrorCode, request.ErrorMessage, request.Source, true);
                        break;
                    case TFTPOPCodes.ACK:
                        if (!Clients.ContainsKey(request.Source.Address))
                            return;

                        var ack_thread = new Thread(new ParameterizedThreadStart(Handle_ACK_Request));
                        ack_thread.Start(request);
                        break;
                    default:
                        this.Handle_Error_Request(TFTPErrorCode.IllegalOperation, "Unknown OPCode: {0}".F(request.OPCode), request.Source);
                        break;
                }
            }
        }
コード例 #4
0
ファイル: DHCP.cs プロジェクト: LipkeGu/bootpd
        internal override void DataReceived(object sender, DataReceivedEventArgs e)
        {
            switch (int.Parse(Exts.GetDataAsString(e.Data, 0, 1)))
            {
                case (int)BootMessageType.Request:
                    #region "BOTP - Request"
                    using (var request = new DHCPPacket(e.Data))
                    {
                        request.Type = e.Type;

                        var optvalue = Exts.GetOptionValue(e.Data, DHCPOptionEnum.Vendorclassidentifier);
                        if (optvalue.Length < 1 || optvalue[0] == byte.MaxValue || e.Data[0] != (byte)BootMessageType.Request)
                            return;

                        var cguid = Exts.GetOptionValue(request.Data, DHCPOptionEnum.GUID);
                        if (cguid.Length == 1)
                            return;

                        var guid = Guid.Parse(Exts.GetGuidAsString(cguid, cguid.Length, true));

                        var clientMAC = Exts.GetDataAsString(request.MacAddress, 0, request.MACAddresslength);
                        var clientTag = "{0}-{1}".F(guid, clientMAC);

                        if (!Clients.ContainsKey(clientTag))
                            Clients.Add(clientTag, new DHCPClient(guid, clientMAC, request.Type, e.RemoteEndpoint));
                        else
                        {
                            Clients[clientTag].Type = request.Type;
                            Clients[clientTag].EndPoint = e.RemoteEndpoint;
                        }

                        var c = Clients[clientTag];
                        switch (request.MessageType)
                        {
                            case DHCPMsgType.Request:
                                if (e.RemoteEndpoint.Address != IPAddress.None)
                                    this.Handle_DHCP_Request(request, ref c);
                                break;
                            case DHCPMsgType.Discover:
                                this.Handle_DHCP_Request(request, ref c);
                                break;
                            case DHCPMsgType.Release:
                                if (Clients.ContainsKey(clientTag))
                                    Clients.Remove(clientTag);
                                break;
                            default:
                                return;
                        }
                    }
                    #endregion
                    break;
                case (int)BootMessageType.RISRequest:
                    #region "RIS - Request"
                    var packet = new RISPacket(e.Data);
                    var client = new RISClient(e.RemoteEndpoint);

                    switch (packet.RequestType)
                    {
                        case "RQU":
                        case "REQ":
                            packet.OPCode = packet.RequestType == "REQ" ? RISOPCodes.REQ : RISOPCodes.RQU;
                            this.Handle_RIS_Request(packet, ref client, packet.RequestType == "REQ" ? true : false);
                            break;
                        case "NEG":
                        case "AUT":
                            packet.OPCode = packet.RequestType == "NEG" ? RISOPCodes.NEG : RISOPCodes.AUT;
                            this.Handle_RIS_Request(packet, ref client);
                            break;
                        case "NCQ":
                            packet.OPCode = RISOPCodes.NCQ;
                            this.Handle_RIS_Request(packet, ref client);
                            break;
                        default:
                            Errorhandler.Report(LogTypes.Info, "Got Unknown RIS Packet ({0})".F(packet.RequestType));
                            break;
                    }
                    #endregion
                    break;
                case (int)BootMessageType.RISReply:
                default:
                    break;
            }
        }