question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Cannot open BPF device' error on c.open()

See original GitHub issue

I’m working on an Electron App that broadcasts UDP to find specific devices connected to the network and it is throwing an error on this line:

var linkType = c.open(device, filter, bufSize, buffer);

This is the error on the console: Uncaught Error: (cannot open BPF device) /dev/bpf0: Permission denied

It works fine on my local environment, but when running the App on another Mac it’s failing as described. Do I have to grant permissions to the App in order to be able to open the Cap object ©? I’ve tried using the sudo-prompt module but it is not working.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
ghostcommented, Oct 28, 2017

sudo chmod o+r /dev/bpf* should help in reading of Berkley Packet Filter.

0reactions
mscdexcommented, Jul 25, 2017

Yes, the best solution is to start as root, start listening for packets, and then drop the privileges of the process using process.setgid() and process.setuid() to something more appropriate, such as the current user and group (or perhaps nobody/nobody). Perform these steps before doing anything else (including require()ing other non-node core modules). This way you can ensure that nothing else in the node process (e.g. third party modules) gets superuser privileges, which is good for security.

This is also a better solution than what you may find elsewhere online which may suggest to use setcap on the node executable which is a huge security issue because the same node executable is used to execute any and all scripts, not just the one using cap (and setcap can’t be used on a shell script or limited to a specific node script).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix BPF device permissions on Mac OS to use tcpdump
came on this problem today. found me in group chmodbf by command line example above, but could not run tcpdump. Same error.
Read more >
Error creating sniffer on OS X - permission denied
I am trying to run packetbeat on mac with packetbeat.yml configured to have mac settings and http port changes from default:
Read more >
tcpdump command fails with "bpf_load: genminor failed" error
The error usually indicates tcpdump cannot find any bpf (Berkeley Packet Filter) devices to run against or mismatch of the device major ...
Read more >
bpf-helpers(7) - Linux manual page - man7.org
This helper is intended to be used in combination with bpf_csum_diff(), in particular when the checksum needs to be updated after data has...
Read more >
Linux Socket Filtering aka Berkeley Packet Filter (BPF)
4 manpage is very helpful in creating filters. On Linux, BPF is much simpler than on BSD. One does not have to worry...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found