Ejemplo n.º 1
0
 def __init__(self, interface_name, port_number):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                                 socket.htons(self.ETH_P_ALL))
     self.socket.bind((interface_name, 0))
     netutils.set_promisc(self.socket, interface_name)
     self.socket.settimeout(self.RCV_TIMEOUT)
Ejemplo n.º 2
0
 def __init__(self, interface_name, port_number):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                                 socket.htons(self.ETH_P_ALL))
     self.socket.bind((interface_name, 0))
     netutils.set_promisc(self.socket, interface_name)
     self.socket.settimeout(self.RCV_TIMEOUT)
Ejemplo n.º 3
0
 def __init__(self, interface_name, device_number, port_number):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.device_number = device_number
     self.port_number = port_number
     self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)
     afpacket.enable_auxdata(self.socket)
     self.socket.bind((interface_name, self.ETH_P_ALL))
     netutils.set_promisc(self.socket, interface_name)
     self.socket.settimeout(self.RCV_TIMEOUT)
Ejemplo n.º 4
0
 def interface_open(self, interface_name):
     """
     Open a socket in a promiscuous mode for a data connection.
     @param interface_name port name as a string such as 'eth1'
     @retval s socket
     """
     s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                       socket.htons(ETH_P_ALL))
     s.bind((interface_name, 0))
     netutils.set_promisc(s, interface_name)
     s.settimeout(RCV_TIMEOUT)
     return s
Ejemplo n.º 5
0
 def __init__(self, interface_name, device_number, port_number):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.device_number = device_number
     self.port_number = port_number
     self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)
     afpacket.enable_auxdata(self.socket)
     self.socket.bind((interface_name, self.ETH_P_ALL))
     netutils.set_promisc(self.socket, interface_name)
     self.socket.settimeout(self.RCV_TIMEOUT)
Ejemplo n.º 6
0
 def interface_open(self, interface_name):
     """
     Open a socket in a promiscuous mode for a data connection.
     @param interface_name port name as a string such as 'eth1'
     @retval s socket
     """
     s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                       socket.htons(ETH_P_ALL))
     s.bind((interface_name, 0))
     netutils.set_promisc(s, interface_name)
     s.settimeout(RCV_TIMEOUT)
     return s
Ejemplo n.º 7
0
 def __init__(self, interface_name, device_number, port_number, config={}):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.device_number = device_number
     self.port_number = port_number
     self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
                                 socket.htons(self.ETH_P_ALL))
     self.socket.bind((interface_name, 0))
     netutils.set_promisc(self.socket, interface_name)
     self.socket.settimeout(self.RCV_TIMEOUT)
     self.recv_size = config.get("socket_recv_size", self.RCV_SIZE_DEFAULT)
Ejemplo n.º 8
0
 def __init__(self, interface_name, udp_port, port_number):
     """
     @param interface_name The name of the physical interface like eth1
     """
     self.interface_name = interface_name
     self.udp_port       = udp_port
     if interface_name in OFTEST_SERVER_INTERFACE:
         try:
             print "---- (1) Connecting to " + interface_name  + " ..."
             self.interface_name = interface_name
             self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,socket.htons(self.ETH_P_ALL))
             self.socket.bind((interface_name, 0))
             netutils.set_promisc(self.socket, interface_name)
             self.socket.settimeout(self.RCV_TIMEOUT)
         except socket.error, e:
             print e
             sys.exit(1)
         print "---- Now connected"
Ejemplo n.º 9
0
                self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
                self.socket.bind(('', self.udp_port))
                self.socket.setblocking(0)
            except socket.error, e:
                print e
                sys.exit(1)
            print "---- Now connected"
        else :
            try:
                self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,socket.htons(self.ETH_P_ALL))
                self.socket.bind((interface_name, 0))
            except socket.error, e:
                print e
                sys.exit(1)
            print "A socket is conneted to "+interface_name
            netutils.set_promisc(self.socket, interface_name)
            self.socket.settimeout(self.RCV_TIMEOUT)

    def __del__(self):
        if self.socket:
            try:
                self.socket.close()
            except socket.error,e:
                print e
                sys.exit(1)
            print self.interface_name+"'s socket is closed"

    def fileno(self):
        """
        Return an integer file descriptor that can be passed to select(2).
        """