Commit ffb13dc
Afshin Paydar
Fix interface existence check on Linux before privileged operations
When attempting to open a non-existent network interface on Linux,
libpcap would return PCAP_ERROR_PERM_DENIED instead of the correct
PCAP_ERROR_NO_SUCH_DEVICE. This occurred because the privileged
socket(PF_PACKET, SOCK_RAW, 0) call in setup_socket() would fail
with permission errors before interface validation could occur.
This fix adds an interface existence check using an unprivileged
AF_INET socket and SIOCGIFINDEX ioctl before attempting to create
the privileged packet socket. Non-existent interfaces now correctly
return PCAP_ERROR_NO_SUCH_DEVICE.
This resolves the issue where applications like tcpdump would report
"Permission denied" instead of "No such device exists" for non-existent
interfaces, breaking their fallback logic from interface names to indices.
Note: BSD/macOS platforms have the same underlying issue where BPF device
access fails with permission errors before interface validation. This
should be addressed in a separate commit.
Fixes: libpcap issue #1538
Related: tcpdump issue #1334
Signed-off-by: Afshin Paydar <[email protected]>1 parent 19fd783 commit ffb13dc
1 file changed
+62
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
| |||
2426 | 2427 | | |
2427 | 2428 | | |
2428 | 2429 | | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
2429 | 2441 | | |
2430 | 2442 | | |
2431 | 2443 | | |
| |||
4812 | 4824 | | |
4813 | 4825 | | |
4814 | 4826 | | |
| 4827 | + | |
| 4828 | + | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
| 4836 | + | |
| 4837 | + | |
| 4838 | + | |
| 4839 | + | |
| 4840 | + | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
| 4847 | + | |
| 4848 | + | |
| 4849 | + | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
4815 | 4871 | | |
4816 | 4872 | | |
4817 | 4873 | | |
| |||
5164 | 5220 | | |
5165 | 5221 | | |
5166 | 5222 | | |
5167 | | - | |
5168 | | - | |
5169 | | - | |
5170 | | - | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
| 5226 | + | |
5171 | 5227 | | |
5172 | | - | |
5173 | | - | |
| 5228 | + | |
| 5229 | + | |
5174 | 5230 | | |
5175 | 5231 | | |
5176 | 5232 | | |
| |||
0 commit comments