internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: secdev/scapy

Issue:
L2CAP_ConnResp answers method is comparing the wrong Channel Identifier fields
#### Brief description

The answers method of L2CAP_ConnResp (scapy/layers/bluetooth.py) is comparing the wrong Channel Identifier fields.


#### Actual result

The answers method of L2CAP_ConnResp checks whether the _dcid_ field of the Response is the same as the _scid_ field from the Request.
However, according to Bluetooth Core spec v4.2 (p. 63):

> 4.3 CONNECTION RESPONSE (CODE 0x03)
> Source Channel Identifier - SCID (2 octets)
> This field contains the channel endpoint on the device receiving this
> Response packet. This is copied from the SCID field of the connection
> request packet.

On the other hand, the Destination Channel Identifier (DCID) of the Response is chosen by the receiver of the Request and is not necessarily related to the SCID of the Request.

This leads to L2CAP Connection Responses not getting detected as answers to Connection Requests if SCID and DCID differ.

#### Expected result

Instead of:

> return isinstance(other, L2CAP_ConnReq) and self.dcid == other.scid

it should be 

> return isinstance(other, L2CAP_ConnReq) and self.scid == other.scid



Discussion:
Thanks for the notice !

Feel free to submit a PR

Resolving patch:
diff --git a/scapy/layers/bluetooth.py b/scapy/layers/bluetooth.py
--- a/scapy/layers/bluetooth.py
+++ b/scapy/layers/bluetooth.py
@@ -241,7 +241,7 @@ class L2CAP_ConnResp(Packet):
                    ]
 
     def answers(self, other):
-        return isinstance(other, L2CAP_ConnReq) and self.dcid == other.scid
+        return isinstance(other, L2CAP_ConnReq) and self.scid == other.scid
 
 
 class L2CAP_CmdRej(Packet):


Test patch:
diff --git a/test/bluetooth.uts b/test/bluetooth.uts
--- a/test/bluetooth.uts
+++ b/test/bluetooth.uts
@@ -234,7 +234,7 @@ assert a[L2CAP_InfoResp].data == b"debug"
 
 = Answers
 a = HCI_Hdr(b'\x02\x00\x00\x0c\x00\x08\x00\x05\x00\x02\x00\x04\x00\x00\x00\x9a;')
-b = HCI_Hdr(b'\x02\x00\x00\x10\x00\x0c\x00\x05\x00\x03\x00\x08\x00\x9a;\x00\x00\x00\x00\x01\x00')
+b = HCI_Hdr(b'\x02\x00\x00\x10\x00\x0c\x00\x05\x00\x03\x00\x08\x00\xff\xff\x9a;\x00\x00\x01\x00')
 assert b.answers(a)
 assert not a.answers(b)
Repository: secdev/scapy

Issue:
Bug: wrong base class usage in radius.
the following file should be corrected:
scapy/layers/radius.py

`
class _RadiusAttrIPv4AddrVal(RadiusAttribute):
.....
`

should be:
`
class _RadiusAttrIPv4AddrVal(_SpecificRadiusAttr):
.....
`

without this change, the 'type' IE will be always 4.




Discussion:
Hi & thanks for the report.
Feel free to submit a PR !

Resolving patch:
diff --git a/scapy/layers/radius.py b/scapy/layers/radius.py
--- a/scapy/layers/radius.py
+++ b/scapy/layers/radius.py
@@ -579,7 +579,7 @@ def compute_message_authenticator(radius_packet, packed_req_authenticator,
 #
 
 
-class _RadiusAttrIPv4AddrVal(RadiusAttribute):
+class _RadiusAttrIPv4AddrVal(_SpecificRadiusAttr):
     """
     Implements a RADIUS attribute which value field is an IPv4 address.
     """


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -9619,6 +9619,16 @@ assert len(s) == 1
 s = b"Z\xa5\xaaUZ\xa5\xaaU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\xc5\x00\x00\x14'\x02\x00\x00\x001\x9a\xe44\xea4"
 isinstance(Radius(s), Radius)
 
+= RADIUS - attributes with IPv4 addresses
+
+r = raw(RadiusAttr_NAS_IP_Address())
+p = RadiusAttr_NAS_IP_Address(p)
+assert p.type == 4
+
+r = raw(RadiusAttr_Framed_IP_Address())
+p = RadiusAttr_Framed_IP_Address(p)
+assert p.type == 8
+
 
 ############
 ############
Repository: secdev/scapy

Issue:
Dot11Encrypted -vs- Dot11WEP



Discussion:
With the current version as of 20 minutes or so ago, Dot11Encrypted does not work for WEP in Python 3.  In Python 2, it still works and shows as Dot11WEP.

![image](https://user-images.githubusercontent.com/12008469/58850659-82707780-865d-11e9-83e1-0d8baf72f445.png)


If I can offer any help in fixing this, I'd be happy to give it a try.  I use the heck out of scapy for 802.11 analysis and I've been looking forward to the Python 3x shift; just have to move slow with the large volumes of code I've got to port.
Thanks for reporting this issue. Could you share the faulty frame in hex or pcap?

Hi @guedou,

Attached for your review.
[example.pcap.gz](https://github.com/secdev/scapy/files/3259474/example.pcap.gz)


Did you install the Python `cryptography` module? on both Python2 and Python3? This only happens when the module is not installed.

Resolving patch:
diff --git a/scapy/layers/dot11.py b/scapy/layers/dot11.py
--- a/scapy/layers/dot11.py
+++ b/scapy/layers/dot11.py
@@ -1050,11 +1050,10 @@ class Dot11WEP(Dot11Encrypted):
                    StrField("wepdata", None, remain=4),
                    IntField("icv", None)]
 
-    @crypto_validator
     def decrypt(self, key=None):
         if key is None:
             key = conf.wepkey
-        if key:
+        if key and conf.crypto_valid:
             d = Cipher(
                 algorithms.ARC4(self.iv + key.encode("utf8")),
                 None,


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -1034,6 +1034,12 @@ assert raw(pkt) == w_payload
 
 = WEP tests
 ~ wifi crypto Dot11 LLC SNAP IP TCP
+conf.wepkey = ""
+bck_conf_crypto_valid = conf.crypto_valid
+p = Dot11WEP(b'\x00\x00\x00\x00\xe3OjYLw\xc3x_%\xd0\xcf\xdeu-\xc3pH#\x1eK\xae\xf5\xde\xe7\xb8\x1d,\xa1\xfe\xe83\xca\xe1\xfe\xbd\xfe\xec\x00)T`\xde.\x93Td\x95C\x0f\x07\xdd')
+assert isinstance(p, Dot11WEP)
+conf.crypto_valid = bck_conf_crypto_valid
+
 conf.wepkey = "Fobar"
 r = raw(Dot11WEP()/LLC()/SNAP()/IP()/TCP(seq=12345678))
 r
Repository: secdev/scapy

Issue:
AttributeErrror: module 'os' has no attribute 'popen2' when using voip module
Hello I have installed the last scapy version, I want to use the module voip but i has the issue 
AttributeErrror: module 'os' has no attribute 'popen2' when using voip_play function. 


Discussion:

Resolving patch:
diff --git a/scapy/modules/voip.py b/scapy/modules/voip.py
--- a/scapy/modules/voip.py
+++ b/scapy/modules/voip.py
@@ -8,7 +8,7 @@
 """
 
 from __future__ import absolute_import
-import os
+import subprocess
 ###################
 #   Listen VoIP   #
 ###################
@@ -21,12 +21,12 @@
 from scapy.modules.six.moves import range
 
 
-sox_base = "sox -t .ul %s - -t ossdsp /dev/dsp"
+sox_base = (["sox", "-t", ".ul"], ["-", "-t", "ossdsp", "/dev/dsp"])
 
 if WINDOWS:
     if conf.prog.sox is None:
         raise OSError("Sox must be installed to play VoIP packets")
-    sox_base = "\"" + conf.prog.sox + "\" -t .ul %s - -t waveaudio"
+    sox_base = ([conf.prog.sox, "-t", ".ul"], ["-", "-t", "waveaudio"])
 
 
 def _merge_sound_bytes(x, y, sample_size=2):
@@ -75,7 +75,9 @@ def voip_play(s1, lst=None, **kargs):
     to read RTP VoIP packets
     """
 
-    dsp, rd = os.popen2(sox_base % "")
+    proc = subprocess.Popen(sox_base[0] + sox_base[1], stdin=subprocess.PIPE,
+                            stdout=subprocess.PIPE)
+    dsp, rd = proc.stdin, proc.stdout
 
     def play(pkt):
         if not pkt:
@@ -113,7 +115,9 @@ def voip_play2(s1, **kargs):
     .. seealso:: voip_play
     to play only incoming packets.
     """
-    dsp, rd = os.popen2(sox_base % "-c 2")
+    proc = subprocess.Popen(sox_base[0] + ["-c", "2"] + sox_base[1],
+                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    dsp, rd = proc.stdin, proc.stdout
     global x1, x2
     x1 = ""
     x2 = ""
@@ -133,7 +137,14 @@ def play(pkt):
             x1, x2, r = _merge_sound_bytes(x1, x2)
             dsp.write(r)
 
-    sniff(store=0, prn=play, **kargs)
+    try:
+        sniff(store=0, prn=play, **kargs)
+    finally:
+        try:
+            dsp.close()
+            rd.close()
+        except Exception:
+            pass
 
 
 def voip_play3(lst=None, **kargs):
@@ -144,7 +155,9 @@ def voip_play3(lst=None, **kargs):
     .. seealso:: voip_play
     for basic VoIP packets
     """
-    dsp, rd = os.popen2(sox_base % "")
+    proc = subprocess.Popen(sox_base[0] + sox_base[1], stdin=subprocess.PIPE,
+                            stdout=subprocess.PIPE)
+    dsp, rd = proc.stdin, proc.stdout
 
     def play(pkt, dsp=dsp):
         if pkt and pkt.haslayer(UDP) and pkt.haslayer(RTP):


Test patch:
Repository: secdev/scapy

Issue:
lack of precision for nanoseconds timestamp
Here is part of a [parsing of pcap](https://github.com/secdev/scapy/blob/master/scapy/utils.py#L1050).

If pcap was captured with nanoseconds timestamps than double is not enough to store timestamp value. Can be checked [here](https://www.exploringbinary.com/floating-point-converter/).  

If packets have arrived with 100 nanoseconds time difference, they will have "the same" timestamps. 


Discussion:

Resolving patch:
diff --git a/scapy/utils.py b/scapy/utils.py
--- a/scapy/utils.py
+++ b/scapy/utils.py
@@ -9,6 +9,8 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
+from decimal import Decimal
+
 import os
 import sys
 import socket
@@ -1047,7 +1049,8 @@ def read_packet(self, size=MTU):
                 debug.crashed_on = (self.LLcls, s)
                 raise
             p = conf.raw_layer(s)
-        p.time = pkt_info.sec + (0.000000001 if self.nano else 0.000001) * pkt_info.usec  # noqa: E501
+        power = Decimal(10) ** Decimal(-9 if self.nano else -6)
+        p.time = Decimal(pkt_info.sec + power * pkt_info.usec)
         p.wirelen = pkt_info.wirelen
         return p
 


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -6669,16 +6669,18 @@ pktpcap = rdpcap(pcapfile)
 
 = Read a pcapng file
 pktpcapng = rdpcap(pcapngfile)
+assert pktpcapng[0].time == 1454163407.666223
 
 = Read a pcap file with nanosecond precision
 pktpcapnano = rdpcap(pcapnanofile)
+assert pktpcapnano[0].time == Decimal('1454163407.666223049')
 
 = Read a pcap file with wirelen != captured len
 pktpcapwirelen = rdpcap(pcapwirelenfile)
 
 = Check all packet lists are the same
 assert list(pktpcap) == list(pktpcapng) == list(pktpcapnano)
-assert [p.time for p in pktpcap] == [p.time for p in pktpcapng] == [p.time for p in pktpcapnano]
+assert [float(p.time) for p in pktpcap] == [float(p.time) for p in pktpcapng] == [float(p.time) for p in pktpcapnano]
 
 = Check packets from pcap file
 assert all(IP in pkt for pkt in pktpcap)
@@ -6766,12 +6768,11 @@ conf.prog.tcpdump = conf_prog_tcpdump
 = Check wrpcap(nano=True)
 fdesc, filename = tempfile.mkstemp()
 fdesc = os.fdopen(fdesc, "wb")
-pktpcapnano[0].time += 0.000000001
+pktpcapnano[0].time += Decimal('1E-9')
 wrpcap(fdesc, pktpcapnano, nano=True)
 fdesc.close()
 pktpcapnanoread = rdpcap(filename)
 assert pktpcapnanoread[0].time == pktpcapnano[0].time
-assert pktpcapnanoread[0].time == pktpcap[0].time + 0.000000001
 os.unlink(filename)
 
 = Check PcapNg with nanosecond precision using obsolete packet block
Repository: secdev/scapy

Issue:
Inconsisten hash value
#### Brief description

Value of hash(packet) is not consistent for equivalent packets.
Eg. It does not hold that pktA==pktB => hash(pktA)==hash(pktB)

This appears to be the result of working with different packets which are the same at higher layers. In the example below, the objects being compared are the IP layer, which are identical. However, their containing Ethernet layer differs.

#### Environment

- Scapy version: 7c61676aef950ca268eac480902dd91cb0abe3a4
- Python version: Python 2.7.15rc1
- Operating System: Ubuntu 18.04.1

#### How to reproduce
```
p1=Ether("\\&\n\x82'Z\x00\x00P]g\x96\x08\x00E\x00\x02\x18\x00\x00@\x00\x00\x11\x8ar\xc0\xa8\xb1\xba\xc0\xa8\xbbW\x88\x80\x11P\x02\x04\\\x99")
p2=Ether("\x00\x00P]g\xb6\\&\na\xd3\xca\x08\x00E\x00\x02\x18\x00\x00@\x00\x00\x11\x8ar\xc0\xa8\xb1\xba\xc0\xa8\xbbW\x88\x80\x11P\x02\x04\\\x99")
p1['IP']==p2['IP']
hash(p1['IP'])==hash(p2['IP'])
```

#### Actual result

```
>>> p1['IP']==p2['IP']
True
>>> hash(p1['IP'])==hash(p2['IP'])
False
```

#### Expected result

```
>>> p1['IP']==p2['IP']
True
>>> hash(p1['IP'])==hash(p2['IP'])
True
```




Discussion:
Does this quick and dirty patch do the job?

```
diff --git a/scapy/packet.py b/scapy/packet.py
index d839c390..54568c94 100644
--- a/scapy/packet.py
+++ b/scapy/packet.py
@@ -1004,6 +1004,9 @@ class Packet(six.with_metaclass(Packet_metaclass, BasePacket,
         """DEV: returns a string that has the same value for a request and its answer."""  # noqa: E501
         return self.payload.hashret()
 
+    def __hash__(self):
+        return int(self.hashret().encode("hex"), 16)
+
     def answers(self, other):
         """DEV: true if self is an answer from other"""
         if other.__class__ == self.__class__:
```

Do we really care though ? What's the use case of `hash()` on packets ?!
If we can easily implement it, we should. However, I think that hashing a Packet is application dependent.

Resolving patch:
diff --git a/scapy/packet.py b/scapy/packet.py
--- a/scapy/packet.py
+++ b/scapy/packet.py
@@ -1431,6 +1431,13 @@ def command(self):
             c += "/" + pc
         return c
 
+    def __hash__(self):
+        """Needed for Python 2 only: Packet() subclasses should not be
+hashable.
+
+        """
+        raise TypeError('unhashable type: %r' % self.__class__.__name__)
+
 
 class NoPayload(Packet):
     def __new__(cls, *args, **kargs):


Test patch:
Repository: secdev/scapy

Issue:
explore() function yields AssertionError
I have the following environment:

Ubuntu 18.04 LTS (X86_64)
Python2/3: 2.7.15+/ 3.6.8
Scapy:  Version 2.4.3

When I try to use explore function, I get the following error. 
```
>>> explore()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 1845, in explore
    (six.text_type("Cancel"), "cancel")
  File "/usr/local/lib/python2.7/dist-packages/prompt_toolkit/shortcuts/dialogs.py", line 60, in button_dialog
    with_background=True)
  File "/usr/local/lib/python2.7/dist-packages/prompt_toolkit/widgets/dialogs.py", line 32, in __init__
    assert is_formatted_text(title)
AssertionError
```
Besides that I have not found problem with any other modules that I have come across so far.


Discussion:
I was able to reproduce on Python2.7 only with:
```
virtualenv -p python2.7 venv
. venv/bin/activate
pip install scapy prompt_toolkit
scapy
>>> explore()
```

Resolving patch:
diff --git a/scapy/packet.py b/scapy/packet.py
--- a/scapy/packet.py
+++ b/scapy/packet.py
@@ -1842,7 +1842,7 @@ def explore(layer=None):
             call_ptk = lambda x: x
         # 1 - Ask for layer or contrib
         btn_diag = button_dialog(
-            title="Scapy v%s" % conf.version,
+            title=six.text_type("Scapy v%s" % conf.version),
             text=HTML(
                 six.text_type(
                     '<style bg="white" fg="red">Chose the type of packets'
@@ -1881,7 +1881,7 @@ def explore(layer=None):
         # 3 - Ask for the layer/contrib module to explore
         rd_diag = radiolist_dialog(
             values=_radio_values,
-            title="Scapy v%s" % conf.version,
+            title=six.text_type("Scapy v%s" % conf.version),
             text=HTML(
                 six.text_type(
                     '<style bg="white" fg="red">Please select a layer among'


Test patch:
Repository: secdev/scapy

Issue:
ISOTPSoftSocket warnings during unit tests
Speaking of sockets, could one of you please take care of fixing those warnings we have at the end of the tests:
```
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e23d10>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e231d0>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e56150>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e63810>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e27a90>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e495d0>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method ISOTPSoftSocket.__del__ of <scapy.contrib.isotp.ISOTPSoftSocket object at 0x7fe924e56dd0>> ignored
```

In fact, a `SuperSocket` needs to implement a `close()` to be properly closed.

_Originally posted by @gpotter2 in https://github.com/secdev/scapy/issues/2170#issuecomment-514771519_


Discussion:
@gpotter2 can you please point me to a unit test where these errors occurred.
You can track them by running `tox -e linux_warnings` locally.
Unfortunately, I can't reproduce this errors on my system.

Resolving patch:
diff --git a/scapy/contrib/isotp.py b/scapy/contrib/isotp.py
--- a/scapy/contrib/isotp.py
+++ b/scapy/contrib/isotp.py
@@ -596,10 +596,11 @@ def __init__(self,
         self.basecls = basecls
 
     def close(self):
-        self.impl.close()
-        self.outs = None
-        self.ins = None
-        SuperSocket.close(self)
+        if not self.closed:
+            self.impl.close()
+            self.outs = None
+            self.ins = None
+            SuperSocket.close(self)
 
     def begin_send(self, p):
         """Begin the transmission of message p. This method returns after


Test patch:
Repository: secdev/scapy

Issue:
KRACK module requires python-cryptography
When `python-cryptography` or `python3-cryptography` packages are not installed, the KRACK module cannot be loaded.

```
>>> load_module("krack")
ERROR: Loading module scapy.modules.krack
Traceback (most recent call last):
  File "/home/ria/scapy/scapy/main.py", line 150, in _load
    mod = importlib.import_module(module)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ria/scapy/scapy/modules/krack/__init__.py", line 28, in <module>
    from scapy.modules.krack.automaton import KrackAP  # noqa: F401
  File "/home/ria/scapy/scapy/modules/krack/automaton.py", line 7, in <module>
    from cryptography.hazmat.primitives import hashes
ModuleNotFoundError: No module named 'cryptography'
```

Calling @commial to assess whether the module could still offer functionalities with a `crypto_valid` around some blocks. But at first glance I believe a missing `cryptography` should completely prevent importing the module.

https://github.com/secdev/scapy/blob/a58e1b90a704c394216a0b5a864a50931754bdf7/scapy/modules/krack/automaton.py#L6-L10

https://github.com/secdev/scapy/blob/a58e1b90a704c394216a0b5a864a50931754bdf7/scapy/modules/krack/crypto.py#L6-L9


Discussion:
Hi,

This is indeed needed to install the PMK. I'm not sure the module still has an interest without being able to compute it. So preventing the module to be imported seems the right solution to me.

Resolving patch:
diff --git a/scapy/modules/krack/__init__.py b/scapy/modules/krack/__init__.py
--- a/scapy/modules/krack/__init__.py
+++ b/scapy/modules/krack/__init__.py
@@ -1,5 +1,7 @@
 """Module implementing Krack Attack on client, as a custom WPA Access Point
 
+Requires the python cryptography package v1.7+. See https://cryptography.io/
+
 More details on the attack can be found on https://www.krackattacks.com/
 
 Example of use (from the scapy shell):
@@ -25,4 +27,10 @@
 - Client is likely not vulnerable to CVE-2017-13080
 """
 
-from scapy.modules.krack.automaton import KrackAP  # noqa: F401
+from scapy.config import conf
+
+if conf.crypto_valid:
+    from scapy.modules.krack.automaton import KrackAP  # noqa: F401
+else:
+    raise ImportError("Cannot import Krack module due to missing dependency. "
+                      "Please install python{3}-cryptography v1.7+.")


Test patch:
Repository: secdev/scapy

Issue:
Broken sendp(realtime=True)
`sendp(..., realtime=True)` is broken in scapy 2.4.3
It produces TypeError:

```
File "/usr/local/lib/python3.7/dist-packages/scapy/sendrecv.py", line 290, in __gen_send
    dt0 = ct - p.time
TypeError: unsupported operand type(s) for -: 'float' and 'decimal.Decimal'
```

The issue is introduced by this commit:
ebd4e26d - fix double precision for timestamp (4 months ago) <Sergey Platonov>





Discussion:
Where do the packet you are trying come from? Did you read them from a PCAP file (which I suspect)?

Resolving patch:
diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py
--- a/scapy/sendrecv.py
+++ b/scapy/sendrecv.py
@@ -283,11 +283,11 @@ def __gen_send(s, x, inter=0, loop=0, count=None, verbose=None, realtime=None, r
                 if realtime:
                     ct = time.time()
                     if dt0:
-                        st = dt0 + p.time - ct
+                        st = dt0 + float(p.time) - ct
                         if st > 0:
                             time.sleep(st)
                     else:
-                        dt0 = ct - p.time
+                        dt0 = ct - float(p.time)
                 s.send(p)
                 if return_packets:
                     sent_packets.append(p)


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -1351,6 +1351,12 @@ def _test():
     
     tmp = sendp(Ether()/IP(dst="8.8.8.8")/ICMP(), return_packets=True, realtime=True)
     assert(len(tmp) == 1)
+    
+    p = Ether()/IP(dst="8.8.8.8")/ICMP()
+    from decimal import Decimal
+    p.time = Decimal(p.time)
+    tmp = sendp(p, return_packets=True, realtime=True)
+    assert(len(tmp) == 1)
 
 retry_test(_test)