0

pcap ファイルの抽出に Jnetpcap 1.3.0 バージョンを使用しています。

以下は私のコードスニペットです

  /* Main Class */
    public class Proceed{

 public static void main(String[] args) {

  PCapFile pcapFile = new PCapFile("C:/test/no-gre-sample.pcap");
  pcapFile.process();

  }
 }

 /in some other class I have written this method */

  public void process() {
  RandomAccessFile raf = null;
  FileLock lock = null;
  try {
     raf = new RandomAccessFile(file, "rw");
     lock = raf.getChannel().tryLock();

     this.pcap = Pcap.openOffline(file, errbuf);
     System.out.printf("Opening file for reading: %s", filePath);
     if (pcap == null) {
        System.err.println(errbuf); // prob occurs here
     } else {
        PcapPacketHandler<String> jpacketHandler;
        jpacketHandler = new PcapPacketHandler<String>() {
           @Override
           public void nextPacket( packet, String user) {
              PPacket pcap = new PPacket(packet, user);
             //Process packet
           }
        };

        // Loop over all packets in the file...
        try {
           pcap.loop(-1, jpacketHandler, "jNetPcap Rocks!!!!!");
        } finally {
           pcap.close();
        }
     }
  } catch (IOException e) {
     System.err.println(e.getMessage());

  } finally {
     try {
        if (lock != null) {
           lock.release();
        }
        if (raf != null) {
           raf.close();
        }
     } catch (IOException e) {
        System.err.println(e.getMessage());

     }
  }
  }

しかし、Eclipse(Windows)で実行しているときに、このエラーが発生します

「ダンプファイルの読み取りエラー: 権限が拒否されました」

.dll ファイルも含めましたが、ここで何が問題なのか理解できません。

注 - (このコードは Ubuntu で正常に動作します)

4

1 に答える 1

0

ユーザーがこのファイルにアクセスできないか、ファイルが別のプロセスによって排他的に開かれています。

// simple code to check
String filePath = "C:/test/no-gre-sample.pcap";
StringBuilder errbuf = new StringBuilder();
Pcap pcap = Pcap.openOffline(filePath, errbuf);
System.out.println("errbuf = " + errbuf);
System.out.println("pcap = " + pcap);

出力 - ファイルが存在しません

errbuf = C:/test/no-gre-sample.pcap: No such file or directory
pcap = null

出力 - 通常のユーザーにはアクセス権限がありません

errbuf = C:/test/no-gre-sample.pcap: Permission denied
pcap = null

で許可を確認できますcacls no-gre-sample.pcap

C:\test\no-gre-sample.pcap BUILTIN\Users:N

グループ内のすべてのユーザーUsers(より特権のあるユーザーは除く) は、このファイルに対するアクセス許可を持っていないことを意味します。ただし、ディレクトリのアクセス許可も確認する必要があります。

悲しいことに、 によって報告されたエラーPcap.openOfflineは、 と の両方のケースmissed permissionsで同じですread locked by another application。簡単なテストを実行して、違いを確認できます。

InputStream is = new FileInputStream(filePath);
is.read();
is.close();

許可されなかった場合の出力

Exception in thread "main" java.io.FileNotFoundException: _
    C:\test\no-gre-sample.pcap (Access is denied)

別のアプリケーションによってロックされた読み取りの出力

 Exception in thread "main" java.io.FileNotFoundException: _
    C:\test\no-gre-sample.pcap _
    (The process cannot access the file because it is being used by another process)
于 2015-06-30T07:07:11.387 に答える