diff --git a/lib/netlink/c_struct.rb b/lib/netlink/c_struct.rb index 291c571..a7cb594 100644 --- a/lib/netlink/c_struct.rb +++ b/lib/netlink/c_struct.rb @@ -96,7 +96,7 @@ class CStruct if h.instance_of?(self.class) @attrs = h.to_hash.dup else - @attrs = self.class::DEFAULTS.dup + @attrs = {} h.each { |k,v| self[k] = v } if h end end @@ -153,7 +153,7 @@ class CStruct self::DEFAULTS[name] = default define_method name do - @attrs.fetch name + @attrs[name] end define_method "#{name}=" do |val| @attrs.store name, val @@ -170,7 +170,7 @@ class CStruct # Returns the packed binary representation of this structure def to_str - self.class::FIELDS.map { |key| self[key] }.pack(self.class::FORMAT) + self.class::FIELDS.map { |key| self[key] || self.class::DEFAULTS[key] }.pack(self.class::FORMAT) end def inspect diff --git a/lib/netlink/route.rb b/lib/netlink/route.rb index db575f7..9f65693 100644 --- a/lib/netlink/route.rb +++ b/lib/netlink/route.rb @@ -40,7 +40,7 @@ module Netlink end # Convert an interface index into name string, or nil if the - # index is nil or empty string. Raises exception for unknown values. + # index is nil or 0. Raises exception for unknown values. # # nl = Netlink::Route::Socket.new # nl.routes(:family=>Socket::AF_INET) do |route|