class Lib::BOOTP::Packet
Public Class Methods
new(op: 1, htype: 1, hlen: 6, hops: 0, xid: nil, secs: 0, flags: 0, ciaddr: 0, yiaddr: 0, siaddr: 0, giaddr: 0, chaddr: nil, sname: '.', file: '.')
click to toggle source
# File lib/lib/bootp.rb, line 38 def initialize(op: 1, htype: 1, hlen: 6, hops: 0, xid: nil, secs: 0, flags: 0, ciaddr: 0, yiaddr: 0, siaddr: 0, giaddr: 0, chaddr: nil, sname: '.', file: '.') @packets = {} @packets[:op] = (op.is_a? Lib::BOOTP::Packet::OpCode) ? op : Lib::BOOTP::Packet::OpCode.new(op) @packets[:htype] = (htype.is_a? Lib::BOOTP::Packet::HardwareAddressType) ? htype : Lib::BOOTP::Packet::HardwareAddressType.new(htype) @packets[:hlen] = (hlen.is_a? Lib::BOOTP::Packet::HardwareAddressLength) ? hlen : Lib::BOOTP::Packet::HardwareAddressLength.new(hlen) @packets[:hops] = (hops.is_a? Lib::BOOTP::Packet::HopCount) ? hops : Lib::BOOTP::Packet::HopCount.new(hops) @packets[:xid] = (xid.is_a? Lib::BOOTP::Packet::TransactionID) ? xid : Lib::BOOTP::Packet::TransactionID.new(xid) @packets[:secs] = (secs.is_a? Lib::BOOTP::Packet::Seconds) ? secs : Lib::BOOTP::Packet::Seconds.new(secs) @packets[:flags] = (flags.is_a? Lib::BOOTP::Packet::Flags) ? flags : Lib::BOOTP::Packet::Flags.new(flags) @packets[:ciaddr] = (ciaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? ciaddr : Lib::BOOTP::Packet::IPAddress.new(ciaddr) @packets[:yiaddr] = (yiaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? yiaddr : Lib::BOOTP::Packet::IPAddress.new(yiaddr) @packets[:siaddr] = (siaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? siaddr : Lib::BOOTP::Packet::IPAddress.new(siaddr) @packets[:giaddr] = (giaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? giaddr : Lib::BOOTP::Packet::IPAddress.new(giaddr) @packets[:chaddr] = (chaddr.is_a? Lib::BOOTP::Packet::ClientHardwareAddress) ? chaddr : Lib::BOOTP::Packet::ClientHardwareAddress.new(chaddr) @packets[:sname] = (sname.is_a? Lib::BOOTP::Packet::ServerHostName) ? sname : Lib::BOOTP::Packet::ServerHostName.new(sname) @packets[:file] = (file.is_a? Lib::BOOTP::Packet::BootFile) ? file : Lib::BOOTP::Packet::BootFile.new(file) end
unpack(packet)
click to toggle source
# File lib/lib/bootp.rb, line 151 def self.unpack(packet) op, htype, hlen, hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file = packet.unpack('C4NnnN4a16a64a128') op = Lib::BOOTP::Packet::OpCode.new op htype = Lib::BOOTP::Packet::HardwareAddressType.new htype hlen = Lib::BOOTP::Packet::HardwareAddressLength.new hlen hops = Lib::BOOTP::Packet::HopCount.new hops xid = Lib::BOOTP::Packet::TransactionID.new xid secs = Lib::BOOTP::Packet::Seconds.new secs flags = Lib::BOOTP::Packet::Flags.new flags ciaddr = Lib::BOOTP::Packet::IPAddress.new ciaddr yiaddr = Lib::BOOTP::Packet::IPAddress.new yiaddr siaddr = Lib::BOOTP::Packet::IPAddress.new siaddr giaddr = Lib::BOOTP::Packet::IPAddress.new giaddr chaddr = Lib::BOOTP::Packet::ClientHardwareAddress.unpack chaddr sname = Lib::BOOTP::Packet::ServerHostName.unpack sname file = Lib::BOOTP::Packet::BootFile.unpack file self.new(op:op, htype:htype, hlen:hlen, hops:hops, xid:xid, secs:secs, flags:flags, ciaddr:ciaddr, yiaddr:yiaddr, siaddr:siaddr, giaddr:giaddr, chaddr:chaddr, sname:sname, file:file) end
Private Class Methods
hash_attr_reader(hash_name, *key_names)
click to toggle source
# File lib/lib/bootp.rb, line 26 def hash_attr_reader(hash_name, *key_names) key_names.each do |key_name| define_method key_name do instance_variable_get("@#{hash_name}")[key_name] end end end
Public Instance Methods
chaddr=(chaddr)
click to toggle source
# File lib/lib/bootp.rb, line 100 def chaddr=(chaddr) @packets[:chaddr] = (chaddr.is_a? Lib::BOOTP::Packet::ClientHardwareAddress) ? chaddr : Lib::BOOTP::Packet::ClientHardwareAddress.new(chaddr) end
ciaddr=(ciaddr)
click to toggle source
# File lib/lib/bootp.rb, line 84 def ciaddr=(ciaddr) @packets[:ciaddr] = (ciaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? ciaddr : Lib::BOOTP::Packet::IPAddress.new(ciaddr) end
file=(file)
click to toggle source
# File lib/lib/bootp.rb, line 108 def file=(file) @packets[:file] = (file.is_a? Lib::BOOTP::Packet::BootFile) ? file : Lib::BOOTP::Packet::BootFile.new(file) end
flags=(flags)
click to toggle source
# File lib/lib/bootp.rb, line 80 def flags=(flags) @packets[:flags] = (flags.is_a? Lib::BOOTP::Packet::Flags) ? flags : Lib::BOOTP::Packet::Flags.new(flags) end
giaddr=(giaddr)
click to toggle source
# File lib/lib/bootp.rb, line 96 def giaddr=(giaddr) @packets[:giaddr] = (giaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? giaddr : Lib::BOOTP::Packet::IPAddress.new(giaddr) end
hlen=(hlen)
click to toggle source
# File lib/lib/bootp.rb, line 64 def hlen=(hlen) @packets[:hlen] = (hlen.is_a? Lib::BOOTP::Packet::HardwareAddressLength) ? hlen : Lib::BOOTP::Packet::HardwareAddressLength.new(hlen) end
hops=(hops)
click to toggle source
# File lib/lib/bootp.rb, line 68 def hops=(hops) @packets[:hops] = (hops.is_a? Lib::BOOTP::Packet::HopCount) ? hops : Lib::BOOTP::Packet::HopCount.new(hops) end
htype=(htype)
click to toggle source
# File lib/lib/bootp.rb, line 60 def htype=(htype) @packets[:htype] = (htype.is_a? Lib::BOOTP::Packet::HardwareAddressType) ? htype : Lib::BOOTP::Packet::HardwareAddressType.new(htype) end
op=(op)
click to toggle source
# File lib/lib/bootp.rb, line 56 def op=(op) @packets[:op] = (op.is_a? Lib::BOOTP::Packet::OpCode) ? op : Lib::BOOTP::Packet::OpCode.new(op) end
pack()
click to toggle source
# File lib/lib/bootp.rb, line 134 def pack self.op.pack + self.htype.pack + self.hlen.pack + self.hops.pack + self.xid.pack + self.secs.pack + self.flags.pack + self.ciaddr.pack + self.yiaddr.pack + self.siaddr.pack + self.giaddr.pack + self.chaddr.pack + self.sname.pack + self.file.pack end
secs=(secs)
click to toggle source
# File lib/lib/bootp.rb, line 76 def secs=(secs) @packets[:secs] = (secs.is_a? Lib::BOOTP::Packet::Seconds) ? secs : Lib::BOOTP::Packet::Seconds.new(secs) end
siaddr=(siaddr)
click to toggle source
# File lib/lib/bootp.rb, line 92 def siaddr=(siaddr) @packets[:siaddr] = (siaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? siaddr : Lib::BOOTP::Packet::IPAddress.new(siaddr) end
sname=(sname)
click to toggle source
# File lib/lib/bootp.rb, line 104 def sname=(sname) @packets[:sname] = (sname.is_a? Lib::BOOTP::Packet::ServerHostName) ? sname : Lib::BOOTP::Packet::ServerHostName.new(sname) end
to_h()
click to toggle source
# File lib/lib/bootp.rb, line 113 def to_h @packets end
to_s()
click to toggle source
# File lib/lib/bootp.rb, line 117 def to_s "OP: #{self.op}"+ "\nHTYPE: #{self.htype}"+ "\nHLEN: #{self.hlen}"+ "\nHOPS: #{self.hops}"+ "\nXID: #{self.xid}"+ "\nSECS: #{self.secs}"+ "\nFLAGS: #{self.flags}"+ "\nCIADDR: #{self.ciaddr}"+ "\nYIADDR: #{self.yiaddr}"+ "\nSIADDR: #{self.siaddr}"+ "\nGIADDR: #{self.giaddr}"+ "\nCHADDR: #{self.chaddr}"+ "\nSNAME: #{self.sname}"+ "\nFILE: #{self.file}" end
xid=(xid)
click to toggle source
# File lib/lib/bootp.rb, line 72 def xid=(xid) @packets[:xid] = (xid.is_a? Lib::BOOTP::Packet::TransactionID) ? xid : Lib::BOOTP::Packet::TransactionID.new(xid) end
yiaddr=(yiaddr)
click to toggle source
# File lib/lib/bootp.rb, line 88 def yiaddr=(yiaddr) @packets[:yiaddr] = (yiaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? yiaddr : Lib::BOOTP::Packet::IPAddress.new(yiaddr) end