Skip to content
Snippets Groups Projects
Commit d5db227c authored by Phil's avatar Phil
Browse files

Added __repr__() to supersockets

parent 7f0bc767
Branches
No related tags found
No related merge requests found
...@@ -210,6 +210,7 @@ def _flush_fd(fd): ...@@ -210,6 +210,7 @@ def _flush_fd(fd):
class L3PacketSocket(SuperSocket): class L3PacketSocket(SuperSocket):
desc = "read/write packets at layer 3 using Linux PF_PACKET sockets"
def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0): def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
self.type = type self.type = type
self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
...@@ -307,6 +308,7 @@ class L3PacketSocket(SuperSocket): ...@@ -307,6 +308,7 @@ class L3PacketSocket(SuperSocket):
class L2Socket(SuperSocket): class L2Socket(SuperSocket):
desc = "read/write packets at layer 2 using Linux PF_PACKET sockets"
def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0): def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
if iface is None: if iface is None:
iface = conf.iface iface = conf.iface
...@@ -351,6 +353,7 @@ class L2Socket(SuperSocket): ...@@ -351,6 +353,7 @@ class L2Socket(SuperSocket):
class L2ListenSocket(SuperSocket): class L2ListenSocket(SuperSocket):
desc = "read packets at layer 2 using Linux PF_PACKET sockets"
def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None, nofilter=0): def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None, nofilter=0):
self.type = type self.type = type
self.outs = None self.outs = None
......
...@@ -71,6 +71,7 @@ if conf.use_pcap: ...@@ -71,6 +71,7 @@ if conf.use_pcap:
class L2pcapListenSocket(SuperSocket): class L2pcapListenSocket(SuperSocket):
desc = "read packets at layer 2 using libpcap"
def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None): def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None):
self.type = type self.type = type
self.outs = None self.outs = None
...@@ -158,6 +159,7 @@ if conf.use_dnet: ...@@ -158,6 +159,7 @@ if conf.use_dnet:
if conf.use_pcap and conf.use_dnet: if conf.use_pcap and conf.use_dnet:
class L3dnetSocket(SuperSocket): class L3dnetSocket(SuperSocket):
desc = "read/write packets at layer 3 using libdnet and libpcap"
def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0): def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
self.iflist = {} self.iflist = {}
if iface is None: if iface is None:
...@@ -234,6 +236,7 @@ if conf.use_pcap and conf.use_dnet: ...@@ -234,6 +236,7 @@ if conf.use_pcap and conf.use_dnet:
del(self.outs) del(self.outs)
class L2dnetSocket(SuperSocket): class L2dnetSocket(SuperSocket):
desc = "read/write packets at layer 2 using libdnet and libpcap"
def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0): def __init__(self, iface = None, type = ETH_P_ALL, filter=None, nofilter=0):
if iface is None: if iface is None:
iface = conf.iface iface = conf.iface
......
...@@ -155,6 +155,7 @@ bind_layers( L2CAP_CmdHdr, L2CAP_InfoReq, code=10) ...@@ -155,6 +155,7 @@ bind_layers( L2CAP_CmdHdr, L2CAP_InfoReq, code=10)
bind_layers( L2CAP_CmdHdr, L2CAP_InfoResp, code=11) bind_layers( L2CAP_CmdHdr, L2CAP_InfoResp, code=11)
class BluetoothL2CAPSocket(SuperSocket): class BluetoothL2CAPSocket(SuperSocket):
desc = "read/write packets on a connected L2CAP socket"
def __init__(self, peer): def __init__(self, peer):
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW,
socket.BTPROTO_L2CAP) socket.BTPROTO_L2CAP)
...@@ -167,6 +168,7 @@ class BluetoothL2CAPSocket(SuperSocket): ...@@ -167,6 +168,7 @@ class BluetoothL2CAPSocket(SuperSocket):
class BluetoothHCISocket(SuperSocket): class BluetoothHCISocket(SuperSocket):
desc = "read/write on a BlueTooth HCI socket"
def __init__(self, iface=0x10000, type=None): def __init__(self, iface=0x10000, type=None):
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)
s.setsockopt(socket.SOL_HCI, socket.HCI_DATA_DIR,1) s.setsockopt(socket.SOL_HCI, socket.HCI_DATA_DIR,1)
......
...@@ -9,8 +9,17 @@ from packet import Raw ...@@ -9,8 +9,17 @@ from packet import Raw
from config import conf from config import conf
from data import * from data import *
class _SuperSocket_metaclass(type):
def __repr__(self):
if self.desc is not None:
return "<%s: %s>" % (self.__name__,self.desc)
else:
return "<%s>" % self.__name__
class SuperSocket: class SuperSocket:
__metaclass__ = _SuperSocket_metaclass
desc = None
closed=0 closed=0
def __init__(self, family=socket.AF_INET,type=socket.SOCK_STREAM, proto=0): def __init__(self, family=socket.AF_INET,type=socket.SOCK_STREAM, proto=0):
self.ins = socket.socket(family, type, proto) self.ins = socket.socket(family, type, proto)
...@@ -38,8 +47,8 @@ class SuperSocket: ...@@ -38,8 +47,8 @@ class SuperSocket:
def bind_out(self, addr): def bind_out(self, addr):
self.outs.bind(addr) self.outs.bind(addr)
class L3RawSocket(SuperSocket): class L3RawSocket(SuperSocket):
desc = "Layer 3 using Raw sockets (PF_INET/SOCK_RAW)"
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0): def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1) self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
...@@ -55,12 +64,14 @@ class L3RawSocket(SuperSocket): ...@@ -55,12 +64,14 @@ class L3RawSocket(SuperSocket):
log_runtime.error(msg) log_runtime.error(msg)
class SimpleSocket(SuperSocket): class SimpleSocket(SuperSocket):
desc = "wrapper arround a classic socket"
def __init__(self, sock): def __init__(self, sock):
self.ins = sock self.ins = sock
self.outs = sock self.outs = sock
class StreamSocket(SimpleSocket): class StreamSocket(SimpleSocket):
desc = "transforms a stream socket into a layer 2"
def __init__(self, sock, basecls=Raw): def __init__(self, sock, basecls=Raw):
SimpleSocket.__init__(self, sock) SimpleSocket.__init__(self, sock)
self.basecls = basecls self.basecls = basecls
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment