示例#1
0
 public void Open(string name)
 {
     byte[] err = new byte[256];
     fixed(byte *pErr = &err[0])
     {
         handle = LibPcap.pcap_open(name, 68, 0, 0, null, pErr);
         if (handle == null)
         {
             throw new LibPcapException(Encoding.ASCII.GetString(err));
         }
     }
 }
示例#2
0
        public Packet Next()
        {
            pcap_pkthdr *header = null;
            byte *       data   = null;
            int          result = LibPcap.pcap_next_ex(handle, ref header, ref data);

            if (result == 1)
            {
                return(new Packet(ref *header, data));
            }
            else if (result == 0)
            {
                return(null);
            }
            else if (result == -2)
            {
                throw new EndOfStreamException();
            }
            else
            {
                throw new LibPcapException("error");
            }
        }
示例#3
0
 public void Close()
 {
     LibPcap.pcap_close(handle);
 }