pcap-linux.c (235426) | pcap-linux.c (241231) |
---|---|
1/* 2 * pcap-linux.c: Packet capture interface to the Linux kernel 3 * 4 * Copyright (c) 2000 Torsten Landschoff <torsten@debian.org> 5 * Sebastian Krahmer <krahmer@cs.uni-potsdam.de> 6 * 7 * License: BSD 8 * --- 152 unchanged lines hidden (view full) --- 161#ifdef PCAP_SUPPORT_BT 162#include "pcap-bt-linux.h" 163#endif 164 165#ifdef PCAP_SUPPORT_CAN 166#include "pcap-can-linux.h" 167#endif 168 | 1/* 2 * pcap-linux.c: Packet capture interface to the Linux kernel 3 * 4 * Copyright (c) 2000 Torsten Landschoff <torsten@debian.org> 5 * Sebastian Krahmer <krahmer@cs.uni-potsdam.de> 6 * 7 * License: BSD 8 * --- 152 unchanged lines hidden (view full) --- 161#ifdef PCAP_SUPPORT_BT 162#include "pcap-bt-linux.h" 163#endif 164 165#ifdef PCAP_SUPPORT_CAN 166#include "pcap-can-linux.h" 167#endif 168 |
169#if PCAP_SUPPORT_CANUSB 170#include "pcap-canusb-linux.h" 171#endif 172 |
|
169#ifdef PCAP_SUPPORT_NETFILTER 170#include "pcap-netfilter-linux.h" 171#endif 172 173/* 174 * If PF_PACKET is defined, we can use {SOCK_RAW,SOCK_DGRAM}/PF_PACKET 175 * sockets rather than SOCK_PACKET sockets. 176 * --- 236 unchanged lines hidden (view full) --- 413#endif /* HAVE_SNF_API */ 414 415#ifdef PCAP_SUPPORT_BT 416 if (strstr(device, "bluetooth")) { 417 return bt_create(device, ebuf); 418 } 419#endif 420 | 173#ifdef PCAP_SUPPORT_NETFILTER 174#include "pcap-netfilter-linux.h" 175#endif 176 177/* 178 * If PF_PACKET is defined, we can use {SOCK_RAW,SOCK_DGRAM}/PF_PACKET 179 * sockets rather than SOCK_PACKET sockets. 180 * --- 236 unchanged lines hidden (view full) --- 417#endif /* HAVE_SNF_API */ 418 419#ifdef PCAP_SUPPORT_BT 420 if (strstr(device, "bluetooth")) { 421 return bt_create(device, ebuf); 422 } 423#endif 424 |
425#if PCAP_SUPPORT_CANUSB 426 if (strstr(device, "canusb")) { 427 return canusb_create(device, ebuf); 428 } 429#endif 430 |
|
421#ifdef PCAP_SUPPORT_CAN | 431#ifdef PCAP_SUPPORT_CAN |
422 if (strstr(device, "can") || strstr(device, "vcan")) { | 432 if ((strncmp(device, "can", 3) == 0 && isdigit(device[3])) || 433 (strncmp(device, "vcan", 4) == 0 && isdigit(device[4]))) { |
423 return can_create(device, ebuf); 424 } 425#endif 426 427#ifdef PCAP_SUPPORT_USB 428 if (strstr(device, "usbmon")) { 429 return usb_create(device, ebuf); 430 } --- 1863 unchanged lines hidden (view full) --- 2294#ifdef PCAP_SUPPORT_NETFILTER 2295 /* 2296 * Add netfilter devices. 2297 */ 2298 if (netfilter_platform_finddevs(alldevsp, errbuf) < 0) 2299 return (-1); 2300#endif 2301 | 434 return can_create(device, ebuf); 435 } 436#endif 437 438#ifdef PCAP_SUPPORT_USB 439 if (strstr(device, "usbmon")) { 440 return usb_create(device, ebuf); 441 } --- 1863 unchanged lines hidden (view full) --- 2305#ifdef PCAP_SUPPORT_NETFILTER 2306 /* 2307 * Add netfilter devices. 2308 */ 2309 if (netfilter_platform_finddevs(alldevsp, errbuf) < 0) 2310 return (-1); 2311#endif 2312 |
2313#if PCAP_SUPPORT_CANUSB 2314 if (canusb_platform_finddevs(alldevsp, errbuf) < 0) 2315 return (-1); 2316#endif 2317 |
|
2302 return (0); 2303} 2304 2305/* 2306 * Attach the given BPF code to the packet capture device. 2307 */ 2308static int 2309pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter, --- 3088 unchanged lines hidden (view full) --- 5398 if (p->k >= SLL_HDR_LEN) { 5399 /* 5400 * It's within the link-layer payload; that starts at an 5401 * offset of 0, as far as the kernel packet filter is 5402 * concerned, so subtract the length of the link-layer 5403 * header. 5404 */ 5405 p->k -= SLL_HDR_LEN; | 2318 return (0); 2319} 2320 2321/* 2322 * Attach the given BPF code to the packet capture device. 2323 */ 2324static int 2325pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter, --- 3088 unchanged lines hidden (view full) --- 5414 if (p->k >= SLL_HDR_LEN) { 5415 /* 5416 * It's within the link-layer payload; that starts at an 5417 * offset of 0, as far as the kernel packet filter is 5418 * concerned, so subtract the length of the link-layer 5419 * header. 5420 */ 5421 p->k -= SLL_HDR_LEN; |
5422 } else if (p->k == 0) { 5423 /* 5424 * It's the packet type field; map it to the special magic 5425 * kernel offset for that field. 5426 */ 5427 p->k = SKF_AD_OFF + SKF_AD_PKTTYPE; |
|
5406 } else if (p->k == 14) { 5407 /* 5408 * It's the protocol field; map it to the special magic 5409 * kernel offset for that field. 5410 */ 5411 p->k = SKF_AD_OFF + SKF_AD_PROTOCOL; | 5428 } else if (p->k == 14) { 5429 /* 5430 * It's the protocol field; map it to the special magic 5431 * kernel offset for that field. 5432 */ 5433 p->k = SKF_AD_OFF + SKF_AD_PROTOCOL; |
5412 } else { | 5434 } else if ((bpf_int32)(p->k) > 0) { |
5413 /* 5414 * It's within the header, but it's not one of those 5415 * fields; we can't do that in the kernel, so punt 5416 * to userland. 5417 */ 5418 return -1; 5419 } 5420 return 0; --- 119 unchanged lines hidden --- | 5435 /* 5436 * It's within the header, but it's not one of those 5437 * fields; we can't do that in the kernel, so punt 5438 * to userland. 5439 */ 5440 return -1; 5441 } 5442 return 0; --- 119 unchanged lines hidden --- |