title: Network interface: you don't have permission to capture on that device (socket: Operation not permitted)
body: <p>Currently I'm writing a small project that views the local bandwidth. I installed the package and implemented the code that's available on the pcap4j <a href="https://www.pcap4j.org/" rel="nofollow noreferrer">site</a> just to try it out like so:</p>
  
  <pre class="lang-java prettyprint-override"><code>import org.pcap4j.core.*;
  import org.pcap4j.core.PcapNetworkInterface.PromiscuousMode;
  import org.pcap4j.packet.IpV4Packet;
  import org.pcap4j.packet.Packet;
  
  import java.io.EOFException;
  import java.lang.*;
  import java.net.*;
  import java.util.concurrent.TimeoutException;
  
  public class BandwidthViewer {
      public static void main(String[] args) throws UnknownHostException, PcapNativeException, EOFException, TimeoutException, NotOpenException {
          InetAddress addr = InetAddress.getByName("192.168.1.8");
          PcapNetworkInterface nif = Pcaps.getDevByAddress(addr);
  
          int snapLen = 65536;
          PromiscuousMode mode = PromiscuousMode.PROMISCUOUS;
          int timeout = 10;
          PcapHandle handle = nif.openLive(snapLen, mode, timeout);
  
          Packet packet = handle.getNextPacketEx();
          handle.close();
  
          IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
          Inet4Address srcAddr = ipV4Packet.getHeader().getSrcAddr();
          System.out.println(srcAddr);
      }
  }
  </code></pre>
  
  <p>Once run I get this error:</p>
  
  <pre><code>/usr/lib/jvm/java-11-openjdk/bin/java -javaagent:/usr/share/idea/lib/idea_rt.jar=46685:/usr/share/idea/bin -Dfile.encoding=UTF-8 -classpath /home/ivan/mdrive/Projects/IdeaProjects/BandwidthViewer/target/classes:/home/ivan/.m2/repository/org/pcap4j/pcap4j-core/2.0.0-alpha.6/pcap4j-core-2.0.0-alpha.6.jar:/home/ivan/.m2/repository/org/slf4j/slf4j-api/1.7.26/slf4j-api-1.7.26.jar:/home/ivan/.m2/repository/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar:/home/ivan/.m2/repository/org/pcap4j/pcap4j-packetfactory-static/2.0.0-alpha.6/pcap4j-packetfactory-static-2.0.0-alpha.6.jar BandwidthViewer
  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  Exception in thread "main" org.pcap4j.core.PcapNativeException: enp3s0: You don't have permission to capture on that device (socket: Operation not permitted)
      at org.pcap4j.core.PcapNetworkInterface.openLive(PcapNetworkInterface.java:238)
      at BandwidthViewer.main(BandwidthViewer.java:19)
  
  Process finished with exit code 1
  </code></pre>
  
  <p>It makes sense that I can sniff any packets since I'm running it as a non-root user. I tried to fix this by using a solution like <a href="https://stackoverflow.com/questions/33008954/drop-tcpdump-permissions">this</a> but ultimately it didn't work. I know this should be possible, since programs like Wireshark also need you to log in as a root user in order to look at all the packets. Does anybody know what can fix this? Obviously I could run my IDE as root but that just seems unnecessary. I'm running this on Manjaro Linux.</p>