Exemplo n.º 1
0
        /// <summary>
        /// Open
        /// </summary>
        /// <param name="flags">
        /// A <see cref="OpenFlags"/>
        /// </param>
        /// <param name="readTimeoutMilliseconds">
        /// A <see cref="int"/>
        /// </param>
        /// <param name="remoteAuthentication">
        /// A <see cref="RemoteAuthentication"/>
        /// </param>
        public void Open(OpenFlags flags,
                         int readTimeoutMilliseconds,
                         RemoteAuthentication remoteAuthentication)
        {
            if (!Opened)
            {
                var errbuf = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE); //will hold errors

                var auth = RemotePcap.CreateAuth(Name, remoteAuthentication);

                PcapHandle = LibPcapSafeNativeMethods.pcap_open(Name,
                                                                Pcap.MAX_PACKET_SIZE, // portion of the packet to capture.
                                                                (int)flags,
                                                                readTimeoutMilliseconds,
                                                                ref auth,
                                                                errbuf);

                if (PcapHandle == IntPtr.Zero)
                {
                    string err = "Unable to open the adapter (" + Name + "). " + errbuf.ToString();
                    throw new PcapException(err);
                }

                Active = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open a device with specific flags
        /// WinPcap extension - Use of this method will exclude your application
        ///                     from working on Linux or Mac
        /// </summary>
        public virtual void Open(OpenFlags flags, int read_timeout)
        {
            ThrowIfNotWinPcap();

            if (!Opened)
            {
                var errbuf = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE);
                var auth   = RemotePcap.CreateAuth(Name, Interface.Credentials);

                PcapHandle = LibPcapSafeNativeMethods.pcap_open
                                 (Name,                // name of the device
                                 Pcap.MAX_PACKET_SIZE, // portion of the packet to capture.
                                                       // MAX_PACKET_SIZE (65536) grants that the whole packet will be captured on all the MACs.
                                 (short)flags,         // one or more flags
                                 (short)read_timeout,  // read timeout
                                 ref auth,             // no authentication right now
                                 errbuf);              // error buffer

                if (PcapHandle == IntPtr.Zero)
                {
                    string err = "Unable to open the adapter (" + Name + "). " + errbuf.ToString();
                    throw new PcapException(err);
                }

                Active = true;
            }
        }
Exemplo n.º 3
0
 private static string TimestampDescription(TimestampType number)
 {
     return(LibPcapSafeNativeMethods.pcap_tstamp_type_val_to_description((int)number));
 }
Exemplo n.º 4
0
 private static string TimestampName(TimestampType number)
 {
     return(LibPcapSafeNativeMethods.pcap_tstamp_type_val_to_name((int)number));
 }