[Gd-chatter] r11642 - trunk/libraries/protocols
lobo at gwydiondylan.org
lobo at gwydiondylan.org
Sat Jan 19 20:31:53 CET 2008
Author: lobo
Date: Sat Jan 19 20:31:52 2008
New Revision: 11642
Modified:
trunk/libraries/protocols/ntp.dylan
trunk/libraries/protocols/protocols-library.dylan
Log:
Bug: 7299
- make usage of enum fields
- added default value to unix-time-value fields
- removed summary method
Modified: trunk/libraries/protocols/ntp.dylan
==============================================================================
--- trunk/libraries/protocols/ntp.dylan (original)
+++ trunk/libraries/protocols/ntp.dylan Sat Jan 19 20:31:52 2008
@@ -2,26 +2,23 @@
// Simple Network Time Protocol (SNTP) RFC 1769
define protocol ntp (container-frame)
+ summary "NTP v%= mode: %=", version, mode;
over <udp-frame> 123;
- field leap-indicator :: <2bit-unsigned-integer> = 0;
- /*
- 0 nowarning
- 1 longminute, last minute has 61 seconds
- 2 shortminute, last minute has 59 seconds
- 3 notsync, alarm condition (clock not synchronized)
- */
+ enum field leap-indicator :: <2bit-unsigned-integer> = 0,
+ mappings: { 0 <=> #"nowarning",
+ 1 <=> #"longminute",
+ 2 <=> #"shortminute",
+ 3 <=> #"notsync" };
field version :: <3bit-unsigned-integer> = 3;
- /*
- 0 reserved
- 1 symmetric active
- 2 symmetric passive
- 3 client
- 4 server
- 5 broadcast
- 6 control
- 7 private
- */
- field mode :: <3bit-unsigned-integer> = 3;
+ enum field mode :: <3bit-unsigned-integer> = 3,
+ mappings: { 0 <=> #"reserved",
+ 1 <=> #"symmetric active",
+ 2 <=> #"symmetric passive",
+ 3 <=> #"client",
+ 4 <=> #"server",
+ 5 <=> #"broadcast",
+ 6 <=> #"control",
+ 7 <=> #"private" };
/*
0 unspecified or unavailable
1 primary reference (e.g., radio clock)
@@ -34,28 +31,16 @@
field root-delay :: <big-endian-unsigned-integer-4byte> = 0;
field root-dispersion :: <big-endian-unsigned-integer-4byte> = 0;
field reference-clock-id :: <ipv4-address>;
- field reference-timestamp :: <unix-time-value>;
- field originate-timestamp :: <unix-time-value>;
- field receive-timestamp :: <unix-time-value>;
- field transmit-timestamp :: <unix-time-value>;
+ field reference-timestamp :: <unix-time-value>
+ = make-unix-time(current-date() - make(<date>, year: 1970, month: 1, day: 1));
+ field originate-timestamp :: <unix-time-value>
+ = make-unix-time(current-date() - make(<date>, year: 1970, month: 1, day: 1));
+ field receive-timestamp :: <unix-time-value>
+ = make-unix-time(current-date() - make(<date>, year: 1970, month: 1, day: 1));
+ field transmit-timestamp :: <unix-time-value>
+ = make-unix-time(current-date() - make(<date>, year: 1970, month: 1, day: 1));
/* Authenticator (optional)
field key-id :: <big-endian-unsigned-integer-4byte>;
field message-authentication-code :: 16 bytes
*/
end;
-
-define method summary (frame :: <ntp>) => (res :: <string>)
- if(frame.mode = 1)
- format-to-string("NTP v%= Symmetric active", frame.version)
- elseif(frame.mode = 2)
- format-to-string("NTP v%= Symmetric passive", frame.version)
- elseif(frame.mode = 3)
- format-to-string("NTP v%= Client", frame.version)
- elseif(frame.mode = 4)
- format-to-string("NTP v%= Server", frame.version)
- else
- format-to-string("NTP v%= mode: %=",
- frame.version,
- frame.mode)
- end
-end;
Modified: trunk/libraries/protocols/protocols-library.dylan
==============================================================================
--- trunk/libraries/protocols/protocols-library.dylan (original)
+++ trunk/libraries/protocols/protocols-library.dylan Sat Jan 19 20:31:52 2008
@@ -469,8 +469,9 @@
define module ntp
use dylan;
use packetizer;
+ use date;
use format;
use ipv4, import: { ipv4-address, <ipv4-address>, <udp-frame> };
- use pcap, import: { <unix-time-value> };
+ use pcap, import: { <unix-time-value>, make-unix-time };
end;
More information about the chatter
mailing list