Class: Scriptroute::UDP
Direct Known Subclasses
Constant Summary
Constants inherited from IPv4
IPv4::IPPROTO_ICMP, IPv4::IPPROTO_TCP, IPv4::IPPROTO_UDP
Instance Attribute Summary collapse
- #uh_dport ⇒ Fixnum
- #uh_sport ⇒ Fixnum readonly
- #uh_sum ⇒ Fixnum
- #uh_ulen ⇒ Fixnum readonly
Attributes inherited from IPv4
#ip_dst, #ip_hl, #ip_id, #ip_len, #ip_off, #ip_options, #ip_p, #ip_src, #ip_sum, #ip_tos, #ip_ttl, #ip_v
Instance Method Summary collapse
-
#initialize(paylen_or_str = 0) ⇒ UDP
constructor
Create a new UDP packet from a payload size or from contents.
-
#ip_payload_len ⇒ Fixnum
The udp data plus header length, uh_ulen.
-
#marshal ⇒ String
Header and payload of this UDP datagram.
- #to_s ⇒ String
-
#udp_unmarshal(str) ⇒ void
Used for subclasses to set the UDP header fields.
Methods inherited from IPv4
#add_option, #calculate_header_len, #calculate_packet_len, creator, #ipv4_unmarshal
Constructor Details
#initialize(paylen_or_str = 0) ⇒ UDP
Create a new UDP packet from a payload size or from contents.
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/scriptroute/packets.rb', line 424 def initialize(paylen_or_str = 0) if(paylen_or_str.is_a?(Fixnum)) then if( paylen_or_str < 0) then raise "payload length must be >= 0" end @uh_ulen = paylen_or_str + 8 if(@uh_ulen > 1480) then raise "desired packet too big" end @uh_sport = 32945 @uh_dport = 33434 @uh_sum = 0 super( IPPROTO_UDP ) else @uh_sport, @uh_dport, @uh_ulen, @uh_sum = paylen_or_str.unpack("nnnn") end end |
Instance Attribute Details
#uh_dport ⇒ Fixnum
403 404 405 |
# File 'lib/scriptroute/packets.rb', line 403 def uh_dport @uh_dport end |
#uh_sport ⇒ Fixnum (readonly)
403 404 405 |
# File 'lib/scriptroute/packets.rb', line 403 def uh_sport @uh_sport end |
#uh_sum ⇒ Fixnum
403 404 405 |
# File 'lib/scriptroute/packets.rb', line 403 def uh_sum @uh_sum end |
#uh_ulen ⇒ Fixnum (readonly)
403 404 405 |
# File 'lib/scriptroute/packets.rb', line 403 def uh_ulen @uh_ulen end |
Instance Method Details
#ip_payload_len ⇒ Fixnum
Returns the udp data plus header length, uh_ulen.
418 419 420 |
# File 'lib/scriptroute/packets.rb', line 418 def ip_payload_len @uh_ulen end |
#marshal ⇒ String
Returns header and payload of this UDP datagram.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/scriptroute/packets.rb', line 441 def marshal # payload = "a%d"% (@payload_len) # puts payload if(@uh_ulen < 8) then warn "uh_ulen should be at least 8" end array_of_elements = [ @uh_sport, @uh_dport, @uh_ulen, @uh_sum ] raise "a UDP header field was unset" if array_of_elements.include?(nil) super + [ @uh_sport, @uh_dport, @uh_ulen, @uh_sum ].pack("nnnn") + if ( self.class == UDP ) then "\0" * ( @uh_ulen - 8 ) else "" # the subclass will take care of it end end |
#to_s ⇒ String
465 466 467 |
# File 'lib/scriptroute/packets.rb', line 465 def to_s super + " UDP %d > %d len %d" % [ @uh_sport, @uh_dport, @uh_ulen ] end |
#udp_unmarshal(str) ⇒ void
This method returns an undefined value.
Used for subclasses to set the UDP header fields.
460 461 462 |
# File 'lib/scriptroute/packets.rb', line 460 def udp_unmarshal(str) @uh_sport, @uh_dport, @uh_ulen, @uh_sum = str.unpack("nnnn") end |