#NEWLINE# def __enter__( self ) : #NEWLINE# #INDENT# for ( interface_name , sock , ifr ) in self . interfaces : #NEWLINE# #INDENT# LOG . info ( 'Interface %s entering promiscuous mode to capture ' , interface_name ) #NEWLINE# try : #NEWLINE# #INDENT# ifr . ifr_ifrn = interface_name . encode ( ) #NEWLINE# fcntl . ioctl ( sock . fileno ( ) , SIOCGIFFLAGS , ifr ) #NEWLINE# ifr . ifr_flags |= IFF_PROMISC #NEWLINE# fcntl . ioctl ( sock . fileno ( ) , SIOCSIFFLAGS , ifr ) #NEWLINE# LOG . debug ( 'Binding interface %(interface)s for protocol %(proto)s' , { #NEWLINE# #INDENT# 'interface' : interface_name , #NEWLINE# 'proto' : self . protocol , #NEWLINE# #UNINDENT# } ) #NEWLINE# sock . bind ( ( interface_name , self . protocol ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# LOG . warning ( 'Failed to open all RawPromiscuousSockets, attempting to close any opened sockets.' ) #NEWLINE# if self . __exit__ ( * sys . exc_info ( ) ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . exception ( 'Could not successfully close all opened RawPromiscuousSockets.' ) #NEWLINE# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return [ ( sock [ 0 ] , sock [ 1 ] ) for sock in self . interfaces ]