xref: /freebsd-src/contrib/libpcap/doc/README.macos (revision 57e22627f9459b9dfd6043b32e02ecfcf205e176)
1*57e22627SCy SchubertAs with other systems using BPF, macOS allows users with read access to
2*57e22627SCy Schubertthe BPF devices to capture packets with libpcap and allows users with
3*57e22627SCy Schubertwrite access to the BPF devices to send packets with libpcap.
4*57e22627SCy Schubert
5*57e22627SCy SchubertOn some systems that use BPF, the BPF devices live on the root file
6*57e22627SCy Schubertsystem, and the permissions and/or ownership on those devices can be
7*57e22627SCy Schubertchanged to give users other than root permission to read or write those
8*57e22627SCy Schubertdevices.
9*57e22627SCy Schubert
10*57e22627SCy SchubertOn newer versions of FreeBSD, the BPF devices live on devfs, and devfs
11*57e22627SCy Schubertcan be configured to set the permissions and/or ownership of those
12*57e22627SCy Schubertdevices to give users other than root permission to read or write those
13*57e22627SCy Schubertdevices.
14*57e22627SCy Schubert
15*57e22627SCy SchubertOn macOS, the BPF devices live on devfs, but the macOS version of devfs
16*57e22627SCy Schubertis based on an older (non-default) FreeBSD devfs, and that version of
17*57e22627SCy Schubertdevfs cannot be configured to set the permissions and/or ownership of
18*57e22627SCy Schubertthose devices.
19*57e22627SCy Schubert
20*57e22627SCy SchubertTherefore, we supply:
21*57e22627SCy Schubert
22*57e22627SCy Schubert	a "startup item" for older versions of macOS;
23*57e22627SCy Schubert
24*57e22627SCy Schubert	a launchd daemon for Tiger and later versions of macOS;
25*57e22627SCy Schubert
26*57e22627SCy SchubertBoth of them will change the ownership of the BPF devices so that the
27*57e22627SCy Schubert"admin" group owns them, and will change the permission of the BPF
28*57e22627SCy Schubertdevices to rw-rw----, so that all users in the "admin" group - i.e., all
29*57e22627SCy Schubertusers with "Allow user to administer this computer" turned on - have
30*57e22627SCy Schubertboth read and write access to them.
31*57e22627SCy Schubert
32*57e22627SCy SchubertThe startup item is in the ChmodBPF directory in the source tree.  A
33*57e22627SCy Schubert/Library/StartupItems directory should be created if it doesn't already
34*57e22627SCy Schubertexist, and the ChmodBPF directory should be copied to the
35*57e22627SCy Schubert/Library/StartupItems directory (copy the entire directory, so that
36*57e22627SCy Schubertthere's a /Library/StartupItems/ChmodBPF directory, containing all the
37*57e22627SCy Schubertfiles in the source tree's ChmodBPF directory; don't copy the individual
38*57e22627SCy Schubertitems in that directory to /Library/StartupItems).  The ChmodBPF
39*57e22627SCy Schubertdirectory, and all files under it, must be owned by root.  Installing
40*57e22627SCy Schubertthe files won't immediately cause the startup item to be executed; it
41*57e22627SCy Schubertwill be executed on the next reboot.  To change the permissions before
42*57e22627SCy Schubertthe reboot, run
43*57e22627SCy Schubert
44*57e22627SCy Schubert	sudo SystemStarter start ChmodBPF
45*57e22627SCy Schubert
46*57e22627SCy SchubertThe launchd daemon is the chmod_bpf script, plus the
47*57e22627SCy Schubertorg.tcpdump.chmod_bpf.plist launchd plist file.  chmod_bpf should be
48*57e22627SCy Schubertinstalled in /usr/local/bin/chmod_bpf, and org.tcpdump.chmod_bpf.plist
49*57e22627SCy Schubertshould be installed in /Library/LaunchDaemons.  chmod_bpf, and
50*57e22627SCy Schubertorg.tcpdump.chmod_bpf.plist, must be owned by root.  Installing the
51*57e22627SCy Schubertscript and plist file won't immediately cause the script to be executed;
52*57e22627SCy Schubertit will be executed on the next reboot.  To change the permissions
53*57e22627SCy Schubertbefore the reboot, run
54*57e22627SCy Schubert
55*57e22627SCy Schubert	sudo /usr/local/bin/chmod_bpf
56*57e22627SCy Schubert
57*57e22627SCy Schubertor
58*57e22627SCy Schubert
59*57e22627SCy Schubert	sudo launchctl load /Library/LaunchDaemons/org.tcpdump.chmod_bpf.plist
60*57e22627SCy Schubert
61*57e22627SCy SchubertIf you want to give a particular user permission to access the BPF
62*57e22627SCy Schubertdevices, rather than giving all administrative users permission to
63*57e22627SCy Schubertaccess them, you can have the ChmodBPF/ChmodBPF script change the
64*57e22627SCy Schubertownership of /dev/bpf* without changing the permissions.  If you want to
65*57e22627SCy Schubertgive a particular user permission to read and write the BPF devices and
66*57e22627SCy Schubertgive the administrative users permission to read but not write the BPF
67*57e22627SCy Schubertdevices, you can have the script change the owner to that user, the
68*57e22627SCy Schubertgroup to "admin", and the permissions to rw-r-----.  Other possibilities
69*57e22627SCy Schubertare left as an exercise for the reader.
70*57e22627SCy Schubert
71*57e22627SCy Schubert(NOTE: due to a bug in Snow Leopard, if you change the permissions not
72*57e22627SCy Schubertto grant write permission to everybody who should be allowed to capture
73*57e22627SCy Schuberttraffic, non-root users who cannot open the BPF devices for writing will
74*57e22627SCy Schubertnot be able to capture outgoing packets.)
75