module Scriptroute::UDPgeneric

Attributes

uh_dport[RW]

@return [Fixnum]

uh_sport[R]

@return [Fixnum]

uh_sum[RW]

@return [Fixnum]

uh_ulen[R]

@return [Fixnum]

Public Class Methods

new(paylen_or_str = 0) click to toggle source

Create a new UDP packet from a payload size or from contents. @param paylen_or_str [Integer,String] size or contents

Calls superclass method
# 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

Public Instance Methods

ip_payload_len() click to toggle source

@return [Fixnum] the udp data plus header length, uh_ulen

# 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() click to toggle source

@return [String] header and payload of this UDP datagram.

Calls superclass method
# 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() click to toggle source

@return [String]

Calls superclass method
# 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) click to toggle source

Used for subclasses to set the UDP header fields. @param str [String] the udp header to parse into

ports, length, and checksum.

@return [void]

# File lib/scriptroute/packets.rb, line 587
def udp_unmarshal(str)
  @uh_sport, @uh_dport, @uh_ulen, @uh_sum = str.unpack("nnnn")
end