prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  
  </issue>
  <code>
  [start of scapy/layers/ntp.py]
  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 of scapy/layers/ntp.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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:
  
verification_info: {"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"}]}