Go to the source code of this file.
Functions/Subroutines | |
ret | usage () |
ret | Error (type message) |
ret | rdate (type args) |
Variables | |
package require | time |
ret Error | ( | type | message | ) |
ret rdate | ( | type | args | ) |
Definition at line 33 of file rdate.tcl.
References error(), Error(), p(), and usage().
Referenced by usage().
00033 { 00034 # process the command line options. 00035 array set opts {-p 0 -s 0 -a 0 -t 0 -u x -S 0} 00036 while {[string match -* [set option [lindex $args 0]]]} { 00037 switch -exact -- $option { 00038 -p { set opts(-p) 1 } 00039 -u { set opts(-t) 0 } 00040 -t { set opts(-t) 1 } 00041 -s { Error "not implemented: use rdate(8)" } 00042 -a { Error "not implemented: use rdate(8)" } 00043 -S { set opts(-S) 1 } 00044 -T { set opts(-S) 0 } 00045 -- { ::time::Pop args; break } 00046 default { 00047 set err [join [lsort [array names opts -*]] ", "] 00048 Error "bad option $option: must be $err" 00049 } 00050 } 00051 ::time::Pop args 00052 } 00053 00054 # Check that we have a host to talk to. 00055 if {[llength $args] != 1} { 00056 Error [usage] 00057 } 00058 set host [lindex $args 0] 00059 00060 # Construct the time command - optionally force the protocol to tcp 00061 set cmd ::time::gettime 00062 if {$opts(-S)} { 00063 set cmd ::time::getsntp 00064 } 00065 if {$opts(-t)} { 00066 lappend cmd -protocol tcp 00067 } 00068 lappend cmd $host 00069 00070 # Perform the RFC 868 query (synchronously) 00071 set tok [eval $cmd] 00072 00073 # Check for errors or extract the time in the unix epoch. 00074 set t 0 00075 if {[::time::status $tok] == "ok"} { 00076 set t [::time::unixtime $tok] 00077 ::time::cleanup $tok 00078 } else { 00079 set msg [::time::error $tok] 00080 ::time::cleanup $tok 00081 Error $msg 00082 } 00083 00084 # Display the time. 00085 if {$opts(-p)} { 00086 puts [clock format $t] 00087 } 00088 00089 return 0 00090 }
ret usage | ( | ) |
Definition at line 15 of file rdate.tcl.
References p(), rdate(), and time.
Referenced by rdate().
00015 { 00016 set s {usage: rdate [-psa] [-utS] host 00017 -p Do not set, just print the remote time. 00018 -s Do not print the time. [NOT IMPLEMENTED] 00019 -a Use the adjtime(2) call to gradually skew the local time to the 00020 remote time instead of just jumping. [NOT IMPLEMENTED] 00021 -u Use UDP (default if available) 00022 -t Use TCP 00023 -S Use SNTP protocol (RFC 2030) (default is TIME, RFC 868) 00024 } 00025 return $s 00026 }