@@ -74,25 +74,72 @@ class debug:
7474# Send / Receive #
7575####################
7676
77- _DOC_SNDRCV_PARAMS = """
77+ _DOC_SNDRCV_PARAMS_HEAD = """
7878 :param pks: SuperSocket instance to send/receive packets
79- :param pkt: the packet to send
80- :param timeout: how much time to wait after the last packet has been sent
81- :param inter: delay between two packets during sending
82- :param verbose: set verbosity level
83- :param chainCC: if True, KeyboardInterrupts will be forwarded
84- :param retry: if positive, how many times to resend unanswered packets
85- if negative, how many times to retry when no more packets
86- are answered
87- :param multi: whether to accept multiple answers for the same stimulus
88- :param rcv_pks: if set, will be used instead of pks to receive packets.
89- packets will still be sent through pks
90- :param prebuild: pre-build the packets before starting to send them.
91- Automatically enabled when a generator is passed as the packet
92- :param _flood:
93- :param threaded: if True, packets will be sent in an individual thread
94- :param session: a flow decoder used to handle stream of packets
95- :param chainEX: if True, exceptions during send will be forwarded
79+ :type pkt: SuperSocket
80+ """
81+
82+ _DOC_SNDRCV_PARAMS_BODY = """
83+ :param pkt: Packet or iterable of packets to be sent.
84+ :type pkt: _PacketIterable
85+ :param timeout: How much time to wait after the last packet
86+ has been sent. Defaults to None.
87+ :type timeout: Optional[int]
88+ :param inter: Delay between two packets during sending. Defaults to 0.
89+ :type inter: Optional[int]
90+
91+ :param verbose: Set verbosity level. Defaults to None.
92+ :type verbose: Optional[int]
93+
94+ :param chainCC: If True, KeyboardInterrupts will be forwarded.
95+ Defaults to False.
96+ :type chainCC: Optional[bool]
97+
98+ :param retry: If positive, how many times to resend unanswered packets.
99+ If negative, how many times to retry when no more packets
100+ are answered. Defaults to 0.
101+ :type retry: Optional[int]
102+
103+ :param multi: Whether to accept multiple answers for the same stimulus.
104+ Defaults to False.
105+ :type multi: Optional[bool]
106+
107+ :param rcv_pks: If set, will be used instead of pks to receive packets.
108+ Packets will still be sent through pks.
109+ Defaults to None.
110+ :type rcv_pks: Optional[SuperSocket]
111+
112+ :param prebuild: Pre-build the packets before starting to send them.
113+ Automatically enabled when a generator is passed as the
114+ packet. Defaults to False.
115+ :type prebuild: Optional[bool]
116+
117+ :param _flood: _FloodGenerator object, internally used by `flood()`
118+ methods. Defaults to None.
119+ :type _flood: Optional[_FloodGenerator]
120+
121+ :param threaded: If True, packets will be sent in an individual thread.
122+ Defaults to False.
123+ :type threaded: Optional[bool]
124+
125+ :param session: A flow decoder used to handle the stream of packets.
126+ Defaults to None.
127+ :type session: Optional[_GlobSessionType]
128+
129+ :param chainEX: If True, exceptions during send will be forwarded.
130+ Defaults to False.
131+ :type chainEX: Optional[bool]
132+ """
133+
134+ _DOC_SNDRCV_PARAMS_TAIL = """
135+ :return: A tuple, consisting of two packet lists, one with
136+ answered packets, the other with unanswered packets
137+ :rtype: Tuple[SndRcvList, PacketList]
138+ """
139+
140+ _DOC_SNDRCV1_PARAMS_TAIL = """
141+ :return: A received Packet answering the sent packet, or None
142+ :rtype: Optional[Packet]
96143 """
97144
98145
@@ -713,9 +760,26 @@ def srp1(*args, **kargs):
713760
714761
715762# Append doc
716- for sr_func in [srp , srp1 , sr , sr1 ]:
763+ for sr_func in [srp , sr ]:
717764 if sr_func .__doc__ is not None :
718- sr_func .__doc__ += _DOC_SNDRCV_PARAMS
765+ sr_func .__doc__ += (_DOC_SNDRCV_PARAMS_HEAD +
766+ _DOC_SNDRCV_PARAMS_BODY +
767+ _DOC_SNDRCV_PARAMS_TAIL )
768+
769+ for sr_func in [srp1 , sr1 ]:
770+ if sr_func .__doc__ is not None :
771+ sr_func .__doc__ += (_DOC_SNDRCV_PARAMS_HEAD +
772+ _DOC_SNDRCV_PARAMS_BODY +
773+ _DOC_SNDRCV1_PARAMS_TAIL )
774+
775+ # Append doc in SuperSocket
776+ for sr_func in [SuperSocket .sr ]:
777+ if sr_func .__doc__ is not None :
778+ sr_func .__doc__ += _DOC_SNDRCV_PARAMS_BODY + _DOC_SNDRCV_PARAMS_TAIL
779+
780+ for sr_func in [SuperSocket .sr1 ]:
781+ if sr_func .__doc__ is not None :
782+ sr_func .__doc__ += _DOC_SNDRCV_PARAMS_BODY + _DOC_SNDRCV1_PARAMS_TAIL
719783
720784
721785# SEND/RECV LOOP METHODS
@@ -995,40 +1059,49 @@ def srp1flood(x, # type: _PacketIterable
9951059# SNIFF METHODS
9961060
9971061
998- class AsyncSniffer (object ):
999- """
1000- Sniff packets and return a list of packets.
1001-
1002- Args:
1003- count: number of packets to capture. 0 means infinity.
1004- store: whether to store sniffed packets or discard them
1005- prn: function to apply to each packet. If something is returned, it
1006- is displayed.
1007- --Ex: prn = lambda x: x.summary()
1008- session: a session = a flow decoder used to handle stream of packets.
1009- --Ex: session=TCPSession
1010- See below for more details.
1011- filter: BPF filter to apply.
1012- lfilter: Python function applied to each packet to determine if
1013- further action may be done.
1014- --Ex: lfilter = lambda x: x.haslayer(Padding)
1015- offline: PCAP file (or list of PCAP files) to read packets from,
1016- instead of sniffing them
1017- quiet: when set to True, the process stderr is discarded
1018- (default: False).
1019- timeout: stop sniffing after a given time (default: None).
1020- L2socket: use the provided L2socket (default: use conf.L2listen).
1021- opened_socket: provide an object (or a list of objects) ready to use
1022- .recv() on.
1023- stop_filter: Python function applied to each packet to determine if
1024- we have to stop the capture after this packet.
1025- --Ex: stop_filter = lambda x: x.haslayer(TCP)
1026- iface: interface or list of interfaces (default: None for sniffing
1027- on all interfaces).
1028- monitor: use monitor mode. May not be available on all OS
1029- started_callback: called as soon as the sniffer starts sniffing
1030- (default: None).
1062+ _DOC_SNIFF_PARAMS = """
1063+ :param count: Number of packets to capture. 0 means infinity.
1064+ :type count: int
1065+ :param store: Whether to store sniffed packets or discard them.
1066+ :type store: bool
1067+ :param offline: PCAP file (or list of PCAP files) to read packets from,
1068+ instead of sniffing them.
1069+ :type offline: Any
1070+ :param quiet: When set to True, the process stderr is discarded.
1071+ (default: False).
1072+ :type quiet: bool
1073+ :param prn: Function to apply to each packet. If something is returned,
1074+ it is displayed.
1075+ --Ex: prn = lambda x: x.summary()
1076+ :type prn: Optional[Callable[[Packet], Any]]
1077+ :param lfilter: Python function applied to each packet to determine if
1078+ further action may be done.
1079+ :type lfilter: Optional[Callable[[Packet], bool]]
1080+ :param L2socket: Use the provided L2socket (default: use conf.L2listen).
1081+ :type L2socket: Optional[Type[SuperSocket]]
1082+ :param timeout: Stop sniffing after a given time (default: None).
1083+ :type timeout: Optional[int]
1084+ :param opened_socket: Provide an object (or a list of objects) ready to
1085+ use .recv() on.
1086+ :type opened_socket: Optional[SuperSocket]
1087+ :param stop_filter: Python function applied to each packet to determine if
1088+ we have to stop the capture after this packet.
1089+ :type stop_filter: Optional[Callable[[Packet], bool]]
1090+ :param iface: Interface or list of interfaces (default: None for sniffing
1091+ on all interfaces).
1092+ :type iface: Optional[_GlobInterfaceType]
1093+ :param started_callback: Called as soon as the sniffer starts sniffing
1094+ (default: None).
1095+ :type started_callback: Optional[Callable[[], Any]]
1096+ :param session: A session, which is a flow decoder used to handle a stream
1097+ of packets. See the documentation for more details.
1098+ :type session: Optional[_GlobSessionType]
1099+ :param session_kwargs: Additional keyword arguments for session initialization.
1100+ :type session_kwargs: Dict[str, Any]
1101+
1102+ """
10311103
1104+ _DOC_ASYNC_SNIFF = """
10321105 The iface, offline and opened_socket parameters can be either an
10331106 element, a list of elements, or a dict object mapping an element to a
10341107 label (see examples below).
@@ -1058,6 +1131,11 @@ class AsyncSniffer(object):
10581131 >>> t.stop()
10591132 """
10601133
1134+
1135+ class AsyncSniffer (object ):
1136+ """Sniff packets and return a list of packets.
1137+ """
1138+
10611139 def __init__ (self , * args , ** kwargs ):
10621140 # type: (*Any, **Any) -> None
10631141 # Store keyword arguments
@@ -1321,6 +1399,10 @@ def join(self, *args, **kwargs):
13211399 self .thread .join (* args , ** kwargs )
13221400
13231401
1402+ AsyncSniffer .__doc__ = ((AsyncSniffer .__doc__ or "" ) + _DOC_SNIFF_PARAMS +
1403+ _DOC_ASYNC_SNIFF )
1404+
1405+
13241406@conf .commands .register
13251407def sniff (* args , ** kwargs ):
13261408 # type: (*Any, **Any) -> PacketList
@@ -1329,7 +1411,7 @@ def sniff(*args, **kwargs):
13291411 return cast (PacketList , sniffer .results )
13301412
13311413
1332- sniff .__doc__ = AsyncSniffer .__doc__
1414+ SuperSocket . sniff . __doc__ = sniff .__doc__ = AsyncSniffer .__doc__
13331415
13341416
13351417@conf .commands .register
@@ -1346,18 +1428,21 @@ def bridge_and_sniff(if1, # type: _GlobInterfaceType
13461428 """Forward traffic between interfaces if1 and if2, sniff and return
13471429 the exchanged packets.
13481430
1349- :param if1: the interfaces to use (interface names or opened sockets).
1350- :param if2:
1351- :param xfrm12: a function to call when forwarding a packet from if1 to
1431+ :param if1: The interfaces to use (interface names or opened sockets).
1432+ :type if1: _GlobInterfaceType
1433+
1434+ :param if2: The interfaces to use (interface names or opened sockets).
1435+ :type if2: _GlobInterfaceType
1436+
1437+ :param xfrm12: A function to call when forwarding a packet from if1 to
13521438 if2. If it returns True, the packet is forwarded as it. If it
13531439 returns False or None, the packet is discarded. If it returns a
1354- packet, this packet is forwarded instead of the original packet
1355- one.
1356- :param xfrm21: same as xfrm12 for packets forwarded from if2 to if1.
1440+ packet, this packet is forwarded instead of the original packet.
1441+ :type xfrm12: Optional[Callable[[Packet], Union[Packet, bool]]]
1442+
1443+ :param xfrm21: Same as xfrm12 for packets forwarded from if2 to if1.
1444+ :type xfrm21: Optional[Callable[[Packet], Union[Packet, bool]]]
13571445
1358- The other arguments are the same than for the function sniff(),
1359- except for offline, opened_socket and iface that are ignored.
1360- See help(sniff) for more.
13611446 """
13621447 for arg in ['opened_socket' , 'offline' , 'iface' ]:
13631448 if arg in kargs :
@@ -1430,11 +1515,15 @@ def prn(pkt):
14301515 * args , ** kargs )
14311516
14321517
1518+ bridge_and_sniff .__doc__ = (bridge_and_sniff .__doc__ or "" ) + _DOC_SNIFF_PARAMS
1519+
1520+
14331521@conf .commands .register
14341522def tshark (* args , ** kargs ):
14351523 # type: (Any, Any) -> None
14361524 """Sniff packets and print them calling pkt.summary().
1437- This tries to replicate what text-wireshark (tshark) would look like"""
1525+ This tries to replicate what text-wireshark (tshark) would look like.
1526+ """
14381527
14391528 if 'iface' in kargs :
14401529 iface = kargs .get ('iface' )
@@ -1455,3 +1544,7 @@ def _cb(pkt):
14551544
14561545 sniff (prn = _cb , store = False , * args , ** kargs )
14571546 print ("\n %d packet%s captured" % (i [0 ], 's' if i [0 ] > 1 else '' ))
1547+
1548+
1549+ tshark .__doc__ = (tshark .__doc__ or "" ) + _DOC_SNIFF_PARAMS
1550+ SuperSocket .tshark .__doc__ = tshark .__doc__
0 commit comments