class RadiusRB::Packet::Attribute
Attributes
dict[R]
name[R]
value[RW]
vendor[R]
Public Class Methods
new(dict, name, value, vendor=nil)
click to toggle source
# File lib/radiusrb/packet.rb, line 229 def initialize dict, name, value, vendor=nil @dict = dict # This is the cheapest and easiest way to add VSA's! if (name && (chunks = name.split('/')) && (chunks.size == 2)) @vendor = chunks[0] @name = chunks[1] else @name = name end @vendor ||= vendor @value = value.is_a?(Attribute) ? value.to_s : value end
Public Instance Methods
inspect()
click to toggle source
# File lib/radiusrb/packet.rb, line 261 def inspect @value end
pack()
click to toggle source
# File lib/radiusrb/packet.rb, line 246 def pack attribute = if (vendor? && (@dict.vendors.find_by_name(@vendor))) @dict.vendors.find_by_name(@vendor).attributes.find_by_name(@name) else @dict.find_attribute_by_name(@name) end raise "Undefined attribute '#{@name}'." if attribute.nil? if vendor? pack_vendor_specific_attribute attribute else pack_attribute attribute end end
to_s()
click to toggle source
# File lib/radiusrb/packet.rb, line 265 def to_s @value end
vendor?()
click to toggle source
# File lib/radiusrb/packet.rb, line 242 def vendor? !!@vendor end
Private Instance Methods
pack_attribute(attribute)
click to toggle source
# File lib/radiusrb/packet.rb, line 279 def pack_attribute attribute anum = attribute.id val = case attribute.type when "string" @value when "integer" raise "Invalid value name '#{@value}'." if attribute.has_values? && attribute.find_values_by_name(@value).nil? [attribute.has_values? ? attribute.find_values_by_name(@value).id : @value].pack("N") when "ipaddr" [@value.to_ip.to_i].pack("N") when "ipv6addr" ipi = @value.to_ip.to_i [ ipi >> 96, ipi >> 64, ipi >> 32, ipi ].pack("NNNN") when "date" [@value].pack("N") when "time" [@value].pack("N") else "" end begin [anum, val.length + 2, val ].pack(P_ATTR) rescue puts "#{@name} => #{@value}" puts [anum, val.length + 2, val].inspect end end
pack_vendor_specific_attribute(attribute)
click to toggle source
# File lib/radiusrb/packet.rb, line 271 def pack_vendor_specific_attribute attribute inside_attribute = pack_attribute attribute vid = attribute.vendor.id.to_i header = [ 26, inside_attribute.size + 6 ].pack("CC") # 26: Type = Vendor-Specific, 4: length of Vendor-Id field header += [ 0, vid >> 16, vid >> 8, vid ].pack("CCCC") # first byte of Vendor-Id is 0 header + inside_attribute end