Skip to content

Problem with set_immediate_mode for a not activated pcap_t struct. Error: Struct already activated. #13

@Kroptokin

Description

@Kroptokin

Hi!
I am trying to program a capture script using libpcap library for python.
The problem is when I try to activate immediate mode, if gives me the following error:

ERROR = b"The setting can't be changed after the pcap_t is activated"

Some of my code:

`

 #Initialize pcap_t
 func_pcap_t = libpcap.pcap_t()

#Set immediate mode to make timeout work:
if func_wrongSystemConfig == False:
    intRes = libpcap.set_immediate_mode(ctypes.byref(func_pcap_t), ctypes.c_int(1))
	
    if intRes != 0: #Error
        print("ERROR -  Not possible to set immediate mode!")
        p_errBuff = libpcap.statustostr(intRes)
        print("ERROR = ", repr(p_errBuff))
        
        func_wrongSystemConfig = True
  
  
  #Open Live Interface with promiscuous mode	
if func_wrongSystemConfig == False:
	
	#pcap_t *pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
	pcap_device = ctypes.c_char_p(if_name.encode(gl_pcap_encode))
	pcap_snaplen = ctypes.c_int(func_pcap_snaplen)
	pcap_promisc = ctypes.c_int(func_pacp_promisc)
	pcap_timeout = ctypes.c_int(func_pcap_timeout)
	
	func_pcap_t = libpcap.open_live(pcap_device, pcap_snaplen, pcap_promisc, pcap_timeout, p_errBuff)
	
	if not func_pcap_t:
		print("ERROR - Could not open live device: ", if_name)
		print("DEBUG - errBuf = ", repr(p_errBuff.value))
		func_wrongSystemConfig = True
	else:
		pass
		#print("SUCCESS - Opening live device: ", if_name) 

`

I also tried to set immediate mode after open_live but gives the same error...
What am I doing wrong and how can I fix this issue?
The struct pcap_t seems to do not activated but the function does not think so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions