From: Joel VanderWerf Date: 2005-10-10T10:31:29+09:00 Subject: Re: [ANN] BitStruct Someone asked offline about block-based initialization, and BitStruct supports that, as well as hash-based and string-based. Here are the variants: ip1 = IP.new ip1.ip_tos = 0 ip1.ip_len = 0 ip1.ip_id = 0 ip1.ip_off = 0 ip1.ip_ttl = 255 ip1.ip_p = 255 ip1.ip_sum = 0 ip1.ip_src = "192.168.1.4" ip1.ip_dst = "192.168.1.255" ip1.body = "This is the payload text." ip1.ip_len = ip1.length ip2 = IP.new do |ip| ip.ip_tos = 0 ip.ip_len = 0 ip.ip_id = 0 ip.ip_off = 0 ip.ip_ttl = 255 ip.ip_p = 255 ip.ip_sum = 0 ip.ip_src = "192.168.1.4" ip.ip_dst = "192.168.1.255" ip.body = "This is the payload text." ip.ip_len = ip.length end ip3 = IP.new( :ip_tos => 0, :ip_len => 0, :ip_id => 0, :ip_off => 0, :ip_ttl => 255, :ip_p => 255, :ip_sum => 0, :ip_src => "192.168.1.4", :ip_dst => "192.168.1.255", :body => "This is the payload text." ) do |ip| ip.ip_len = ip.length end ip4 = IP.new(ip1) # Construct from a BitStruct (or String) Btw, if you've ever wanted to write ping in ruby, check out ping-recv.rb in the example dir. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407