Sha256: 678da6b29ad8bbb7883d97cf433e3ce2ae03629116d8a9d32e6eed1f07b62081

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# -*- coding: binary -*-
##
#
# NAT-PMP protocol support
#
# by Jon Hart <jhart@spoofed.org>
#
##

module Rex
module Proto
module NATPMP

  # Return a NAT-PMP request to get the external address.
  def external_address_request
    [ 0, 0 ].pack('nn')
  end

  # Parse a NAT-PMP external address response +resp+.
  # Returns the decoded parts of the response as an array.
  def parse_external_address_response(resp)
    (ver, op, result, epoch, addr) = resp.unpack("CCnNN")
    [ ver, op, result, epoch, Rex::Socket::addr_itoa(addr) ]
  end

  # Return a NAT-PMP request to map remote port +rport+/+protocol+ to local port +lport+ for +lifetime+ ms
  def map_port_request(lport, rport, protocol, lifetime)
    [ Rex::Proto::NATPMP::Version, # version
      protocol, # opcode, which is now the protocol we are asking to forward
      0, # reserved
      lport,
      rport,
      lifetime
    ].pack("CCnnnN")
  end

  # Parse a NAT-PMP mapping response +resp+.
  # Returns the decoded parts as an array.
  def parse_map_port_response(resp)
    resp.unpack("CCnNnnN")
  end
end

end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
rex-2.0.4 lib/rex/proto/natpmp/packet.rb
dstruct-0.0.1 lib/rex/proto/natpmp/packet.rb
rex-2.0.3 lib/rex/proto/natpmp/packet.rb
librex-0.0.999 lib/rex/proto/natpmp/packet.rb
rex-2.0.2 lib/rex/proto/natpmp/packet.rb
librex-0.0.71 lib/rex/proto/natpmp/packet.rb