We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unable to Accurately Set Time Fields in NTP Layer
I'm trying to modify the time fields in the NTP layer, and not having any luck. I've tried setting packet.recv to an integer value and a string representation of time, but no matter what I try, when I send the packet, this field is always set to the default 0. Is there any example code that I just missed that would show me how to do this? Thank you in advance.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scapy/layers/ntp.py`
Content:
```
1 ## This file is part of Scapy
2 ## See http://www.secdev.org/projects/scapy for more informations
3 ## Copyright (C) Philippe Biondi <phil@secdev.org>
4 ## This program is published under a GPLv2 license
5 
6 """
7 NTP (Network Time Protocol).
8 """
9 
10 import time
11 from scapy.packet import *
12 from scapy.fields import *
13 from scapy.layers.inet import UDP
14 
15 
16 # seconds between 01-01-1900 and 01-01-1970
17 _NTP_BASETIME = 2208988800
18 
19 class TimeStampField(FixedPointField):
20     def __init__(self, name, default):
21         FixedPointField.__init__(self, name, default, 64, 32)
22 
23     def i2repr(self, pkt, val):
24         if val is None:
25             return "--"
26         val = self.i2h(pkt,val)
27         if val < _NTP_BASETIME:
28             return val
29         return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(val-_NTP_BASETIME))
30 
31     def any2i(self, pkt, val):
32         if type(val) is str:
33             return int(time.mktime(time.strptime(val))) + _NTP_BASETIME + 3600 # XXX
34         return FixedPointField.any2i(self,pkt,val)
35     
36     def i2m(self, pkt, val):
37         if val is None:
38             val = FixedPointField.any2i(self, pkt, time.time()+_NTP_BASETIME)
39         return FixedPointField.i2m(self, pkt, val)
40         
41 
42 
43 class NTP(Packet):
44     # RFC 1769
45     name = "NTP"
46     fields_desc = [ 
47          BitEnumField('leap', 0, 2,
48                       { 0: 'nowarning',
49                         1: 'longminute',
50                         2: 'shortminute',
51                         3: 'notsync'}),
52          BitField('version', 3, 3),
53          BitEnumField('mode', 3, 3,
54                       { 0: 'reserved',
55                         1: 'sym_active',
56                         2: 'sym_passive',
57                         3: 'client',
58                         4: 'server',
59                         5: 'broadcast',
60                         6: 'control',
61                         7: 'private'}),
62          BitField('stratum', 2, 8),
63          BitField('poll', 0xa, 8),          ### XXX : it's a signed int
64          BitField('precision', 0, 8),       ### XXX : it's a signed int
65          FixedPointField('delay', 0, size=32, frac_bits=16),
66          FixedPointField('dispersion', 0, size=32, frac_bits=16),
67          IPField('id', "127.0.0.1"),
68          TimeStampField('ref', 0),
69          TimeStampField('orig', None),  # None means current time
70          TimeStampField('recv', 0),
71          TimeStampField('sent', None) 
72          ]
73     def mysummary(self):
74         return self.sprintf("NTP v%ir,NTP.version%, %NTP.mode%")
75 
76 
77 bind_layers( UDP,           NTP,           dport=123, sport=123)
78
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py
--- a/scapy/layers/ntp.py
+++ b/scapy/layers/ntp.py
@@ -8,6 +8,7 @@
 """
 
 import time
+import datetime
 from scapy.packet import *
 from scapy.fields import *
 from scapy.layers.inet import UDP
@@ -29,9 +30,11 @@
         return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(val-_NTP_BASETIME))
 
     def any2i(self, pkt, val):
-        if type(val) is str:
-            return int(time.mktime(time.strptime(val))) + _NTP_BASETIME + 3600 # XXX
-        return FixedPointField.any2i(self,pkt,val)
+        if isinstance(val, basestring):
+            val = int(time.mktime(time.strptime(val))) + _NTP_BASETIME
+        elif isinstance(val, datetime.datetime):
+            val = int(val.strftime("%s")) + _NTP_BASETIME
+        return FixedPointField.any2i(self, pkt, val)
     
     def i2m(self, pkt, val):
         if val is None:

{"golden_diff": "diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py\n--- a/scapy/layers/ntp.py\n+++ b/scapy/layers/ntp.py\n@@ -8,6 +8,7 @@\n \"\"\"\n \n import time\n+import datetime\n from scapy.packet import *\n from scapy.fields import *\n from scapy.layers.inet import UDP\n@@ -29,9 +30,11 @@\n         return time.strftime(\"%a, %d %b %Y %H:%M:%S +0000\", time.gmtime(val-_NTP_BASETIME))\n \n     def any2i(self, pkt, val):\n-        if type(val) is str:\n-            return int(time.mktime(time.strptime(val))) + _NTP_BASETIME + 3600 # XXX\n-        return FixedPointField.any2i(self,pkt,val)\n+        if isinstance(val, basestring):\n+            val = int(time.mktime(time.strptime(val))) + _NTP_BASETIME\n+        elif isinstance(val, datetime.datetime):\n+            val = int(val.strftime(\"%s\")) + _NTP_BASETIME\n+        return FixedPointField.any2i(self, pkt, val)\n     \n     def i2m(self, pkt, val):\n         if val is None:\n", "issue": "Unable to Accurately Set Time Fields in NTP Layer\nI'm trying to modify the time fields in the NTP layer, and not having any luck. I've tried setting packet.recv to an integer value and a string representation of time, but no matter what I try, when I send the packet, this field is always set to the default 0. Is there any example code that I just missed that would show me how to do this? Thank you in advance.\n\n", "before_files": [{"content": "## This file is part of Scapy\n## See http://www.secdev.org/projects/scapy for more informations\n## Copyright (C) Philippe Biondi <phil@secdev.org>\n## This program is published under a GPLv2 license\n\n\"\"\"\nNTP (Network Time Protocol).\n\"\"\"\n\nimport time\nfrom scapy.packet import *\nfrom scapy.fields import *\nfrom scapy.layers.inet import UDP\n\n\n# seconds between 01-01-1900 and 01-01-1970\n_NTP_BASETIME = 2208988800\n\nclass TimeStampField(FixedPointField):\n    def __init__(self, name, default):\n        FixedPointField.__init__(self, name, default, 64, 32)\n\n    def i2repr(self, pkt, val):\n        if val is None:\n            return \"--\"\n        val = self.i2h(pkt,val)\n        if val < _NTP_BASETIME:\n            return val\n        return time.strftime(\"%a, %d %b %Y %H:%M:%S +0000\", time.gmtime(val-_NTP_BASETIME))\n\n    def any2i(self, pkt, val):\n        if type(val) is str:\n            return int(time.mktime(time.strptime(val))) + _NTP_BASETIME + 3600 # XXX\n        return FixedPointField.any2i(self,pkt,val)\n    \n    def i2m(self, pkt, val):\n        if val is None:\n            val = FixedPointField.any2i(self, pkt, time.time()+_NTP_BASETIME)\n        return FixedPointField.i2m(self, pkt, val)\n        \n\n\nclass NTP(Packet):\n    # RFC 1769\n    name = \"NTP\"\n    fields_desc = [ \n         BitEnumField('leap', 0, 2,\n                      { 0: 'nowarning',\n                        1: 'longminute',\n                        2: 'shortminute',\n                        3: 'notsync'}),\n         BitField('version', 3, 3),\n         BitEnumField('mode', 3, 3,\n                      { 0: 'reserved',\n                        1: 'sym_active',\n                        2: 'sym_passive',\n                        3: 'client',\n                        4: 'server',\n                        5: 'broadcast',\n                        6: 'control',\n                        7: 'private'}),\n         BitField('stratum', 2, 8),\n         BitField('poll', 0xa, 8),          ### XXX : it's a signed int\n         BitField('precision', 0, 8),       ### XXX : it's a signed int\n         FixedPointField('delay', 0, size=32, frac_bits=16),\n         FixedPointField('dispersion', 0, size=32, frac_bits=16),\n         IPField('id', \"127.0.0.1\"),\n         TimeStampField('ref', 0),\n         TimeStampField('orig', None),  # None means current time\n         TimeStampField('recv', 0),\n         TimeStampField('sent', None) \n         ]\n    def mysummary(self):\n        return self.sprintf(\"NTP v%ir,NTP.version%, %NTP.mode%\")\n\n\nbind_layers( UDP,           NTP,           dport=123, sport=123)\n", "path": "scapy/layers/ntp.py"}], "after_files": [{"content": "## This file is part of Scapy\n## See http://www.secdev.org/projects/scapy for more informations\n## Copyright (C) Philippe Biondi <phil@secdev.org>\n## This program is published under a GPLv2 license\n\n\"\"\"\nNTP (Network Time Protocol).\n\"\"\"\n\nimport time\nimport datetime\nfrom scapy.packet import *\nfrom scapy.fields import *\nfrom scapy.layers.inet import UDP\n\n\n# seconds between 01-01-1900 and 01-01-1970\n_NTP_BASETIME = 2208988800\n\nclass TimeStampField(FixedPointField):\n    def __init__(self, name, default):\n        FixedPointField.__init__(self, name, default, 64, 32)\n\n    def i2repr(self, pkt, val):\n        if val is None:\n            return \"--\"\n        val = self.i2h(pkt,val)\n        if val < _NTP_BASETIME:\n            return val\n        return time.strftime(\"%a, %d %b %Y %H:%M:%S +0000\", time.gmtime(val-_NTP_BASETIME))\n\n    def any2i(self, pkt, val):\n        if isinstance(val, basestring):\n            val = int(time.mktime(time.strptime(val))) + _NTP_BASETIME\n        elif isinstance(val, datetime.datetime):\n            val = int(val.strftime(\"%s\")) + _NTP_BASETIME\n        return FixedPointField.any2i(self, pkt, val)\n    \n    def i2m(self, pkt, val):\n        if val is None:\n            val = FixedPointField.any2i(self, pkt, time.time()+_NTP_BASETIME)\n        return FixedPointField.i2m(self, pkt, val)\n        \n\n\nclass NTP(Packet):\n    # RFC 1769\n    name = \"NTP\"\n    fields_desc = [ \n         BitEnumField('leap', 0, 2,\n                      { 0: 'nowarning',\n                        1: 'longminute',\n                        2: 'shortminute',\n                        3: 'notsync'}),\n         BitField('version', 3, 3),\n         BitEnumField('mode', 3, 3,\n                      { 0: 'reserved',\n                        1: 'sym_active',\n                        2: 'sym_passive',\n                        3: 'client',\n                        4: 'server',\n                        5: 'broadcast',\n                        6: 'control',\n                        7: 'private'}),\n         BitField('stratum', 2, 8),\n         BitField('poll', 0xa, 8),          ### XXX : it's a signed int\n         BitField('precision', 0, 8),       ### XXX : it's a signed int\n         FixedPointField('delay', 0, size=32, frac_bits=16),\n         FixedPointField('dispersion', 0, size=32, frac_bits=16),\n         IPField('id', \"127.0.0.1\"),\n         TimeStampField('ref', 0),\n         TimeStampField('orig', None),  # None means current time\n         TimeStampField('recv', 0),\n         TimeStampField('sent', None) \n         ]\n    def mysummary(self):\n        return self.sprintf(\"NTP v%ir,NTP.version%, %NTP.mode%\")\n\n\nbind_layers( UDP,           NTP,           dport=123, sport=123)\n", "path": "scapy/layers/ntp.py"}]}