File tree Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change 1
- #![ feature( net) ]
2
1
extern crate time;
3
2
extern crate byteorder;
4
3
5
4
mod ntp;
6
5
7
- use std:: net:: { UdpSocket , lookup_host , SocketAddr } ;
6
+ use std:: net:: { UdpSocket } ;
8
7
use time:: Timespec ;
9
8
10
9
const NTP_PORT : u16 = 123 ;
@@ -16,14 +15,13 @@ const UDP_LOCAL: &'static str = "0.0.0.0:35000";
16
15
///
17
16
/// * `host` - The NTP server (i.e. sundial.columbia.edu).
18
17
pub fn retrieve_ntp_timestamp ( host : & str ) -> Result < Timespec , std:: io:: Error > {
19
- let host = try!( lookup_host ( host) ) . next ( ) . unwrap ( ) ;
20
- let addr = SocketAddr :: new ( try!( host) . ip ( ) , NTP_PORT ) ;
21
18
let header = ntp:: NTPHeader :: new ( ) ;
22
19
let message = header. encode ( ) ;
23
20
24
21
let socket = try!( UdpSocket :: bind ( UDP_LOCAL ) ) ;
25
22
26
- try!( socket. send_to ( & message[ ..] , & addr) ) ;
23
+ let host = format ! ( "{host}:{port}" , host=host, port=NTP_PORT ) ;
24
+ try!( socket. send_to ( & message[ ..] , & host[ ..] ) ) ;
27
25
28
26
let mut buf = [ 0u8 ; 1000 ] ;
29
27
You can’t perform that action at this time.
0 commit comments