Use pcap_setdirection instead of filter
This commit is contained in:
		
							parent
							
								
									6ed895d4c7
								
							
						
					
					
						commit
						590e7a079f
					
				
					 1 changed files with 11 additions and 6 deletions
				
			
		
							
								
								
									
										17
									
								
								ethsock.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								ethsock.c
									
										
									
									
									
								
							|  | @ -345,7 +345,7 @@ inline uint8_t *ethsock_get_hwaddr(struct ethsock *sock) | ||||||
| struct ethsock *ethsock_create(const char *intf, uint16_t protocol) | struct ethsock *ethsock_create(const char *intf, uint16_t protocol) | ||||||
| { | { | ||||||
| 	char buf[PCAP_ERRBUF_SIZE]; | 	char buf[PCAP_ERRBUF_SIZE]; | ||||||
| 	struct bpf_program fp; | 	struct bpf_program bpf; | ||||||
| 	struct ethsock *sock; | 	struct ethsock *sock; | ||||||
| 	bool is_bridge; | 	bool is_bridge; | ||||||
| 	int err; | 	int err; | ||||||
|  | @ -412,17 +412,22 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol) | ||||||
| 	} | 	} | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 	snprintf(buf, sizeof(buf), "ether proto 0x%04x and not ether src %s", | 	err = pcap_setdirection(sock->pcap, PCAP_D_IN); | ||||||
| 			protocol, mac_to_str(sock->hwaddr)); | 	if (err) { | ||||||
|  | 		pcap_perror(sock->pcap, "pcap_setdirection"); | ||||||
|  | 		goto cleanup; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	err = pcap_compile(sock->pcap, &fp, buf, 0, 0); | 	snprintf(buf, sizeof(buf), "ether proto 0x%04x", protocol); | ||||||
|  | 
 | ||||||
|  | 	err = pcap_compile(sock->pcap, &bpf, buf, 0, 0); | ||||||
| 	if (err) { | 	if (err) { | ||||||
| 		pcap_perror(sock->pcap, "pcap_compile"); | 		pcap_perror(sock->pcap, "pcap_compile"); | ||||||
| 		goto cleanup; | 		goto cleanup; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = pcap_setfilter(sock->pcap, &fp); | 	err = pcap_setfilter(sock->pcap, &bpf); | ||||||
| 	pcap_freecode(&fp); | 	pcap_freecode(&bpf); | ||||||
| 
 | 
 | ||||||
| 	if (err) { | 	if (err) { | ||||||
| 		pcap_perror(sock->pcap, "pcap_setfilter"); | 		pcap_perror(sock->pcap, "pcap_setfilter"); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue