Module: Scriptroute::UDPgeneric
Instance Attribute Summary collapse
- #uh_dport ⇒ Fixnum
- #uh_sport ⇒ Fixnum readonly
- #uh_sum ⇒ Fixnum
- #uh_ulen ⇒ Fixnum readonly
Instance Method Summary collapse
-
#initialize(paylen_or_str = 0) ⇒ Object
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.
Instance Attribute Details
#uh_dport ⇒ Fixnum
541 542 543 |
# File 'lib/scriptroute/packets.rb', line 541 def uh_dport @uh_dport end |
#uh_sport ⇒ Fixnum (readonly)
541 542 543 |
# File 'lib/scriptroute/packets.rb', line 541 def uh_sport @uh_sport end |
#uh_sum ⇒ Fixnum
541 542 543 |
# File 'lib/scriptroute/packets.rb', line 541 def uh_sum @uh_sum end |
#uh_ulen ⇒ Fixnum (readonly)
541 542 543 |
# File 'lib/scriptroute/packets.rb', line 541 def uh_ulen @uh_ulen end |
Instance Method Details
#initialize(paylen_or_str = 0) ⇒ Object
Create a new UDP packet from a payload size or from contents.
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/scriptroute/packets.rb', line 552 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( Scriptroute::IP::IPPROTO_UDP ) else @uh_sport, @uh_dport, @uh_ulen, @uh_sum = paylen_or_str.unpack("nnnn") end end |
#ip_payload_len ⇒ Fixnum
Returns the udp data plus header length, uh_ulen.
545 546 547 548 |
# File 'lib/scriptroute/packets.rb', line 545 def ip_payload_len raise "ip_payload_len was nil when asked" unless @uh_ulen @uh_ulen end |
#marshal ⇒ String
Returns header and payload of this UDP datagram.
569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/scriptroute/packets.rb', line 569 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 or self.class == UDP6 ) then "\0" * ( @uh_ulen - 8 ) else "" # the subclass will take care of it end end |
#to_s ⇒ String
592 593 594 |
# File 'lib/scriptroute/packets.rb', line 592 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.
587 588 589 |
# File 'lib/scriptroute/packets.rb', line 587 def udp_unmarshal(str) @uh_sport, @uh_dport, @uh_ulen, @uh_sum = str.unpack("nnnn") end |