Beispiel #1
0
        /// <summary>
        /// Dumps each received packet to a pcap file
        /// </summary>
        private static void device_PcapOnPacketArrival(object sender, SharpPcap.CaptureEventArgs e)
        {
            SyslogMessage msg = null;

            try
            {
                Packet         link     = Packet.ParsePacket(LinkLayers.Ethernet, e.Packet.Data);
                EthernetPacket ethernet = (EthernetPacket)link;
                IpPacket       ip       = (IpPacket)ethernet.PayloadPacket;
                UdpPacket      udp      = (UdpPacket)ip.PayloadPacket;
                msg = new SyslogMessage(udp);
                outputFile.WriteLine(System.Text.Encoding.ASCII.GetString(udp.PayloadData));
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("SwsyslogService", ex.ToString(), EventLogEntryType.Error);
            }


            // if the output file is ready to write, write the log file ...
            if (msg != null && outputFile.BaseStream.CanWrite)
            {
                //outputFile.WriteLine(msg.ToString());
            }

            _logEntryCount++;
        }
Beispiel #2
0
        /// <summary>
        /// Dumps each received packet to a pcap file
        /// </summary>
        private static void device_PcapOnPacketArrival(object sender, SharpPcap.CaptureEventArgs e)
        {
            SyslogMessage msg = null;

            try
            {
                Packet link =  Packet.ParsePacket(LinkLayers.Ethernet, e.Packet.Data);
                EthernetPacket ethernet = (EthernetPacket)link;
                IpPacket ip = (IpPacket)ethernet.PayloadPacket;
                UdpPacket udp = (UdpPacket)ip.PayloadPacket;
                msg = new SyslogMessage(udp);
                outputFile.WriteLine(System.Text.Encoding.ASCII.GetString(udp.PayloadData));
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("SwsyslogService", ex.ToString(), EventLogEntryType.Error);
            }

            // if the output file is ready to write, write the log file ...
            if (msg != null && outputFile.BaseStream.CanWrite)
            {
                //outputFile.WriteLine(msg.ToString());
            }

            _logEntryCount++;
        }