### Home Classes Methods

### In Files

- lib/packetfu/protos/udp/header.rb

### Parent

Struct.new(:udp_src, :udp_dst, :udp_len, :udp_sum, :body)

### Methods

- ::new
- #read
- #to_s
- #udp_calc_len
- #udp_dport
- #udp_dport=
- #udp_dst
- #udp_dst=
- #udp_len
- #udp_len=
- #udp_recalc
- #udp_sport
- #udp_sport=
- #udp_src
- #udp_src=
- #udp_sum
- #udp_sum=
- #udp_sum_readable

### Included Modules

- StructFu

### Files

- .document
- README.rdoc

### Class/Module Index

Quicksearch

- PacketFu
- PacketFu::ARPHeader
- PacketFu::ARPHeaderMixin
- PacketFu::ARPPacket
- PacketFu::AddrIpv6
- PacketFu::Capture
- PacketFu::Config
- PacketFu::EthHeader
- PacketFu::EthHeaderMixin
- PacketFu::EthMac
- PacketFu::EthNic
- PacketFu::EthOui
- PacketFu::EthPacket
- PacketFu::HSRPHeader
- PacketFu::HSRPHeaderMixin
- PacketFu::HSRPPacket
- PacketFu::ICMPHeader
- PacketFu::ICMPHeaderMixin
- PacketFu::ICMPPacket
- PacketFu::IPHeader
- PacketFu::IPHeaderMixin
- PacketFu::IPPacket
- PacketFu::IPv6Header
- PacketFu::IPv6HeaderMixin
- PacketFu::IPv6Packet
- PacketFu::Inject
- PacketFu::InvalidHeader
- PacketFu::InvalidPacket
- PacketFu::LLDPHeader
- PacketFu::LLDPHeaderMixin
- PacketFu::LLDPPacket
- PacketFu::Octets
- PacketFu::Packet
- PacketFu::PcapFile
- PacketFu::PcapHeader
- PacketFu::PcapPacket
- PacketFu::PcapPackets
- PacketFu::Read
- PacketFu::TCPHeader
- PacketFu::TCPHeaderMixin
- PacketFu::TCPPacket
- PacketFu::TcpEcn
- PacketFu::TcpFlags
- PacketFu::TcpHlen
- PacketFu::TcpOption
- PacketFu::TcpOption::ECHO
- PacketFu::TcpOption::ECHOREPLY
- PacketFu::TcpOption::EOL
- PacketFu::TcpOption::MSS
- PacketFu::TcpOption::NOP
- PacketFu::TcpOption::SACK
- PacketFu::TcpOption::SACKOK
- PacketFu::TcpOption::TS
- PacketFu::TcpOption::WS
- PacketFu::TcpOptions
- PacketFu::TcpReserved
- PacketFu::Timestamp
- PacketFu::UDPHeader
- PacketFu::UDPHeaderMixin
- PacketFu::UDPPacket
- PacketFu::Utils
- PacketFu::Write
- StructFu
- StructFu::Int
- StructFu::Int16
- StructFu::Int16be
- StructFu::Int16le
- StructFu::Int32
- StructFu::Int32be
- StructFu::Int32le
- StructFu::Int8
- StructFu::IntString
- StructFu::String
- Struct

No matching classes.

# PacketFu::UDPHeader

UDPHeader is a complete UDP struct, used in UDPPacket. Many Internet-critical protocols rely on UDP, such as DNS and World of Warcraft.

For more on UDP packets, see www.networksorcery.com/enp/protocol/udp.htm

#### Header Definition

    Int16   :udp_src
    Int16   :udp_dst
    Int16   :udp_len  Default: calculated
    Int16   :udp_sum  Default: 0. Often calculated.
    String  :body

### Public Class Methods

new(args={}) click to toggle source

    # File lib/packetfu/protos/udp/header.rb, line 18
    def initialize(args={})
            super(
                    Int16.new(args[:udp_src]),
                    Int16.new(args[:udp_dst]),
                    Int16.new(args[:udp_len] || udp_calc_len),
                    Int16.new(args[:udp_sum]),
                    StructFu::String.new.read(args[:body])
            )
    end

### Public Instance Methods

read(str) click to toggle source

Reads a string to populate the object.

    # File lib/packetfu/protos/udp/header.rb, line 34
    def read(str)
            force_binary(str)
            return self if str.nil?
            self[:udp_src].read(str[0,2])
            self[:udp_dst].read(str[2,2])
            self[:udp_len].read(str[4,2])
            self[:udp_sum].read(str[6,2])
            self[:body].read(str[8,str.size])
            self
    end

to_s() click to toggle source

Returns the object in string form.

    # File lib/packetfu/protos/udp/header.rb, line 29
    def to_s
            self.to_a.map {|x| x.to_s}.join
    end

udp_calc_len() click to toggle source

Returns the true length of the UDP packet.

    # File lib/packetfu/protos/udp/header.rb, line 63
    def udp_calc_len
            body.to_s.size + 8
    end

udp_dport() click to toggle source

Equivalent to udp_dst

    # File lib/packetfu/protos/udp/header.rb, line 91
    def udp_dport
            self.udp_dst
    end

udp_dport=(arg) click to toggle source

Equivalent to udp_dst=

    # File lib/packetfu/protos/udp/header.rb, line 96
    def udp_dport=(arg)
            self.udp_dst=(arg)
    end

udp_dst() click to toggle source

Getter for the UDP destination port.

    # File lib/packetfu/protos/udp/header.rb, line 52
    def udp_dst; self[:udp_dst].to_i; end

udp_dst=(i) click to toggle source

Setter for the UDP destination port.

    # File lib/packetfu/protos/udp/header.rb, line 50
    def udp_dst=(i); typecast i; end

udp_len() click to toggle source

Getter for the length field.

    # File lib/packetfu/protos/udp/header.rb, line 56
    def udp_len; self[:udp_len].to_i; end

udp_len=(i) click to toggle source

Setter for the length field. Usually should be recalc()'ed instead.

    # File lib/packetfu/protos/udp/header.rb, line 54
    def udp_len=(i); typecast i; end

udp_recalc(args=:all) click to toggle source

Recalculates calculated fields for UDP.

    # File lib/packetfu/protos/udp/header.rb, line 68
    def udp_recalc(args=:all)
            arg = arg.intern if arg.respond_to? :intern
            case args
            when :udp_len
                    self.udp_len = udp_calc_len
            when :all
                    self.udp_recalc(:udp_len)
            else
                    raise ArgumentError, "No such field `#{arg}'"
            end
    end

udp_sport() click to toggle source

Equivalent to udp_src.to_i

    # File lib/packetfu/protos/udp/header.rb, line 81
    def udp_sport
            self.udp_src
    end

udp_sport=(arg) click to toggle source

Equivalent to udp_src=

    # File lib/packetfu/protos/udp/header.rb, line 86
    def udp_sport=(arg)
            self.udp_src=(arg)
    end

udp_src() click to toggle source

Getter for the UDP source port.

    # File lib/packetfu/protos/udp/header.rb, line 48
    def udp_src; self[:udp_src].to_i; end

udp_src=(i) click to toggle source

Setter for the UDP source port.

    # File lib/packetfu/protos/udp/header.rb, line 46
    def udp_src=(i); typecast i; end

udp_sum() click to toggle source

Getter for the checksum.

    # File lib/packetfu/protos/udp/header.rb, line 60
    def udp_sum; self[:udp_sum].to_i; end

udp_sum=(i) click to toggle source

Setter for the checksum. Usually should be recalc()'ed instad.

    # File lib/packetfu/protos/udp/header.rb, line 58
    def udp_sum=(i); typecast i; end

udp_sum_readable() click to toggle source

Readability aliases

    # File lib/packetfu/protos/udp/header.rb, line 102
    def udp_sum_readable
            "0x%04x" % udp_sum
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.