Class: Net::NTP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ntp/ntp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, client_time_receive) ⇒ Response

Returns a new instance of Response.



107
108
109
110
111
# File 'lib/net/ntp/ntp.rb', line 107

def initialize(raw_data, client_time_receive)
  @raw_data             = raw_data
  @client_time_receive  = client_time_receive
  @packet_data_by_field = nil
end

Instance Attribute Details

#client_time_receiveObject (readonly)

Returns the value of attribute client_time_receive.



105
106
107
# File 'lib/net/ntp/ntp.rb', line 105

def client_time_receive
  @client_time_receive
end

Instance Method Details

#leap_indicatorObject



113
114
115
# File 'lib/net/ntp/ntp.rb', line 113

def leap_indicator
  @leap_indicator ||= (packet_data_by_field[:byte1].bytes.first & 0xC0) >> 6
end

#leap_indicator_textObject



117
118
119
# File 'lib/net/ntp/ntp.rb', line 117

def leap_indicator_text
  @leap_indicator_text ||= LEAP_INDICATOR[leap_indicator]
end

#modeObject



125
126
127
# File 'lib/net/ntp/ntp.rb', line 125

def mode
  @mode ||= (packet_data_by_field[:byte1].bytes.first & 0x07)
end

#mode_textObject



129
130
131
# File 'lib/net/ntp/ntp.rb', line 129

def mode_text
  @mode_text ||= MODE[mode]
end

#offsetObject

As described in tools.ietf.org/html/rfc958



186
187
188
# File 'lib/net/ntp/ntp.rb', line 186

def offset
  @offset ||= (receive_timestamp - originate_timestamp + transmit_timestamp - client_time_receive) / 2.0
end

#originate_timestampObject



169
170
171
# File 'lib/net/ntp/ntp.rb', line 169

def originate_timestamp
  @originate_timestamp ||= (packet_data_by_field[:org_time] + bin2frac(packet_data_by_field[:org_time_fb]))
end

#poll_intervalObject



141
142
143
# File 'lib/net/ntp/ntp.rb', line 141

def poll_interval
  @poll_interval ||= packet_data_by_field[:poll]
end

#precisionObject



145
146
147
# File 'lib/net/ntp/ntp.rb', line 145

def precision
  @precision ||= packet_data_by_field[:precision] - 255
end

#receive_timestampObject



173
174
175
# File 'lib/net/ntp/ntp.rb', line 173

def receive_timestamp
  @receive_timestamp ||= ((packet_data_by_field[:recv_time] + bin2frac(packet_data_by_field[:recv_time_fb])) - NTP_ADJ)
end

#reference_clock_identifierObject



157
158
159
# File 'lib/net/ntp/ntp.rb', line 157

def reference_clock_identifier
  @reference_clock_identifier ||= unpack_ip(packet_data_by_field[:stratum], packet_data_by_field[:ident])
end

#reference_clock_identifier_textObject



161
162
163
# File 'lib/net/ntp/ntp.rb', line 161

def reference_clock_identifier_text
  @reference_clock_identifier_text ||= REFERENCE_CLOCK_IDENTIFIER[reference_clock_identifier]
end

#reference_timestampObject



165
166
167
# File 'lib/net/ntp/ntp.rb', line 165

def reference_timestamp
  @reference_timestamp ||= ((packet_data_by_field[:ref_time] + bin2frac(packet_data_by_field[:ref_time_fb])) - NTP_ADJ)
end

#root_delayObject



149
150
151
# File 'lib/net/ntp/ntp.rb', line 149

def root_delay
  @root_delay ||= bin2frac(packet_data_by_field[:delay_fb])
end

#root_dispersionObject



153
154
155
# File 'lib/net/ntp/ntp.rb', line 153

def root_dispersion
  @root_dispersion ||= packet_data_by_field[:disp]
end

#stratumObject



133
134
135
# File 'lib/net/ntp/ntp.rb', line 133

def stratum
  @stratum ||= packet_data_by_field[:stratum]
end

#stratum_textObject



137
138
139
# File 'lib/net/ntp/ntp.rb', line 137

def stratum_text
  @stratum_text ||= STRATUM[stratum]
end

#timeObject



181
182
183
# File 'lib/net/ntp/ntp.rb', line 181

def time
  @time ||= Time.at(receive_timestamp)
end

#transmit_timestampObject



177
178
179
# File 'lib/net/ntp/ntp.rb', line 177

def transmit_timestamp
  @transmit_timestamp ||= ((packet_data_by_field[:trans_time] + bin2frac(packet_data_by_field[:trans_time_fb])) - NTP_ADJ)
end

#version_numberObject



121
122
123
# File 'lib/net/ntp/ntp.rb', line 121

def version_number
  @version_number ||= (packet_data_by_field[:byte1].bytes.first & 0x38) >> 3
end